Add isDisposed checking to avoid unexpected NPE
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 30 Sep 2020 05:41:03 +0000 (08:41 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 30 Sep 2020 05:42:10 +0000 (08:42 +0300)
In this case ctx.getContentContext() would return null when the canvas
context was already disposed.

gitlab #614

(cherry picked from commit 930da66f9b2d7d1acba3e5dc805a323933abb780)

bundles/org.simantics.g2d/src/org/simantics/g2d/gallery/GalleryViewer.java

index 5bbe9f26e7de24047b90c875f8e66809d542b897..d09ecf4a6b6f753f7f0adbf57060b3a36ac987c1 100644 (file)
@@ -631,8 +631,10 @@ public class GalleryViewer extends ContentViewer {
                 ctx.getThreadAccess().asyncExec(() -> {
                     //System.out.println(Thread.currentThread() + ": update scene graph(" + el + ")");
                     // Update scene graph and repaint.
-                    el.getElementClass().getSingleItem(GalleryItemSGNode.class).update(el);
-                    ctx.getContentContext().setDirty();
+                    if (!ctx.isDisposed()) {
+                        el.getElementClass().getSingleItem(GalleryItemSGNode.class).update(el);
+                        ctx.getContentContext().setDirty();
+                    }
                 });
                 break;
             }