kent@swrinde.nde.swri.edu (Kent D. Polk) (12/13/90)
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<num;j++) { ng.ng_TopEdge = topborder + w_HEIGHT*j + 5*j; ng.ng_GadgetText = GadLabels[0]; ng.ng_GadgetID = j * MAXCHANNELS; gad = CreateGadget(CYCLE_KIND, gad, &ng, GTCY_Labels, ChanLabels, GTCY_Active, OFF, TAG_DONE); for (i=1;i<NUMGADS-1;i++) if (gad) { ng.ng_TopEdge = ng.ng_TopEdge + topoffset; ng.ng_GadgetText = GadLabels[i]; ng.ng_GadgetID = j * MAXCHANNELS + i; gad = CreateGadget(SLIDER_KIND, gad, &ng, GTSL_Min, SliderMin[i], GTSL_Max, SliderMax[i], GTSL_Level, SliderLevel[i], TAG_DONE); } /* ... some more stuff like this */ } return (gad); } Thanks Much, ==================================================================== Kent Polk - Southwest Research Institute - kent@swrinde.nde.swri.edu "Well... can't you get a Novell card for your Cray ?" ====================================================================