gcherchi / InteractiveAndRobustMeshBooleans

MIT License
192 stars 32 forks source link

mesh_booleans malloc errors #11

Closed yunshengtian closed 1 year ago

yunshengtian commented 1 year ago

Hi, thank you for this great work! I tried it on my meshes, but it triggered some errors I don't know how to fix.

Command

./mesh_booleans intersection 1.obj 1.obj output.obj

Output

mesh_booleans(77363,0x172253000) malloc: *** error for object 0x11a88e600: pointer being freed was not allocated
mesh_booleans(77363,0x172253000) malloc: *** set a breakpoint in malloc_error_break to debug

Mesh

Here is the link to the 1.obj that I used. It passed all the tests in mesh_booleans_inputcheck - see the output below.

- your input is manifold
- your input is watertight
- your input is well oriented
- your input is self-intersections free
- CHECK PASSED!

I also tried on some other meshes, which worked fine, so I suspect there is something wrong with this mesh but the check executable does not catch that. FYI I am running on macOS.

Thanks!

mlivesu commented 1 year ago

hi, indeed there is a bug in our code. I did some testing and the bug is in the octree data structure (race conditions). Substituting the octree in this project with the cinolib's octree everything works just fine, but cinolib's octree is a bit slower than this one, so I prefer not to do the full switch in this code base. We'll try to fix the bug after the holidays

yunshengtian commented 1 year ago

Thank you for the update and look forward to the bug fix!

yunshengtian commented 1 year ago

Thanks again for offering the bug fix. Meanwhile, if I want to have a quick solution by replacing your octree with cinolib's octree, could you let me know roughly how to do that?

I see some API differences between your octree and cinolib's octree, so any guidance on that would be appreciated, or if you have such code at hand, it would be awesome.

mlivesu commented 1 year ago

I just created a branch named octree_cinolib which does the proper changes. You can compile this version and use it. In my computer it successfully processes your failure case: ./mesh_booleans intersection 1.obj 1.obj output.obj Let me know how it goes :)

yunshengtian commented 1 year ago

Thanks @mlivesu for your quick reply! It worked great! This is very helpful. 🙌 Though sometimes for subtraction I see the normals pointing in the reverse direction in the subtracted area, I can use external tools to fix that :)

mlivesu commented 1 year ago

ouch. This was a tiny bug we had already fixed. I reintroduced it by copy pasting my local code used to fix the octree. Can you update your local copy and try again? normals should be fine now

yunshengtian commented 1 year ago

Cool. I just tried and it worked great. Thank you!