sampotter / python-embree

Apache License 2.0
20 stars 6 forks source link

Ray1M, RayHit1M - Deallocation crash #10

Open drawitsro opened 3 years ago

drawitsro commented 3 years ago

Hi, I have tried to use your library, it's exactly what I have been looking for for a long time, unfortunately, I am not skilled in python bindings generation and I encountered some troubles.

I have installed Embree: High-Performance Ray Tracing Kernels 3.12.2 from Embree website. I have built it successfully (latest version, commit 1238e0e127ef4d4d13a5977ab2509f42fc7145ed) on Windows 10, python 3.7 in mingw64 (git bash console). Here is the build log: $ C:/python37/python.exe setup.py build_ext -I/c/Program\ Files/Intel/Embree3/include -L /c/Program\ Files/Intel/Embree3/lib running build_ext building 'embree' extension creating build creating build\temp.win-amd64-3.7 creating build\temp.win-amd64-3.7\Release C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I/opt/local/include "-IC:/Program Files/Intel/Embree3/include" -IC:\python37\include -IC:\python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" /Tcembree.c /Fobuild\temp.win-amd64-3.7\Release\embree.obj embree.c creating C:\external\python-embree\build\lib.win-amd64-3.7 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:/opt/local/lib "/LIBPATH:C:/Program Files/Intel/Embree3/lib" /LIBPATH:C:\python37\libs /LIBPATH:C:\python37\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\um\x64" embree3.lib /EXPORT:PyInit_embree build\temp.win-amd64-3.7\Release\embree.obj /OUT:build\lib.win-amd64-3.7\embree.cp37-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.7\Release\embree.cp37-win_amd64.lib Creating library build\temp.win-amd64-3.7\Release\embree.cp37-win_amd64.lib and object build\temp.win-amd64-3.7\Release\embree.cp37-win_amd64.exp Generating code Finished generating code

I have even successfully created a triangle geometry and the scene (even multiple times with deallocation), everything works until some of the Ray1M or RayHit1M objects are deallocated (freed).

Very minimalistic repro code is: import embree rays = embree.Ray1M(100)

and result after run is: Process finished with exit code -1073740940 (0xC0000374) <- crash

Of course, the same problem prevails even if the Ray1M is created somewhere in the function or class and its freed after usage.

The only workaround I have found to be working is to preallocate the Ray1M big enough for the whole work done in the program and let it crash only when the program is closing.

Any Ideas what might be behind this trouble?

Best regards, Zdenek Glazer

aluo-x commented 3 years ago

Very odd! I can't seem to reproduce this on Linux.

Edit: I have a process that creates/destroys 1000k+ embree rayhit1m objects, each with approximately 10,000 rays - 24/7 for over the course of 3 weeks. They are running on a variety of different CPUs (intel/AMD from the last 8 years), on different kernel versions, apparently without issue. But I haven't tried running this on Windows.

drawitsro commented 3 years ago

Hi, I am afraid, it is only windows related.

sampotter commented 3 years ago

Hi @drawitsro, sorry about the delay, have been quite busy. Is this still a problem for you?

sampotter commented 2 years ago

@drawitsro If you're still having trouble on Windows, you may want to check https://github.com/pyvista/pyvista-support/issues/468#issuecomment-890112999 --- there is a wrapper of Embree 2 which you may have more luck with on Windows for the time being.

mikedh commented 2 years ago

Hey, I was noticing unit tests on Windows were failing with this same memory heap corruption error code, I think it might have been the use of free instead of _aligned_free on windows according to Microsoft's docs. This may be fixed now on master; I changed to aligned_free and it stopped crashing during unit tests.

If you're feeling bold you can try checking out the new Windows wheels with a pip install embree.