[Bf-blender-cvs] [3a880b820b4] blender-v3.3-release: Fix T101001: crash setting texture node active in certain cases

Philipp Oeser noreply at git.blender.org
Wed Sep 21 14:27:11 CEST 2022


Commit: 3a880b820b4229481ec6dc91a5b597fe50da5926
Author: Philipp Oeser
Date:   Mon Sep 12 13:55:40 2022 +0200
Branches: blender-v3.3-release
https://developer.blender.org/rB3a880b820b4229481ec6dc91a5b597fe50da5926

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 36836ed3691..cdaf2f21be6 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