Page MenuHome

Crash opening 2.78 file and switching workspace
Closed, ResolvedPublic

Description

d7824de8e44e8620ebfb6f0971d4136198ab9bb8
MacOS 10.13

Hi - if I open certain Blender 2.78 files in Blender 2.80 I encounter a NULL pointer when changing workspaces.

To reproduce:

  1. open Sun.blend from github
  2. switch to the compositor workspace
(lldb) thread backtrace
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x70)
  * frame #0: 0x000000010017a3b0 blender`WM_toolsystem_mode_from_spacetype(workspace=0x000060c0001e7b08, scene=0x000000012601b208, sa=0x0000604000162b88, spacetype=1) at wm_toolsystem.c:363
    frame #1: 0x000000010017b357 blender`WM_toolsystem_refresh_screen_area(workspace=0x000060c0001e7b08, scene=0x000000012601b208, sa=0x0000604000162b88) at wm_toolsystem.c:407
    frame #2: 0x0000000100779dce blender`ED_area_initialize(wm=0x000000011f683b98, win=0x000000011f683d38, sa=0x0000604000162b88) at area.c:1468
    frame #3: 0x00000001007887ab blender`ED_screen_refresh(wm=0x000000011f683b98, win=0x000000011f683d38) at screen_edit.c:816
    frame #4: 0x000000010078a135 blender`screen_change_update(C=0x00006080000e0288, win=0x000000011f683d38, sc=0x000000011fa838a8) at screen_edit.c:1232
    frame #5: 0x000000010079a0d0 blender`ED_workspace_change(workspace_new=0x000060c0001e7b08, C=0x00006080000e0288, wm=0x000000011f683b98, win=0x000000011f683d38) at workspace_edit.c:199
    frame #6: 0x00000001001474be blender`wm_event_do_notifiers(C=0x00006080000e0288) at wm_event_system.c:387
    frame #7: 0x0000000100142b00 blender`WM_main(C=0x00006080000e0288) at wm.c:548
    frame #8: 0x000000010013ce8c blender`main(argc=1, argv=0x00007ffeefbff4a8) at creator.c:514
    frame #9: 0x00007fff7709a015 libdyld.dylib`start + 1
    frame #10: 0x00007fff7709a015 libdyld.dylib`start + 1

There is a simple tactical fix which I will attach as a patch. It simply checks for a NULL view_layer in the workspace. However the file reading logic may need to spot the missing workspace objects and add them - if I open the file then immediately save it from 2.8 and reopen it the NULL does not happen. This is because write_file_handle calls write_workspace. I notice this happens for the in memory undo stack file when a file is read or something is pushed to the stack so perhaps similar logic could be added to upgrade the 2.78 files?

Event Timeline

Here is my suggested tactical fix

diff --git a/source/blender/windowmanager/intern/wm_toolsystem.c b/source/blender/windowmanager/intern/wm_toolsystem.c
index d734fee05ae..2764123011c 100644
--- a/source/blender/windowmanager/intern/wm_toolsystem.c
+++ b/source/blender/windowmanager/intern/wm_toolsystem.c
@@ -358,15 +358,17 @@ int WM_toolsystem_mode_from_spacetype(
        switch (spacetype) {
                case SPACE_VIEW3D:
                {
+                       mode = CTX_MODE_OBJECT;
+
                        /* 'sa' may be NULL in this case. */
                        ViewLayer *view_layer = BKE_workspace_view_layer_get(workspace, scene);
-                       Object *obact = OBACT(view_layer);
-                       if (obact != NULL) {
-                               Object *obedit = OBEDIT_FROM_OBACT(obact);
-                               mode = CTX_data_mode_enum_ex(obedit, obact, obact->mode);
-                       }
-                       else {
-                               mode = CTX_MODE_OBJECT;
+                       if (view_layer != NULL)
+                       {
+                               Object *obact = OBACT(view_layer);
+                               if (obact != NULL) {
+                                       Object *obedit = OBEDIT_FROM_OBACT(obact);
+                                       mode = CTX_data_mode_enum_ex(obedit, obact, obact->mode);
+                               }
                        }
                        break;
                }

@Campbell Barton (campbellbarton) Looks like one of the toolsystem <-> workspace things you were working on last week.

@Adam Latchem (adamlatchem) Technically we haven't opened the tracker for 2.8 user bug reports yet. We're currently dealing with a large number of critical bugs from the Spring team that need to get addressed first.

The real problem here is that the view layer should not be NULL, if that's the case lots of other things can break too.

Thanks for the more comprehensive fix Brecht.