PDA

View Full Version : Memory Management and plugins


bsupnik
28th May 2004, 04:53 AM
Hi Y'all,

First of all, Andy, great job witih the plugin system. It took less than two hours to write a basic exporter from AC3D to the X-Plane object format, and the vast majority of that was because I was stupidly and stubbornly trying to compile a Windows DLL plugin on my Mac with CodeWarrior (it does work, but the linker settings are non-obvious). I've been able to implement a number of features in the plugin very easily...very nice.

First question: is there a good cross-platform way to bring up a "select a file" type dialog box? I'm currently using the common file dialogs on Windows, but this code will have to be reimplemented on Unix/Linux. Is there a standard way to do this with Tcl or the plugin API?

Second question: when should I and when should I not free a linked list that I get back from the plugin APIs? Right now I never free them, which never crashes, but is probably bad house keeping.

*Cheers*
Ben

PS, my plugin reads and writes the x-plane object format and also provides some additional editing operations.
http://www.x-plane.com/

Andy
28th May 2004, 12:05 PM
Thanks Ben.

Use these - they will work on any platform:

Prototype char *ac_get_load_filename(char *title, char **suffix);
Prototype char *ac_get_import_filename(char *title, char **suffix);
Prototype char *ac_get_save_filename(char *title, char **suffix);
Prototype char *ac_get_export_filename(char *title, char **suffix);

e.g.

static void savepng_go()
{
char *filter[] = { "PNG files", "*.png", "All files", "*", NULL };

char *fname = ac_get_export_filename("Save 3d win as png", filter);
if (STRINGISEMPTY(fname))
return;
save_image(fname);
}

For linked lists, look in the plugin header - a comment at the prototype will tell you if you need to free the thing that's returned. Most of the functions don't, since they just return the pointer to the linked list e.g.

Prototype List *ac_object_get_vertexlist(ACObject *ob);

freeing this list would causes a swift crash.

If you are adding or removing stuff from objects - always use the other functions e.g. ac_object_add/remove... because they may do other stuff (like change vertex counters etc) - don't edit the lists directly - treat them as read only.

Andy

bsupnik
28th May 2004, 01:53 PM
ac_get_load_filename...perfect...and right under my nose! Thanks!

*cheers*
Ben