alecjacobson / computer-graphics-ray-casting

Computer Graphics Assignment about Ray Casting
30 stars 28 forks source link

IOError: .\bunny.stl could not be opened... #5

Closed chenbowen closed 6 years ago

chenbowen commented 6 years ago

I‘m using visual studio 2017 on windows 10 and got this error. I found in "read_json.h", line 110, the value of variable "stl_path" is just "bunny.stl". So how should I fix it? Change the path of "bunny.stl" through "bunny.json" or copy the STL model to the "build" folder?

psarahdactyl commented 6 years ago

Either way is fine. Changing paths might make it harder to grade, so I'd copy the STL model.

alecjacobson commented 6 years ago

We should fix this in the read_json.h file. How can we direct windows to find the path? @psarahdactyl can you test this on windows? I'm guessing the problem is that the working directory is not correct.

psarahdactyl commented 6 years ago

Well so in windows we can run the executable from the directory where it is generated, or we can run the VS project from the IDE which I think uses wherever main.cpp is. There is probably a VS setting to set the execution directory to something else. I can look into it.

alecjacobson commented 6 years ago

Could you see if dirname and the PATH_SEPARATOR on https://github.com/alecjacobson/computer-graphics-ray-casting/blob/2daf549f27572528b659c05842e33f29ef061a91/include/read_json.h#L112 are returning what they're supposed to?

chenbowen commented 6 years ago

I think I found the problem. filename has value ../shared/data/bunny.json. But igl::dirname(filename) returns . . The reason is igl::dirname() can only search \\ in the path on windows but not /.

alecjacobson commented 6 years ago

Thanks, @chenbowen. I'll investigate. For now, does it work if you change the hardcoded path to ..\shared\data\bunny.json ?

chenbowen commented 6 years ago

No, it does not work. If I change the hardcoded path to ..\shared\data\bunny.json, filename becomes ..shareddata\bunny.json immediately. But it works if I change the path to ..\\shared\\data\\bunny.json.

alecjacobson commented 6 years ago

ah, right. yes, C++ needs \\ to mean \ inside a string.

Well, so this is a solution for windows users for now. The better solution is to fix dirname to work correctly. That might come later, but shouldn't stop anyone from working.

alecjacobson commented 6 years ago

@chenbowen or @psarahdactyl , could you try using this new dirname.h https://github.com/alecjacobson/computer-graphics-ray-casting/blob/42d330ca88e32b1ff786156ddda07014a410e8b2/include/dirname.h

I'm hoping it fixes the issue on windows without having to change any other files/paths.

chenbowen commented 6 years ago

Yes, the new dirname.h works for ../shared/data/bunny.json.