From eea40f6600ac4b7cdcbf9d488e25d4f1c7ddb6d8 Mon Sep 17 00:00:00 2001
From: Sojourner Truth <jon.w.wilkes@gmail.com>
Date: Sat, 23 Jul 2016 00:52:21 -0400
Subject: [PATCH] use glist_isvisible to protect against sending messages to
 GUI before the relevant canvas exists

---
 pd/src/g_canvas.c |  2 +-
 pd/src/g_editor.c |  3 ++-
 pd/src/g_graph.c  |  4 +++-
 pd/src/g_scalar.c | 10 ++++++----
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/pd/src/g_canvas.c b/pd/src/g_canvas.c
index 650982b1e..0ece98d49 100644
--- a/pd/src/g_canvas.c
+++ b/pd/src/g_canvas.c
@@ -690,7 +690,7 @@ void canvas_dirty(t_canvas *x, t_floatarg n)
     if ((unsigned)n != x2->gl_dirty)
     {
         x2->gl_dirty = n;
-        if (x2->gl_havewindow) // was glist_isvisible(x2)
+        if (x2->gl_havewindow && glist_isvisible(x2))
             canvas_reflecttitle(x2);
     }
 }
diff --git a/pd/src/g_editor.c b/pd/src/g_editor.c
index 77b649787..7d11efdc6 100644
--- a/pd/src/g_editor.c
+++ b/pd/src/g_editor.c
@@ -7230,7 +7230,8 @@ void canvas_editmode(t_canvas *x, t_floatarg fyesplease)
             //dpsaha@vt.edu called to delete the GOP_blob
             if (x->gl_goprect)        canvas_draw_gop_resize_hooks(x);
         }
-        canvas_setcursor(x, CURSOR_RUNMODE_NOTHING);
+        if (glist_isvisible(x))
+            canvas_setcursor(x, CURSOR_RUNMODE_NOTHING);
     }
     if (glist_isvisible(x))
     {
diff --git a/pd/src/g_graph.c b/pd/src/g_graph.c
index eee928cd5..b5a7bfde5 100644
--- a/pd/src/g_graph.c
+++ b/pd/src/g_graph.c
@@ -1426,7 +1426,9 @@ static void graph_select(t_gobj *z, t_glist *glist, int state)
         {
             canvas = glist;
         }
-        if(glist_istoplevel(glist))
+        if (glist_isvisible(glist) &&
+                (glist_istoplevel(glist) ||
+                 gobj_shouldvis(x, glist)))
         {
             if (state)
                 gui_vmess("gui_gobj_select", "xs",
diff --git a/pd/src/g_scalar.c b/pd/src/g_scalar.c
index fa4764c2a..28b7b3c99 100644
--- a/pd/src/g_scalar.c
+++ b/pd/src/g_scalar.c
@@ -606,14 +606,16 @@ void scalar_select(t_gobj *z, t_glist *owner, int state)
     if (state)
     {
         x->sc_selected = owner;
-        gui_vmess("gui_gobj_select", "xs",
-            glist_getcanvas(owner), tagbuf);
+        if (glist_isvisible(owner))
+            gui_vmess("gui_gobj_select", "xs",
+                glist_getcanvas(owner), tagbuf);
     }
     else
     {
         x->sc_selected = 0;
-        gui_vmess("gui_gobj_deselect", "xs",
-            glist_getcanvas(owner), tagbuf);
+        if (glist_isvisible(owner))
+            gui_vmess("gui_gobj_deselect", "xs",
+                glist_getcanvas(owner), tagbuf);
     }
     //sys_vgui("pdtk_select_all_gop_widgets .x%lx %lx %d\n",
     //    glist_getcanvas(owner), owner, state);
-- 
GitLab