WM: 2.8 screen compatibility
authorCampbell Barton <ideasman42@gmail.com>
Fri, 15 Jun 2018 08:23:03 +0000 (10:23 +0200)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 15 Jun 2018 08:24:53 +0000 (10:24 +0200)
Without these minor changes loading files from 2.8 will crash.

Manually applied edits from 26786a2b87a08

source/blender/blenkernel/intern/screen.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/makesdna/DNA_screen_types.h

index a719cc8..995d22c 100644 (file)
@@ -68,13 +68,17 @@ static void spacetype_free(SpaceType *st)
        for (art = st->regiontypes.first; art; art = art->next) {
                BLI_freelistN(&art->drawcalls);
 
-               for (pt = art->paneltypes.first; pt; pt = pt->next)
-                       if (pt->ext.free)
+               for (pt = art->paneltypes.first; pt; pt = pt->next) {
+                       if (pt->ext.free) {
                                pt->ext.free(pt->ext.data);
+                       }
+               }
 
-               for (ht = art->headertypes.first; ht; ht = ht->next)
-                       if (ht->ext.free)
+               for (ht = art->headertypes.first; ht; ht = ht->next) {
+                       if (ht->ext.free) {
                                ht->ext.free(ht->ext.data);
+                       }
+               }
 
                BLI_freelistN(&art->paneltypes);
                BLI_freelistN(&art->headertypes);
@@ -199,10 +203,15 @@ ARegion *BKE_area_region_copy(SpaceType *st, ARegion *ar)
        if (ar->regiondata) {
                ARegionType *art = BKE_regiontype_from_id(st, ar->regiontype);
 
-               if (art && art->duplicate)
+               if (art && art->duplicate) {
                        newar->regiondata = art->duplicate(ar->regiondata);
-               else
+               }
+               else if (ar->flag & RGN_FLAG_TEMP_REGIONDATA) {
+                       newar->regiondata = NULL;
+               }
+               else {
                        newar->regiondata = MEM_dupallocN(ar->regiondata);
+               }
        }
 
        if (ar->v2d.tab_offset)
index 9378534..7d3d417 100644 (file)
@@ -6817,11 +6817,12 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc
 
                                        /* free render engines for now */
                                        for (ar = sa->regionbase.first; ar; ar = ar->next) {
-                                               RegionView3D *rv3d= ar->regiondata;
-                                               
-                                               if (rv3d && rv3d->render_engine) {
-                                                       RE_engine_free(rv3d->render_engine);
-                                                       rv3d->render_engine = NULL;
+                                               if (ar->regiontype == RGN_TYPE_WINDOW) {
+                                                       RegionView3D *rv3d = ar->regiondata;
+                                                       if (rv3d && rv3d->render_engine) {
+                                                               RE_engine_free(rv3d->render_engine);
+                                                               rv3d->render_engine = NULL;
+                                                       }
                                                }
                                        }
                                }
@@ -7051,6 +7052,10 @@ static void direct_link_region(FileData *fd, ARegion *ar, int spacetype)
                /* unkown space type, don't leak regiondata */
                ar->regiondata = NULL;
        }
+       else if (ar->flag & RGN_FLAG_TEMP_REGIONDATA) {
+               /* Runtime data, don't use. */
+               ar->regiondata = NULL;
+       }
        else {
                ar->regiondata = newdataadr(fd, ar->regiondata);
                if (ar->regiondata) {
index 88e6cbc..0e67bde 100644 (file)
@@ -2825,6 +2825,10 @@ static void write_region(WriteData *wd, ARegion *ar, int spacetype)
        writestruct(wd, DATA, ARegion, 1, ar);
 
        if (ar->regiondata) {
+               if (ar->flag & RGN_FLAG_TEMP_REGIONDATA) {
+                       return;
+               }
+
                switch (spacetype) {
                        case SPACE_VIEW3D:
                                if (ar->regiontype == RGN_TYPE_WINDOW) {
index a771888..a9767f5 100644 (file)
@@ -53,10 +53,10 @@ typedef struct bScreen {
        ListBase edgebase;
        ListBase areabase;
        ListBase regionbase;                            /* screen level regions (menus), runtime only */
-       
+
        struct Scene *scene;
        struct Scene *newscene;                         /* temporary when switching */
-       
+
        short winid;                                            /* winid from WM, starts with 1 */
        short redraws_flag;                                     /* user-setting for which editors get redrawn during anim playback (used to be time->redraws) */
 
@@ -384,7 +384,7 @@ enum {
        RGN_TYPE_UI = 4,
        RGN_TYPE_TOOLS = 5,
        RGN_TYPE_TOOL_PROPS = 6,
-       RGN_TYPE_PREVIEW = 7
+       RGN_TYPE_PREVIEW = 7,
 };
 /* use for function args */
 #define RGN_TYPE_ANY -1
@@ -403,8 +403,12 @@ enum {
 #define RGN_SPLIT_PREV         32
 
 /* region flag */
-#define RGN_FLAG_HIDDEN                1
-#define RGN_FLAG_TOO_SMALL     2
+enum {
+       RGN_FLAG_HIDDEN             = (1 << 0),
+       RGN_FLAG_TOO_SMALL          = (1 << 1),
+       /* Region data is NULL'd on read, never written. */
+       RGN_FLAG_TEMP_REGIONDATA    = (1 << 3),
+};
 
 /* region do_draw */
 #define RGN_DRAW                       1