makehumancommunity/makehuman-plugin-for-blender

Crash on importing body in some scenes

joepal1976 opened this issue · 6 comments

I have two scenes I use. The normal lightroom (from the fashion repo in the online assets) and a more complex interior scene. In the first, everything works as expected, but in the second the import fails with a stack trace:

File "/home/joepal/.config/blender/2.80/scripts/addons/MH_Community/mh_sync/import_body_binary.py", line 391, in gotBodyMaterialInfo
   FetchServerData('getSkeleton', self.gotSkeleton)
 File "/home/joepal/.config/blender/2.80/scripts/addons/MH_Community/mh_sync/fetch_server_data.py", line 8, in __init__
   self.executeJsonCall(expectBinaryResponse=expectBinary, params=params)
 File "/home/joepal/.config/blender/2.80/scripts/addons/MH_Community/mh_sync/sync_ops.py", line 18, in executeJsonCall
   self.callback(json_obj)
 File "/home/joepal/.config/blender/2.80/scripts/addons/MH_Community/mh_sync/fetch_server_data.py", line 14, in callback
   self.readyFunction(json_obj.data)
 File "/home/joepal/.config/blender/2.80/scripts/addons/MH_Community/mh_sync/import_body_binary.py", line 447, in gotSkeleton
   bpy.ops.object.mode_set(mode='EDIT', toggle=False)
 File "/home/joepal/system/blender-2.80-ec471a9b1c14-linux-glibc224-x86_64/2.80/scripts/modules/bpy/ops.py", line 200, in __call__
   ret = op_call(self.idname_py(), None, kw)
TypeError: Converting py args to operator properties:  enum "EDIT" not found in ('OBJECT')

Pasting this here for now. I haven't figured out why things work in one scene but not the other.

'bpy.ops.object.mode_set(mode='EDIT', toggle=False)' is the equivalent of hitting the tab key. Usually it'll switch to edit mode, but you will the that error message when you try it on an non editable object like the camera. I get the impression there are still non-editable objects selected during the import process, causing your error, though I wasn't able to reproduce a similar condition.
Perhaps it's a Blender bug? Your build from February (ec471a9b1c14) is slightly outdated. Maybe you want to retry with a bit more recent version of Blender?

I'm nearing a explanation here, although I'm not entirely there yet.

The problem seems to be that if the object is not visible, then switching to edit mode is prohibited.

The object itself is marked as visible, and the collection it's in is also marked as visible.

However, it seems that the collection sometimes (maybe always?) becomes a child of another collection. And if that collection is hidden, then everything in it becomes hidden too.

I'll see if I can force the collection creation to put the collection in the top level of the hierarchy and maybe that solves the problem.

Once Blender created new collections as children of the current active collection in the outliner. Obviously Blender has changed that behavior and new collections are created under the scene collection. I prefer the former stile and the code was deliberately written in that way. Though turning around some collections manually isn't that super hard and we could leave the code as it currently is...

The problem was that with that approach, the crash would happen if you had a hidden collection selected when clicking the import button. The problem being that you can't enter edit mode for an object which isn't displayed.

My fix was to ensure that the new collection was at top level and visible.

The alternative solution would be to iterate over the hierarchy and force-show all parent levels for the new collection before importing. This is obviously possibly, but I'm not sure it's desirable.

Me, I prefer my collections top-level as I'm still used to the old one-level group style from blender.

But maybe we could have an option in the UI for selecting if the new collection is top or sub, and make clear that if you create a sub-collection, you will also force-show all levels above it?

I've added the option for where to create the collection now. But I'm unable to avoid the crash that happens with hidden collections. See the TODO comment in the commit.

Possibly, we'll have to leave this to documentation.

Tested on B290 it does not crash anymore even with sub collections on hidden collections.