[Bf-blender-cvs] [22b69ed08f7] master: Fix T101001: crash setting texture node active in certain cases

Philipp Oeser noreply at git.blender.org
Tue Sep 20 09:23:19 CEST 2022


Commit: 22b69ed08f7b57a5ba6a53322481f984511b3ecf
Author: Philipp Oeser
Date:   Mon Sep 12 13:55:40 2022 +0200
Branches: master
https://developer.blender.org/rB22b69ed08f7b57a5ba6a53322481f984511b3ecf

Fix T101001: crash setting texture node active in certain cases

Code from {rBb0cb0a785475} assumed a texture node `node->id` would
always be an image.
That is not true though:
 - could be an object (as reported here with the Point Density node)
 - could be a textblock (as in the IES Texture node)

Acting on these would crash when doing `BKE_image_signal` on them.

Now check node id is an image and do nothing otherwise.
Also check if an image is actually set in these nodes (if none is, the
Image Editor is now also untouched, previously the image in the Image
Editor was "cleared" here [set to NULL] -- which does not seems very
beneficial)

Maniphest Tasks: T101001

Differential Revision: https://developer.blender.org/D15943

===================================================================

M	source/blender/editors/space_node/node_edit.cc

===================================================================

diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc
index f9c50aeac64..31d99eafbc1 100644
--- a/source/blender/editors/space_node/node_edit.cc
+++ b/source/blender/editors/space_node/node_edit.cc
@@ -713,10 +713,12 @@ void ED_node_set_active(
             /* Sync to active texpaint slot, otherwise we can end up painting on a different slot
              * than we are looking at. */
             if (ma->texpaintslot) {
-              Image *image = (Image *)node->id;
-              for (int i = 0; i < ma->tot_slots; i++) {
-                if (ma->texpaintslot[i].ima == image) {
-                  ma->paint_active_slot = i;
+              if (node->id != nullptr && GS(node->id->name) == ID_IM) {
+                Image *image = (Image *)node->id;
+                for (int i = 0; i < ma->tot_slots; i++) {
+                  if (ma->texpaintslot[i].ima == image) {
+                    ma->paint_active_slot = i;
+                  }
                 }
               }
             }
@@ -732,23 +734,26 @@ void ED_node_set_active(
         /* Sync to Image Editor under the following conditions:
          * - current image is not pinned
          * - current image is not a Render Result or ViewerNode (want to keep looking at these) */
-        Image *image = (Image *)node->id;
-        wmWindowManager *wm = (wmWindowManager *)bmain->wm.first;
-        LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
-          const bScreen *screen = WM_window_get_active_screen(win);
-          LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
-            LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
-              if (sl->spacetype != SPACE_IMAGE) {
-                continue;
-              }
-              SpaceImage *sima = (SpaceImage *)sl;
-              if (sima->pin) {
-                continue;
-              }
-              if (sima->image && ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) {
-                continue;
+        if (node->id != nullptr && GS(node->id->name) == ID_IM) {
+          Image *image = (Image *)node->id;
+          wmWindowManager *wm = (wmWindowManager *)bmain->wm.first;
+          LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
+            const bScreen *screen = WM_window_get_active_screen(win);
+            LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+              LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
+                if (sl->spacetype != SPACE_IMAGE) {
+                  continue;
+                }
+                SpaceImage *sima = (SpaceImage *)sl;
+                if (sima->pin) {
+                  continue;
+                }
+                if (sima->image &&
+                    ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) {
+                  continue;
+                }
+                ED_space_image_set(bmain, sima, image, true);
               }
-              ED_space_image_set(bmain, sima, image, true);
             }
           }
         }



More information about the Bf-blender-cvs mailing list