From eb144b6f2cb6f51a260097eeaa625ff174020d8b Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Sat, 20 Jun 2020 17:40:11 -0400
Subject: [PATCH] fix a crasher when attempting to resize a nested gop by
 dragging its corner

We were erroneously using canvas_getrootfor instead of glist_getcanvas to
find the canvas on which the nested gop was being displayed.

Also added a consistency check to turn such a crasher into a runtime bug
in the future.
---
 pd/src/g_canvas.c |  2 +-
 pd/src/g_graph.c  | 11 +++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/pd/src/g_canvas.c b/pd/src/g_canvas.c
index d3ed51dab..ef28e956c 100644
--- a/pd/src/g_canvas.c
+++ b/pd/src/g_canvas.c
@@ -2399,7 +2399,7 @@ void canvasgop__motionhook(t_scalehandle *sh, t_floatarg mouse_x,
            that is being used to draw the gop red rect move anchor atm. So
            rather than muck around with that code, we just set a pointer to
            whatever our toplevel is here: */
-        t_glist *owner = canvas_getrootfor(x);
+        t_glist *owner = glist_getcanvas(x);
         /* Just unvis the object, then vis it once we've done our
            mutation and checks */
         gobj_vis((t_gobj *)x, owner, 0);
diff --git a/pd/src/g_graph.c b/pd/src/g_graph.c
index fcaa0b44b..f1a166da2 100644
--- a/pd/src/g_graph.c
+++ b/pd/src/g_graph.c
@@ -879,6 +879,7 @@ static void graph_vis(t_gobj *gr, t_glist *parent_glist, int vis)
     char tag[50];
     t_gobj *g;
     int x1, y1, x2, y2;
+    t_rtext *rtext;
         /* ordinary subpatches: just act like a text object */
     if (!x->gl_isgraph)
     {
@@ -886,6 +887,14 @@ static void graph_vis(t_gobj *gr, t_glist *parent_glist, int vis)
         return;
     }
 
+        /* Sanity check */
+    rtext = glist_findrtext(parent_glist, &x->gl_obj);
+    if (!rtext)
+    {
+        bug("graph_vis");
+        return;
+    }
+    sprintf(tag, "%s", rtext_gettag(rtext));
     // weird exception
     //int exception = 0;
     //t_canvas* tgt = glist_getcanvas(x->gl_owner);
@@ -896,8 +905,6 @@ static void graph_vis(t_gobj *gr, t_glist *parent_glist, int vis)
     //}
     //fprintf(stderr,"tgt=.x%lx %d\n", (t_int)tgt, exception);
 
-    sprintf(tag, "%s", rtext_gettag(glist_findrtext(parent_glist, &x->gl_obj)));
-
     if (vis & gobj_shouldvis(gr, parent_glist))
     {
         int xpix, ypix;
-- 
GitLab