alternative to saveasdialog_extended(filename, &path, &outtype, &filetype, 1))

Feb 23, 2012 at 12:26am

alternative to saveasdialog_extended(filename, &path, &outtype, &filetype, 1))

hello,
i copied the code from the sdk for the savedialog, but it crashes max6 randomly(filed a bug report already), is there an alternative to
saveasdialog_extended(filename, &path, &outtype, &filetype, 1)) ?? (with max5 it s fine..)
what is coll using for example?
thomas

#61925
Feb 24, 2012 at 2:47pm

Hi,

We’ll need more code than the one line to know what’s happening.

Is filename a string that you _copied_ (strcpy or whatever) from a t_symbol? Or is it just a pointer into the t_symbol->s_name? It needs to be a copy because it might get modified (which would corrupt the symbol table). This is an example of something we can’t tell without more code.

best,
Tim

#223620
Feb 24, 2012 at 3:56pm

hey,
below is the code. i m not passing any arguments, argc is 0, just throwing the save dialog always.
it also does not matter whether i m actually doing something afterwards with the name & path.
below i m doing nothing. what is also really weird is, if i m sending the message with a ;message to a receive object it works(most times). when the write message is directly connected to my object it crashes always.
i tried the same thing with an sdk example, just adding the write message, same thing happens. however in max5 no problems at all.
?? really confused..
thanks in advance for any help
best,
thomas

void note_dowrite(t_note *x, t_symbol *s, short argc, t_atom argv)
{
long filetype = ‘TEXT’, outtype = ‘TEXT’;
char filename[MAX_FILENAME_CHARS];
short path;

if (argc == 0)
{ // if no argument supplied, ask for file
if (saveasdialog_extended(filename, &path, &outtype, &filetype, 1)) // non-zero: user cancelled
return;
} else {
strcpy(filename, s->s_name);
path = path_getdefault();
}
// note_writefile(x, filename, path);
}

void note_write(t_note *x, t_symbol *s, short argc, t_atom *argv)
{
defer(x, (method)note_dowrite, s, 0, NULL);
}
class_addmethod(c, (method)note_write, “write”, A_GIMME, 0);

#223621
Feb 24, 2012 at 5:57pm

with defer_low(x, (method)note_dowrite, s, 0, NULL);
instead of defer it is fine.. thanks anyway,
cheers,
thomas

#223622
Feb 24, 2012 at 7:26pm

A short comment: although argc is always set to 0 (therefore, the else block would never be called), the command strcpy(filename, s->s_name); seems to be a semantic error: in this scenario, the value of s->s_name will always be the string ‘write‘. The actual filename, as a parameter, would arrive in the first argument of the argv list. At least according to what I understood from the SDK documentation (Section 5.2 ‘Writing A_GIMME Functions’ — well, I’m still using the 5.1.7 SDK, so the section might have disappeared or moved in the most recent release).

Best,
Ádám

#223623
Feb 24, 2012 at 8:16pm

@siska, you are correct about the s->s_name containing ‘write’ instead of the filename. the doc is still in the same place in the max 6 sdk.

@thomas, can you tell me which example in the sdk you tried? i’d like to try it myself to see (and possibly fix) the problem.

Thanks!
tim

#223624
Feb 24, 2012 at 8:42pm

hi,
i added the write message to the pictmeter example, in order to check whether the problem might be related to my object, just changed the t_note* to t_pictmeter * .. same behaviour, with defer_low() no problems.
cheers,
thomas

#223625
Feb 27, 2012 at 3:59pm

Hi Thomas,

I still need more info. You implemented your write method with a prototype of

void note_write(t_note *x, t_symbol *s, short argc, t_atom *argv)

but I don’t know what your message minding looks like. If it is the same as the “read” message, which looks like

class_addmethod(c, (method)pictmeter_read,					"read", A_DEFSYM, 0);

Then you will have problems because “read” is not defined as A_GIMME. I’m just left to make guesses like this though because I don’t have the complete source.

Hope this helps,
Tim

#223626
Feb 28, 2012 at 12:09pm

