Commit e751223b authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

fix crashes with [field]

do a proper loadbang for canvas fields (needs more testing)
parent 0a81b530
......@@ -105,6 +105,8 @@ static void glist_readatoms(t_glist *x, int natoms, t_atom *vec,
}
}
void scalar_doloadbang(t_scalar *x);
int glist_readscalar(t_glist *x, int natoms, t_atom *vec,
int *p_nextmsg, int selectit)
{
......@@ -158,6 +160,8 @@ int glist_readscalar(t_glist *x, int natoms, t_atom *vec,
{
glist_select(x, &sc->sc_gobj);
}
/* send a loadbang for any canvas fields in this scalar */
scalar_doloadbang(sc);
return (1);
}
......
......@@ -73,6 +73,8 @@ void word_init(t_word *data, t_template *template, t_gpointer *gp)
/* Here too we're being dangerous-- I'm not unsetting this
gpointer yet. */
gpointer_copy(gp, &wp->w_list->gl_gp);
/* make the parent glist the parent of our canvas field */
wp->w_list->gl_owner = gp->gp_stub->gs_un.gs_glist;
while ((x != s__X.s_thing) && s__X.s_thing)
{
......@@ -93,6 +95,22 @@ void word_init(t_word *data, t_template *template, t_gpointer *gp)
}
}
void scalar_doloadbang(t_scalar *x)
{
t_template *template = template_findbyname(x->sc_template);
t_dataslot *datatypes = template->t_vec;
t_word *wp = x->sc_vec;
int i, nitems = template->t_n;
for (i = 0; i < nitems; i++, datatypes++, wp++)
{
if (datatypes->ds_type == DT_LIST)
{
t_canvas *c = wp->w_list;
pd_vmess((t_pd *)c, gensym("loadbang"), "");
}
}
}
void word_restore(t_word *wp, t_template *template,
int argc, t_atom *argv)
{
......
......@@ -3410,7 +3410,7 @@ static void svg_togui(t_svg *x, t_template *template, t_word *data)
if (x->x_fillopacity.a_flag)
{
gui_s("fill-opacity");
gui_f(fielddesc_getfloat(&x->x_fillopacity.a_attr, template, data, 1));
gui_f(fielddesc_getcoord(&x->x_fillopacity.a_attr, template, data, 1));
}
if (x->x_fillrule.a_flag)
{
......
......@@ -1323,8 +1323,7 @@ static void *field_new(t_symbol *s)
t_field *x = (t_field *)pd_new(field_class);
x->x_s = s;
x->x_canvas = canvas_getcurrent();
// do some error checking here
x->x_template = template_findbyname(x->x_canvas->gl_templatesym);
x->x_template = NULL;
outlet_new(&x->x_obj, &s_list);
return (x);
}
......@@ -1334,31 +1333,56 @@ static void field_set(t_field *x, t_symbol *s)
x->x_s = s;
}
/* Contortions to get and possibly cache template after
the first lookup. We can't get it in field_new because
word_init only sets the template after we've been created. */
static t_template *field_gettemplate(t_field *x)
{
if (x->x_template)
return x->x_template;
else
{
if (x->x_canvas->gl_templatesym)
{
x->x_template = template_findbyname(x->x_canvas->gl_templatesym);
return x->x_template;
}
else
return 0;
}
}
static void field_bang(t_field *x)
{
t_word *vec = x->x_canvas->gl_vec;
t_template *template = x->x_template;
t_symbol *fieldsym = x->x_s;
int onset, type;
t_symbol *arraytype;
if (template_find_field(template, fieldsym, &onset, &type, &arraytype))
t_template *template = field_gettemplate(x);
if (template)
{
if (type == DT_FLOAT)
outlet_float(x->x_obj.ob_outlet,
*(t_float *)(((char *)vec) + onset));
else if (type == DT_SYMBOL)
outlet_symbol(x->x_obj.ob_outlet,
*(t_symbol **)(((char *)vec)+ onset));
else pd_error(x, "field: %s.%s is not a number or symbol",
template->t_sym->s_name, fieldsym->s_name);
t_word *vec = x->x_canvas->gl_vec;
t_symbol *fieldsym = x->x_s;
int onset, type;
t_symbol *arraytype;
if (template_find_field(template, fieldsym, &onset, &type, &arraytype))
{
if (type == DT_FLOAT)
outlet_float(x->x_obj.ob_outlet,
*(t_float *)(((char *)vec) + onset));
else if (type == DT_SYMBOL)
outlet_symbol(x->x_obj.ob_outlet,
*(t_symbol **)(((char *)vec)+ onset));
else pd_error(x, "field: %s.%s is not a number or symbol",
template->t_sym->s_name, fieldsym->s_name);
}
else pd_error(x, "field: %s.%s: no such field",
template->t_sym->s_name, fieldsym->s_name);
}
else pd_error(x, "field: %s.%s: no such field",
template->t_sym->s_name, fieldsym->s_name);
else /* send a bang to signal that we're not in a scalar */
outlet_bang(x->x_obj.ob_outlet);
}
static void field_setvalue(t_field *x, t_symbol *s, int argc, t_atom *argv)
{
t_template *template = x->x_template;
t_template *template = field_gettemplate(x);
if (!template) return;
t_word *vec = x->x_canvas->gl_vec;
t_gpointer *gp = &x->x_canvas->gl_gp;
t_gstub *gs = gp->gp_stub;
......
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