×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    92

    Listbox Icons crash

    Hi,

    I have a listbox which I dynamically add icons to with the following code:

    Code:
    	CArrayPtr< CGulIcon >* icons = iListBox->ItemDrawer()->ColumnData()->IconArray();		
    	CleanupStack::PushL( icons );
    	CGulIcon* icon;
    	icon = CGulIcon::NewL(aBitmap, NULL);
    	icon->SetBitmapsOwnedExternally(ETrue);
    	CleanupStack::PushL( icon );
    	icons->AppendL( icon );
    	CleanupStack::Pop( icon );
    	CleanupStack::Pop( icons );
    	
    	if ( icons != NULL )
    		{
    		iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );
    		return (icons->Count() - 1);
    		}
    	
    	return 0;
    The bitmaps are also used in a different place, so I did SetBitmapsOwnedExternally(ETrue) so the listbox wont delete my bitmaps and they are deleted somewhere else.
    In some cases I want to clear my listbox and load new icons.
    This is my code for clearing the listbox (I'm leaving the first icon in the list because I still need it):

    Code:
    	CArrayPtr< CGulIcon >* icons = iListBox->ItemDrawer()->ColumnData()->IconArray();
    	if (icons->Count() > 1)
    		{
    		for (TInt i=1;i<icons->Count();i++)
    			{
    			CGulIcon* icon = (*icons)[i];
    			delete icon;
    			}
    		icons->Delete(1, icons->Count()-1);
    		icons->Compress();
    		}
    
    ((CDesCArray*)iFreelineFriendsContainer->ListBox()->Model()->ItemTextArray())->Reset();
    	iFreelineFriendsContainer->ListBox()->Reset();
    In the first time I load the icons and list data, everything works fine.
    but when I want to load a new data, it crashes.
    I do not know where because the call stack shows me the RunApplication line.
    but if I don't load the icons to the listbox, everything works well.
    so I'm guessing I'm doing something wrong in the attached code.

    Thanks.

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: Listbox Icons crash

    ok, the thing is that you are telling the gul icon that all stuff inside it is externally owned, but then again the actual gul icon is owned by the listbox, since you give it the array of Gul icons, who are not owning the bitmaps in it..So it is still simple dounble deletion issue.

    anyway, next time please do remember to include the crash code, this time I'm assuming that it is Kern-Exec 3.

  3. #3
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    92

    Re: Listbox Icons crash

    Quote Originally Posted by symbianyucca View Post
    ok, the thing is that you are telling the gul icon that all stuff inside it is externally owned, but then again the actual gul icon is owned by the listbox, since you give it the array of Gul icons, who are not owning the bitmaps in it..So it is still simple dounble deletion issue.

    anyway, next time please do remember to include the crash code, this time I'm assuming that it is Kern-Exec 3.
    I'm not sure I understood..
    The icon array owns the gulicons. so he deletes them.
    but the gulicons does not own the bitmaps. so they aren't being deleted.
    so what's the problem?

    should I create a copy of the bitmap for the gulicon?

    Thanks.

  4. #4
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: Listbox Icons crash

    The problem is that the icons are never deleted, since they are not saved nor owned by anybody, and then the Gulicons are owned by the listbox, since they were given to it in the array, thus deleting them by yourself, will cause a memory violation error, whenever the listbox tries to delete the array..

    anyway, I would suggest you to try letting the listbox to handle the icons completely.. Would save your development time most likely..

  5. #5
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    92

    Re: Listbox Icons crash

    Quote Originally Posted by symbianyucca View Post
    The problem is that the icons are never deleted, since they are not saved nor owned by anybody, and then the Gulicons are owned by the listbox, since they were given to it in the array, thus deleting them by yourself, will cause a memory violation error, whenever the listbox tries to delete the array..

    anyway, I would suggest you to try letting the listbox to handle the icons completely.. Would save your development time most likely..
    What do you mean by "let the listbox handle the icons" ?
    I have add icons dynamically because I'm getting them from a remote server.
    and I want to remove them later because I need to replace them with new ones.
    Should I create a copy of the bitmap and make it owned by the gulicon?

    Thanks.

  6. #6
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: Listbox Icons crash

    simply let the gul icons to own the bitmaps, and let the listbox own the array, and as the gulicons are in the array, they are nicely deleted when you add a new icon array to the listbox.

  7. #7
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    92

    Re: Listbox Icons crash

    Quote Originally Posted by symbianyucca View Post
    simply let the gul icons to own the bitmaps, and let the listbox own the array, and as the gulicons are in the array, they are nicely deleted when you add a new icon array to the listbox.
    Ok, so if I want to use the bitmap in another place, then I need to create a copy of it, right?
    and another question, I always want the first icon in the array to stay.. so if I'm creating a new icon array, I need to make a copy of that gulicon and put it in the new array?

    Thanks.

  8. #8
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: Listbox Icons crash

    I think it would be easiet to handle that way really..

  9. #9
    Regular Contributor
    Join Date
    Jun 2009
    Posts
    92

    Re: Listbox Icons crash

    Quote Originally Posted by symbianyucca View Post
    I think it would be easiet to handle that way really..
    I created a copy of the bitmap for the GulIcon to own and everything works fine now.
    Thanks.

    by the way, I made the copy with CFbsBitmap.Duplicate(), for future reference...

Similar Threads

  1. icons in listbox
    By sneha27 in forum Symbian
    Replies: 9
    Last Post: 2009-06-01, 14:57
  2. how to display the Listbox
    By arungupta_2jan in forum Symbian
    Replies: 4
    Last Post: 2009-03-03, 21:10
  3. icons not showing in listbox
    By adamlah in forum Symbian
    Replies: 6
    Last Post: 2009-01-29, 09:54
  4. Listbox icons in S60 v3 Scalable UI
    By PawelDefee in forum Symbian
    Replies: 6
    Last Post: 2006-12-31, 18:25
  5. listbox with icons
    By betasuppe in forum Symbian User Interface
    Replies: 7
    Last Post: 2004-11-25, 08:19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×