Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!kent From: kent@swrinde.nde.swri.edu (Kent D. Polk) Newsgroups: comp.sys.amiga.tech Subject: Refreshing a window with gadtools gadgets Keywords: gadtools library Message-ID: <248@swrinde.nde.swri.edu> Date: 13 Dec 90 03:44:15 GMT Organization: Southwest Research Institute, San Antonio, Texas Lines: 113 I have a window which may have 'variable' sets of gadtools gadgets. It determines how to set things up based on a message that very seldom gets sent to it. Done this way: -------- On program startup (abbreviated version) if (!(GfxBase=(struct GfxBase *) OpenLibrary("graphics.library", 36L))) { ... if (!(IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 36L))) { ... if (!(GadToolsBase = OpenLibrary("gadtools.library", 36L))) { ... if (!(mysc = LockPubScreen(NULL))) { ... -------- On each rethink message: if (reinit) closeinit(); /* closeinit can only be called after the first time */ if (!(vi = GetVisualInfo(mysc, TAG_DONE))) { ... if (!CreateAllGadgets(&glist, vi, topborder, num)) { ... /*** Create the Gadget Window ***/ if (!(mywin = OpenWindowTags(NULL, ... /* Add gadgets, refresh them, and call the toolkit refresh */ AddGList(mywin, glist, ((UWORD) -1), ((UWORD) -1), NULL); RefreshGList(glist, mywin, NULL, ((UWORD) -1)); GT_RefreshWindow(mywin, NULL); ----------------------------- When this refresh or 'rethink' message gets sent to my program after the first time, closeinit gets called, which frees the visualinfo, the Gadgets & closes the window as seen in closeinit() below. Now, the window & gadgets get created correctly, but cputrap gives me a rash of invalid memory accesses to FFFFFFFF, typically. I assume I am incorrectly freeing or reallocating resources. What would be the correct method of doing this? ====================================================================== Associated info: struct GfxBase *GfxBase = NULL; struct IntuitionBase *IntuitionBase = NULL; struct Library *GadToolsBase = NULL; struct Screen *mysc = NULL; struct Gadget *glist = NULL; struct Window *mywin = NULL; void *vi = NULL; /******************************/ closeinit() { if (mywin) CloseWindow(mywin); if (vi) FreeVisualInfo(vi); if (glist) FreeGadgets(glist); } /******************************/ struct Gadget *CreateAllGadgets( struct Gadget **glistptr, void *vi, UWORD topborder, UWORD num) { int i, j; struct NewGadget ng; struct Gadget *gad = NULL; gad = CreateContext(glistptr); ng.ng_VisualInfo = vi; ng.ng_LeftEdge = 70; ng.ng_Height = 11; ng.ng_Width = 45; ng.ng_Flags = PLACETEXT_LEFT; for (j=0;j