From 0bda995a59c8e97c5fb0573fbd73cbfa83b64132 Mon Sep 17 00:00:00 2001 From: Guillem <guillembartrina@gmail.com> Date: Mon, 17 Aug 2020 19:52:27 +0200 Subject: [PATCH] return a dummy object when creating [ab] objects during ab definitions loading, to prevent creation errors from being displayed. show the cycle that is causing the dependency problem when an ab object cannot to create --- pd/src/g_canvas.c | 29 ++++++++++++++++++++++------- pd/src/g_editor.c | 12 ++++++------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/pd/src/g_canvas.c b/pd/src/g_canvas.c index 95b8b5a70..198f9cc44 100644 --- a/pd/src/g_canvas.c +++ b/pd/src/g_canvas.c @@ -1960,24 +1960,32 @@ static t_canvas *canvas_getrootfor_ab(t_canvas *x) } /* check if the dependency graph has a cycle, assuming an new edge between parent and current nodes */ -static int ab_check_cycle(t_ab_definition *current, t_ab_definition *parent) +static int ab_check_cycle(t_ab_definition *current, t_ab_definition *parent, int pathlen, char *path, char *res) { if(current == parent) + { + sprintf(path+pathlen, "[ab %s]", current->ad_name->s_name); + strcpy(res, path); return (1); + } else { + int len = strlen(current->ad_name->s_name); + sprintf(path+pathlen, "[ab %s]<-", current->ad_name->s_name); + pathlen += (len+7); int i, cycle = 0; for(i = 0; !cycle && i < current->ad_numdep; i++) { - cycle = ab_check_cycle(current->ad_dep[i], parent); + cycle = ab_check_cycle(current->ad_dep[i], parent, pathlen, path, res); } + pathlen -= (len+7); return (cycle); } } /* try to register a new dependency into the dependency graph, returns 0 if a dependency issue is found */ -static int canvas_register_ab(t_canvas *x, t_ab_definition *a) +static int canvas_register_ab(t_canvas *x, t_ab_definition *a, char *res) { t_canvas *r = canvas_getrootfor_ab(x), *c = x; @@ -1993,7 +2001,9 @@ static int canvas_register_ab(t_canvas *x, t_ab_definition *a) if(!found) { - if(!ab_check_cycle(f, a)) + char path[MAXPDSTRING]; + sprintf(path, "[ab %s]<-", a->ad_name->s_name); + if(!ab_check_cycle(f, a, strlen(path), path, res)) { a->ad_dep = (t_ab_definition **)resizebytes(a->ad_dep, sizeof(t_ab_definition *)*a->ad_numdep, @@ -2231,11 +2241,15 @@ static void canvas_abframe(t_canvas *x, t_float val) abframe = val; } +extern t_class *text_class; + /* creator for "ab" objects */ static void *ab_new(t_symbol *s, int argc, t_atom *argv) { if(abframe) - return (0); + /* return dummy text object so that creator + does not throw an error */ + return pd_new(text_class); t_canvas *c = canvas_getcurrent(); @@ -2256,14 +2270,15 @@ static void *ab_new(t_symbol *s, int argc, t_atom *argv) source = canvas_add_ab(c, name, b); } - if(canvas_register_ab(c, source)) + char res[MAXPDSTRING]; + if(canvas_register_ab(c, source, res)) { newest = do_create_ab(source, (argc ? argc-1 : 0), (argc ? argv+1 : 0)); source->ad_numinstances++; } else { - error("ab_new: can't insantiate ab within itself"); + error("ab_new: can't insantiate ab within itself\n cycle: %s", res); newest = 0; } } diff --git a/pd/src/g_editor.c b/pd/src/g_editor.c index e526e1fb6..53117ec88 100644 --- a/pd/src/g_editor.c +++ b/pd/src/g_editor.c @@ -1425,10 +1425,10 @@ void canvas_reload_ab_rec(t_canvas *x, t_ab_definition *a, t_gobj *e) { canvas_create_editor(x); - if (!x->gl_havewindow) //necessary? - { - canvas_vis(glist_getcanvas(x), 1); - } + //if (!x->gl_havewindow) //necessary? + //{ + // canvas_vis(glist_getcanvas(x), 1); + //} if (!found) { glist_noselect(x); @@ -1465,8 +1465,8 @@ void canvas_reload_ab_rec(t_canvas *x, t_ab_definition *a, t_gobj *e) g = g->g_next; } - if (!hadwindow && x->gl_havewindow) - canvas_vis(glist_getcanvas(x), 0); + //if (!hadwindow && x->gl_havewindow) + // canvas_vis(glist_getcanvas(x), 0); } /* --------- 6. apply ----------- */ -- GitLab