IfcOpenShell / IfcOpenShell

Open source IFC library and geometry engine
GNU Lesser General Public License v3.0
1.8k stars 715 forks source link

ifc Import crash #1406

Closed Sinasta closed 3 years ago

Sinasta commented 3 years ago

I get this error when i try to import an ifc file with 'import and clean Mesh' activated. the ifc file is tested and certainly not corrupt. I am running the latest ifcopenshell snapshot on blender 2.93 alpha with python 3.9 on archlinux.

Starting import process :: 0.00 Load diff :: 0.00 Purge diffs :: 0.00 Loading file :: 0.06 Setting file :: 0.00 Calculate unit scale :: 0.00 Calculate model offset :: 0.01 Set units :: 0.00 Create project :: 0.00 Create spatial hierarchy :: 0.00 Create aggregates :: 0.00 Create aggregate tree :: 0.00 Create opening collection :: 0.00 Process element filter :: 0.00 Parsing native elements :: 0.02 Create grids :: 0.00 Done creating geometry Create native products :: 0.00 Done creating geometry Create products :: 0.93 Create type products :: 0.00 Create annotation :: 0.00 Create structural elements :: 0.00 Placing objects in spatial tree :: 0.01 Add project to scene :: 0.00 Info: Removed 750 vertice(s) Break segmentation violation Generating stack trace... 0x000055a411a3c04d in BKE_object_boundbox_calc_from_mesh + 0x5d from blender 0x000055a411c87020 in from blender 0x000055a411c872c5 in makeDerivedMesh + 0x75 from blender 0x000055a411a45b92 in BKE_object_handle_data_update + 0x2a2 from blender 0x000055a411a460a1 in BKE_object_eval_uber_data + 0x31 from blender 0x000055a413efec01 in from blender 0x000055a413efec53 in from blender 0x00007f6f036570a6 in tbb::interface7::internal::isolate_within_arena(tbb::interface7::internal::delegate_base&, long) + 0x46 from /usr/lib/libtbb.so.2 0x000055a41401ad44 in from blender 0x00007f6f0365d105 in from /usr/lib/libtbb.so.2 0x00007f6f0365d43c in from /usr/lib/libtbb.so.2 0x00007f6f03656d97 in from /usr/lib/libtbb.so.2 0x00007f6f036553e1 in from /usr/lib/libtbb.so.2 0x00007f6f0365181c in from /usr/lib/libtbb.so.2 0x00007f6f03651a8a in from /usr/lib/libtbb.so.2 0x00007f6f03377299 in from /usr/lib/libpthread.so.0 0x00007f6ef954b053 in clone at :? from /usr/lib/libc.so.6 Break segmentation violation Generating stack trace... 0x000055a411a3c04d in BKE_object_boundbox_calc_from_mesh + 0x5d from blender 0x000055a411c87020 in from blender 0x000055a411c872c5 in makeDerivedMesh + 0x75 from blender 0x000055a411a45b92 in BKE_object_handle_data_update + 0x2a2 from blender 0x000055a411a460a1 in BKE_object_eval_uber_data + 0x31 from blender 0x000055a413efec01 in from blender 0x000055a413efec53 in from blender 0x00007f6f036570a6 in tbb::interface7::internal::isolate_within_arena(tbb::interface7::internal::delegate_base&, long) + 0x46 from /usr/lib/libtbb.so.2 0x000055a41401ad44 in from blender 0x00007f6f0365d105 in from /usr/lib/libtbb.so.2 0x00007f6f0365d43c in from /usr/lib/libtbb.so.2 0x00007f6f03656d97 in from /usr/lib/libtbb.so.2 0x00007f6f036553e1 in from /usr/lib/libtbb.so.2 0x00007f6f0365181c in from /usr/lib/libtbb.so.2 0x00007f6f03651a8a in from /usr/lib/libtbb.so.2 0x00007f6f03377299 in from /usr/lib/libpthread.so.0 0x00007f6ef954b053 in clone at :? from /usr/lib/libc.so.6 QObject::~QObject: Timers cannot be stopped from another thread Error: Not freed memory blocks: 195327, total unfreed memory 89.865314 MB Freeing memory after the leak detector has run. This can happen when using static variables in C++ that are defined outside of functions. To fix this error, use the 'construct on first use' idiom. Freeing memory after the leak detector has run. This can happen when using static variables in C++ that are defined outside of functions. To fix this error, use the 'construct on first use' idiom. Freeing memory after the leak detector has run. This can happen when using static variables in C++ that are defined outside of functions. To fix this error, use the 'construct on first use' idiom. Freeing memory after the leak detector has run. This can happen when using static variables in C++ that are defined outside of functions. To fix this error, use the 'construct on first use' idiom. Freeing memory after the leak detector has run. This can happen when using static variables in C++ that are defined outside of functions. To fix this error, use the 'construct on first use' idiom. Freeing memory after the leak detector has run. This can happen when using static variables in C++ that are defined outside of functions. To fix this error, use the 'construct on first use' idiom.

