vkoskiv / c-ray

c-ray is a small, simple path tracer written in C
MIT License
802 stars 43 forks source link

munmap error when rendering an obj file #109

Closed lordfeck closed 2 years ago

lordfeck commented 2 years ago

When I run c-ray with the attached JSON file, I get the following error:

munmap_chunk(): invalid pointer
Aborted

armchair.zip

I'm trying to render an armchair OBJ file I found on the internet (included are textures and mtl file). I'm not sure why the error is happening.

@

vkoskiv commented 2 years ago

Hey, thanks for reporting this!

TL;DR:

I've fixed the issue, please pull and recompile.

Full story:

That error is very misleading. c-ray currently doesn't support ngons. The wavefront parser encountered some in the mesh you provided, and then silently swallowed that error because I don't build with assertions in release mode. Whoops! So the error you're seeing is just a side effect of the asset parser continuing in an unknown state after that silent error.

I've modified the parser so instead of asserting, it now skips ngons and shouts into the debug log (which you can see with the -v flag) that it found one. The scene you provided works now. I took the liberty to modify it a bit, and I've attached it here. I just loaded an environment map and a ground plane to give a bit more context. You are free to use this scene file I provided for any purpose.

You can see that the armchair has some gaps in a few places, these are the ngons that were (mostly) skipped during parsing. You can re-export the mesh with only triangles and quads, and the gaps should go away.

armchair2-2022-01-04T20:05:22.zip

Let me know if you encounter any further issues - c-ray is still experimental software, and especially the asset parsing likely contains many bugs. And thanks again for checking this out! Always fun to see someone else giving it a go.

vkoskiv commented 2 years ago

Tagging @lordfeck since I noticed I don't get notified by GH unless I get tagged.

lordfeck commented 2 years ago

@vkoskiv Thanks very kindly for the prompt and detailed response, I wasn't expecting it at all! I've since rebuilt with your latest commits and I can confirm the bug is fixed :ok_hand:

I've enjoyed playing with C-Ray! If I ever make my own 3D models I know where I'll have them raytraced. There is still much of 3D rendering that is unknown to me...

vkoskiv commented 2 years ago

Thank you for the nice bug report! I'll close this issue since it's resolved, but if you have any further questions or ideas for improvement, feel free to open further issues or ping me on discord directly with the handle vkoskiv#3100