hi timothy,
sorry for being not clear, below are the parts of pictmeter where i modified things. i just messed around with A_DEFSYM and A_GIMME because i thought it might be related to that.

at the bottom you ll find a maxpatcher using pictmeter. the crash is very unpredictable, sometimes sending
the write message directly to pictmeter is ok and via “;” to a receive object crashes max, sometimes it is the other way around.
cheers,
thomas

void note_dowrite(t_pictmeter *x, t_symbol *s, short argc, t_atom argv)
{
long filetype = ‘TEXT’, outtype;
char filename[512];
short path;

//saveas_dialog(filename, &path, NULL);
// if no argument supplied, ask for file
if (saveasdialog_extended(filename, &path, &outtype, &filetype, 1)) // non-zero: user cancelled
return;

}

void note_write(t_pictmeter *x, t_symbol *s)
{
defer(x, (method)note_dowrite, s, 0, NULL);
}

int main(void)
{
t_class *c;

c = class_new(“pictmeter~”, (method)pictmeter_new, (method)pictmeter_free, sizeof(t_pictmeter), 0L, A_GIMME, 0);

c->c_flags |= CLASS_FLAG_NEWDICTIONARY;
jbox_initclass(c, 0);
class_dspinitjbox(c);

class_addmethod(c, (method)pictmeter_dsp, “dsp”, A_CANT, 0);
class_addmethod(c, (method)pictmeter_dsp64, “dsp64″, A_CANT, 0);
class_addmethod(c, (method)pictmeter_paint, “paint”, A_CANT, 0);
class_addmethod(c, (method)pictmeter_assist, “assist”, A_CANT, 0);
class_addmethod(c, (method)pictmeter_acceptsdrag_unlocked, “acceptsdrag_unlocked”, A_CANT, 0);
class_addmethod(c, (method)pictmeter_acceptsdrag_unlocked, “acceptsdrag_locked”, A_CANT, 0);
class_addmethod(c, (method)pictmeter_read, “read”, A_DEFSYM, 0);
class_addmethod(c, (method)note_write, “write”, A_DEFSYM, 0);

CLASS_ATTR_DEFAULT(c,”patching_rect”,0, “0. 0. 128. 128.”);

class_register(CLASS_BOX, c);
s_pictmeter_class = c;
return 0;
}

{
“boxes” : [ {
"box" : {
"maxclass" : "newobj",
"text" : "r toPict",
"numoutlets" : 1,
"id" : "obj-4",
"fontname" : "Arial",
"outlettype" : [ "" ],
“patching_rect” : [ 161.0, 175.0, 48.0, 20.0 ],
“fontsize” : 12.0,
“numinlets” : 0
}

}
, {
“box” : {
“maxclass” : “message”,
“text” : “;rtoPict write”,
“linecount” : 2,
“numoutlets” : 1,
“id” : “obj-3″,
“fontname” : “Arial”,
“outlettype” : [ "" ],
“patching_rect” : [ 298.0, 118.0, 69.0, 33.0 ],
“fontsize” : 12.0,
“numinlets” : 2
}

}
, {
“box” : {
“maxclass” : “message”,
“text” : “write”,
“numoutlets” : 1,
“id” : “obj-2″,
“fontname” : “Arial”,
“outlettype” : [ "" ],
“patching_rect” : [ 368.0, 166.0, 36.0, 18.0 ],
“fontsize” : 12.0,
“numinlets” : 2
}

}
, {
“box” : {
“maxclass” : “pictmeter~”,
“numoutlets” : 0,
“id” : “obj-1″,
“patching_rect” : [ 298.0, 291.0, 128.0, 128.0 ],
“numinlets” : 1
}

}
],
“lines” : [ {
"patchline" : {
"source" : [ "obj-4", 0 ],
“destination” : [ "obj-1", 0 ],
“hidden” : 0,
“disabled” : 0
}

}
, {
“patchline” : {
“source” : [ "obj-2", 0 ],
“destination” : [ "obj-1", 0 ],
“hidden” : 0,
“disabled” : 0
}

}
],
“appversion” : {
“major” : 6,
“minor” : 0,
“revision” : 4
}

}

#223627

You must be logged in to reply to this topic.