Moult commented 3 years ago

Can you replicate this with 2.92 stable with py37? If not, it could be an alpha blender bug which should be isolated and reported upstream.

Sinasta commented 3 years ago

I sadly can't try it out on Blender 2.92. But i suppose that it is indeed because of the alpha blender version. Could you please tell me how i could change that command :

import_ifc.IfcImportSettings.factory( bpy.context, ifc_tmp.name, logger )

to import without the mesh cleaning flag activated?

Moult commented 3 years ago

@Sinasta

settings = import_ifc.IfcImportSettings.factory(bpy.context, ifc_tmp.name, logger)
settings.should_clean_mesh = False

FYI mesh cleaning does these operations:

        bpy.ops.mesh.remove_doubles(context_override)
        bpy.ops.mesh.tris_convert_to_quads(context_override)
        bpy.ops.mesh.normals_make_consistent(context_override)

Nothing particularly special.

helpsterTee commented 3 years ago

Can reproduce the error with two different example files.

blender-2.93.0-b7b1b2325c1a-linux64 with blender28-bim-210306-py39-linux crashes when mesh cleaning is activated, blender-2.92.0-linux64 with blender28-bim-210404-py37-linux does not crash when mesh cleaning is active.

# Blender 2.93.0, Commit date: 2021-04-07 21:03, Hash b7b1b2325c1a
bpy.data.window_managers["WinMan"].addon_search = "bim"  # Property
bpy.ops.object.select_all(action='SELECT')  # Operator
bpy.ops.object.delete(use_global=False, confirm=False)  # Operator
Deleted 3 object(s)  # Info --- default objects
bpy.context.space_data.system_folders_active = 2  # Property
bpy.ops.object.editmode_toggle()  # Operator

# backtrace
./blender(BLI_system_backtrace+0x20) [0xa57ca70]
./blender() [0xf5912a]
/lib/x86_64-linux-gnu/libc.so.6(+0x46210) [0x7f45bd776210]
./blender(CustomData_get_active_layer+0x1c) [0x12785dc]
./blender(CustomData_bmesh_update_active_layers+0x4d) [0x1279a3d]
./blender(BKE_mesh_update_customdata_pointers+0x3a) [0xfbf57a]
./blender() [0xfbf821]
./blender(BKE_id_free_ex+0x7f) [0xfa905f]
./blender(BKE_editmesh_free_derivedmesh+0x14) [0x12911c4]
./blender() [0x1236dfb]
./blender(makeDerivedMesh+0x65) [0x1238585]
./blender(BKE_object_handle_data_update+0xff) [0xff33df]
./blender(BKE_object_eval_uber_data+0x2f) [0xff3a1f]
./blender() [0x86bbf32]
./blender() [0x86bc102]
./blender() [0x12fcbc5]
./blender() [0xa580673]
./blender() [0x12fb0f5]
./blender() [0x12fb3ab]
./blender() [0x12fc8d7]
./blender() [0x12f5650]
./blender() [0x12f6dac]
./blender() [0x12f6fa9]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x9609) [0x7f45bde72609]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x43) [0x7f45bd852293]
Read prefs: /home/yourusernamegoeshere/.config/blender/2.93/config/userpref.blend
Traceback (most recent call last):
  File "/home/yourusernamegoeshere/.config/blender/2.93/scripts/addons/blenderbim/bim/__init__.py", line 167, in on_register
    bpy.app.handlers.depsgraph_update_post.remove(on_register)
