Commit b038573a authored by pokergaming's avatar pokergaming
Browse files

simplified a trick to make the badarg error "findable" in message boxes

parent c0c9a12d
......@@ -5664,26 +5664,13 @@ static int glist_dofinderror(t_glist *gl, void *error_object)
return (0);
}
extern t_class *messresponder_class;
extern t_class *message_class;
void canvas_finderror(void *error_object)
{
t_canvas *x;
void *error_gobj = error_object;
/* Since the messresponder_class isn't patchable,
we climb up to the parent message_class addy. */
if(((t_gobj *)error_object)->g_pd == messresponder_class)
{
/* do pointer math to potentially get the parent message */
void *msg = error_object - sizeof(t_text);
/* if it looks like a message, it must be a message */
if(((t_gobj *)msg)->g_pd == message_class)
error_gobj = msg;
}
/* find all root canvases */
for (x = canvas_list; x; x = x->gl_next)
{
if ((void *)x == error_gobj)
if ((void *)x == error_object)
{
/* If the error is associated with a toplevel canvas, we
do a quick-and-dirty unvis and vis to give some basic
......@@ -5693,7 +5680,7 @@ void canvas_finderror(void *error_object)
canvas_vis(glist_getcanvas(x), 1);
return;
}
if (glist_dofinderror(x, error_gobj))
if (glist_dofinderror(x, error_object))
return;
}
post("... sorry, I couldn't find the source of that error.");
......
......@@ -530,7 +530,7 @@ typedef struct _message
t_clock *m_clock;
} t_message;
t_class *messresponder_class;
static t_class *messresponder_class;
static void messresponder_bang(t_messresponder *x)
{
......@@ -687,6 +687,19 @@ static void message_free(t_message *x)
clock_free(x->m_clock);
}
t_pd *pd_mess_from_responder(t_pd *x)
{
if (pd_class(x) == messresponder_class)
{
/* do pointer math to try to get to the container message struct */
void *tmp = (void *)x - sizeof(t_text);
/* if it looks like a message, it must be a message */
if(((t_text *)tmp)->te_pd == message_class)
return ((t_pd *)tmp);
}
return x;
}
void canvas_msg(t_glist *gl, t_symbol *s, int argc, t_atom *argv)
{
if (canvas_hasarray(gl)) return;
......
......@@ -689,6 +689,9 @@ typedef t_pd *(*t_fun5)(t_int i1, t_int i2, t_int i3, t_int i4, t_int i5,
typedef t_pd *(*t_fun6)(t_int i1, t_int i2, t_int i3, t_int i4, t_int i5, t_int i6,
t_floatarg d1, t_floatarg d2, t_floatarg d3, t_floatarg d4, t_floatarg d5);
/* needed for proper error reporting */
extern t_pd *pd_mess_from_responder(t_pd *x);
void pd_typedmess(t_pd *x, t_symbol *s, int argc, t_atom *argv)
{
t_method *f;
......@@ -849,6 +852,10 @@ void pd_typedmess(t_pd *x, t_symbol *s, int argc, t_atom *argv)
(*c->c_anymethod)(x, s, argc, argv);
return;
badarg:
/* if x is a messresponder class, tweak it to point to the
message that contains it (so it can be selected when 'Find
Error' is used). */
x = pd_mess_from_responder(x);
pd_error(x, "Bad arguments for message '%s' to object '%s'",
s->s_name, c->c_name->s_name);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment