gcherchi / InteractiveAndRobustMeshBooleans

MIT License
192 stars 32 forks source link

iterator out of bounds in fast_trimesh.cpp #21

Closed cyachen closed 1 year ago

cyachen commented 1 year ago

I encountered an iterator out of bounds when I tested mesh arrangement code on large triangles. I replaced code for(uint t_id : e2t[e_id]) in Line 713 of fast_trimesh with for(int i=0; i < e2t[e_id].size(); i++) uint t_id = e2t[e_id].data()[i]; and the error disappeared. So I suspect there are something wrong in iterator of fmvector.

gcherchi commented 1 year ago

Hi, thank you for your interest in our work! It would be really helpful having more information about this problem. What operation are you doing (intersection, union, subtraction), and with which models (can you provide a zip?)? I'd like to reproduce your error and debug the code. Thanks a lot. Gianmarco

cyachen commented 1 year ago

Thanks for reply! I only did mesh arrangement by using the customArrangementPipeline interface in booleans.cpp. I directly converted the attached big_tris.obj file to input format and called customArrangementPipeline. I reproduced the same error by simply perfoming union operation on two same meshes in Debug mode. Besides, the error message in terminal is Assertion failed: t_id < triangles.size() && "tri id out of range", file E:\2023\cad\InteractiveAndRobustMeshBooleans_octree_error\arrangements\code\fast_trimesh.cpp, line 452. big_tris.zip

gcherchi commented 1 year ago

Dear JiaxiChen, It is evident that you still need to read both the paper and the README repository.

We provide this code to perform Boolean operations between meshes with particular requirements. You can find all the requirements in the paper (input meshes must be manifold, watertight, self-intersections free, and well-oriented): https://dl.acm.org/doi/abs/10.1145/3550454.3555460. Not even one of these requirements is met by the mesh you sent me.

Furthermore, in this repository README, we also describe how to test your inputs before using our code in order to be sure they satisfy our requirements:

258184713-1c71cb9f-dd9a-476b-a713-0b73d7681769

Finally, if you only need the Arrangemet pipeline, please refer to the Arrangement repository here: https://github.com/gcherchi/FastAndRobustMeshArrangements. You are using the customArrangementPipeline interface in the booleans.cpp file, that is, obviously, a "custom" version of the Arrangement for the Booleans operations (thus subject to the requirements of the Booleans code).

Hope you can find the solution to your problem in our other repository. Best regards, Gianmarco

cyachen commented 1 year ago

Hi! Thanks for detailed explanation! I follow your suggestion to test my input using code in https://github.com/gcherchi/FastAndRobustMeshArrangements. And I found the same error occured in vs2019 debug mode. I carefully checked the code in Line 713 of fast_trimesh.cpp and suspected the bug is caused by invalid iterator in this range-for loop. Actually, e2t.emplace_back() is called by addTri --> addEdge function in this for loop, so the reallocation of e2t occured which make the range-for-loop fail. This could probably be the reason of this bug. I tried to fix this bug by using index to access. Could you please check my pull request and correct my mistake if I misunderstand your code? Thanks a lot! Jiaxi Chen

gcherchi commented 1 year ago

Hi Jiaxi, I'll check the pull request in the correct repo. Thanks again! Gianmarco