![]() |
![]() |
![]() |
#1 |
Registered User
![]() Join Date: Sep 2013
Location: Bettendorf, IA, USA
Age: 49
Posts: 204
|
struct Image
My program is having memory losses due to images I am putting in a listbrowser. I know what to do to fix it, I just don't know how.
- Open program, libs, set everything up, open window and gadgets - Get a list of items, will vary in length every time - Call a subroutine to create the listbrowser list - That sub has a struct Image *ImgLabel that I use in a LABEL object with a PENMAP image. - Return to main program body to do some stuff - Go back to sub to fill in listbrowser with new data - etc. Code:
ImgLabel=NewObject(LabelClass,NULL, IA_Font, &xen8, LABEL_Image, myImg, LABEL_Text, " ", LABEL_Text, "The Text", LABEL_DisposeImage, TRUE, TAG_DONE); if (node=AllocListBrowserNode(1, LBNA_Generation, 1, LBNA_Flags, LBFLG_HASCHILDREN|LBFLG_SHOWCHILDREN, LBNCA_Image, ImgLabel, // LBNCA_CopyText, TRUE, // LBNCA_Text, "The Text", LBNA_UserData, "The Text", TAG_END)) AddTail(list,node); @Thomas: Your ListBrowser2 program, for example. When you load a file, how would you add an image to every line so that it gets free'd correctly? Code:
while(!Done) { -create a new struct Image *ImgLabel ???? -do the above code snippet -free the struct ???? -repeat until Done } |
![]() |
![]() |
#2 |
Registered User
Join Date: Apr 2005
Location: Hangover
Posts: 2,860
|
I'm not a C programmer, but struct Image has nothing to do with any string pointers or text.
from structure.guide Code:
Struct Image: $0014 20 sizeof(Image) $0000 0 2 LeftEdge $0002 2 2 TopEdge $0004 4 2 Width $0006 6 2 Height $0008 8 2 Depth $000a 10 4 ImageData $000e 14 1 PlanePick $000f 15 1 PlaneOnOff $0010 16 4 NextImage or struct Image must be the first element in your Object, but as I said, I don't no much about C ... Last edited by PeterK; 04 June 2014 at 05:25. |
![]() |
![]() |
#3 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 6,192
|
FreeListBrowserList frees all memory allocated by AllocListBroserNode for those nodes which are still in the list. If you remove nodes from the list you have to call FreeListBrowserNode for these.
FreeListBrowserList does not free memory you allocated. So in case of the NewObject you call yourself you have to call DisposeObject to free the memory. You could replace FreeListBrowserList by something like this: Code:
void free_listbrowser_list_with_images (struct List *list) { struct Node *node; while ((node = RemTail (list))) { Object *img = NULL; GetListBrowserNodeAttrs (node,LBNCA_Image,&img,TAG_END); if (img) DisposeObject (img); FreeListBrowserNode (node); } } Last edited by thomas; 04 June 2014 at 08:51. |
![]() |
![]() |
#4 |
Registered User
![]() Join Date: Sep 2013
Location: Bettendorf, IA, USA
Age: 49
Posts: 204
|
Thomas, so far so good! Came through again.
Now, when I use your code the screen flashes black. Not every time, maybe every third time. Strange. |
![]() |
![]() |
#5 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 6,192
|
Make sure that you do not free an object which is still in use. For example, first close the window, then dispose the window object (which also disposes of all the gadget objects, including the list browser) and only then free the list.
Also make sure that you do not free an object twice. Like mentioned above, disposing the window object also disposes all dependent objects. So you should not try to free a gadget again which was already freed by the window object. A good help in all memory-related issues is Mungwall. I can only recommend to have Sashimi, Mungwall and some kind of Enforcer (CyberGuard, winuaeenforcer or the like) running all the time while writing programs. |
![]() |
![]() |
#6 |
Registered User
![]() Join Date: Sep 2013
Location: Bettendorf, IA, USA
Age: 49
Posts: 204
|
Hmmmm.......it's not your code causing the black flashes. That is good. My WinUAE is doing it with other things, too, that are totally unrelated. Not sure what is going on.
|
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
PC Image to Amiga Image? | AF2013 | Coders. AMOS | 6 | 21 December 2013 23:36 |
Anyone know where this image came from, what is it? | StoneOakvalley | request.Other | 4 | 05 September 2012 10:42 |
cd32 image..? | spannernick | support.WinUAE | 1 | 21 June 2007 16:50 |
spitting image | rigster | request.Old Rare Games | 2 | 30 September 2004 02:55 |
Iso Image | Carlos Ace | request.Apps | 1 | 18 November 2001 13:41 |
|
|