ValueError: list.remove(x): x not in list
Info: Deleted 3 object(s)

Starting import process :: 0.00
Load diff :: 0.00
Purge diffs :: 0.00
Loading file :: 0.73
Setting file :: 0.00
Calculate unit scale :: 0.00
Calculate model offset :: 0.11
Set units :: 0.00
Create project :: 0.00
Create spatial hierarchy :: 0.00
Create aggregates :: 0.00
Create opening collection :: 0.00
Process element filter :: 0.00
Create grids :: 0.00
250 elements processed in 0.10s ...
500 elements processed in 0.09s ...
750 elements processed in 0.12s ...
1000 elements processed in 0.18s ...
Done creating geometry
Create products :: 1.98
Create type products :: 0.06
Create annotation :: 0.00
Placing objects in spatial tree :: 0.09
Add project to scene :: 0.00
Writing: /tmp/blender.crash.txt
Writing: /tmp/blender.crash.txt
Attempt to free NULL pointer
Writing: /tmp/blender.crash.txt
Writing: /tmp/blender.crash.txt
Writing: /tmp/blender.crash.txt
Writing: /tmp/blender.crash.txt
Writing: /tmp/blender.crash.txt
Writing: /tmp/blender.crash.txt
Writing: /tmp/blender.crash.txt
Writing: /tmp/blender.crash.txt
Writing: /tmp/blender.crash.txt
Writing: /tmp/blender.crash.txt
Writing: /tmp/blender.crash.txt
Writing: /tmp/blender.crash.txt
[1]    segmentation fault (core dumped)  ./blender
Moult commented 3 years ago

@helpsterTee can you disable mesh cleaning, then manually run those three operations, and see if Blender crashes? It may be an upstream bug.

helpsterTee commented 3 years ago

@Moult Blender crashes if I do A, TAB As the code activates edit mode before performing these operations, this seems to be an upstream bug. Edit mode works for single parts of the imported file, but not if I select all. So it's either a bug referencing a single object or the amount of objects.

https://github.com/RWTH-E3D/DigitalHub/blob/master/Version_1/FM_ARC_DigitalHub.ifc can be used as example for error reporting.

Moult commented 3 years ago

@helpsterTee great - is it possible to save the blend file, reopen it, and see if a crash is still triggered when you toggle edit mode?

It may help to also isolate elements using a binary search (basically, select half the objects, see if it is a crash, if yes, select a quarter of that half, etc etc until you very quickly narrow down the troublesome elements).

Hopefully, that can help isolate the issues and provide upstream with useful test cases.

helpsterTee commented 3 years ago

@Moult so this happens even after saving and reopening and seems to be related to shared geometry, as far as I can guess.

As you can see, these are shared meshes: Edit one

If I select everything but the last one, edit mode works: Select all but last

If I additionally select the last one and enter edit mode, it will crash with the usual error. It will also crash on certain combinations of these objects. So it may have to do something with the shared data between these.

Will also happen on the trees, which are also shared geometry. I found this yesterday, but don't know, if the fix is already merged in 2.93: https://developer.blender.org/rB0a34fec56a2f8d051a1348d4e82049e063ffcc37

Moult commented 3 years ago

@helpsterTee potentially, and sorry for the late reply. Can you try with a newer Blender developer build to see if they have fixed it upstream? If so, we can close this bug :)

helpsterTee commented 3 years ago

@Moult fixed in blender-2.93.0-0566ebdebeeb-linux64 Import with mesh cleanup and editing of multiple objects with shared geometry works now :)

@Sinasta can you confirm?