×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    31

    Listbox deletion fails

    Hi

    I'm totally confused what's wrong with my code. I may be blind to my own code, but this has been tough prob. last couple of days. Why does "delete iPositionQuery" cause emulator to crash? I know that it's usually occures because of double deletion, but I cant see such a thing.... :(

    Here is related code:

    Containers member variables:
    Code:
    CAknSingleNumberStyleListBox* iPositionQuery;
    CDesCArray* iItemList;
    second phase constructor:
    Code:
    CreateWindowL();
    	
    /*Construct and prepare listbox*/
    iPositionQuery = new (ELeave) CAknSingleNumberStyleListBox();
    iPositionQuery->ConstructL(this);
    iPositionQuery->SetContainerWindowL(*this);
    iPositionQuery->CreateScrollBarFrameL(ETrue);
    iPositionQuery->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto);	
    
    SetRect(aRect);
    ActivateL();
    Adding items to list:
    Code:
    TInt items = 0;
    _LIT(KListItemFormat, "%d\t%S\t\t");
    	
    /*Count items*/
    for (TInt i = 0; i < aLanes; i++)
    {
      if (aRacerMaskArray[i] == 0){items ++;}
    }
    	
    /*Gather needeed items*/
    CDesCArray* iItemList = new (ELeave) CDesCArrayFlat(items);		
    	 																										
    for (TInt i = 0; i < aLanes; i++)
    {	
      if (aRacerMaskArray[i] == 0)
      {
        TBuf<MaxNameChars> name;
        name.Format(KListItemFormat, (i + 1), (*aDriverArray)[i]);
        iItemList->AppendL(name);		
      }		
    }
    
    iPositionQuery->Model()->SetItemTextArray(iItemList);
    iPositionQuery->Model()->SetOwnershipType(ELbmOwnsItemArray); //or ELbmDoesNotOwnItemArray
    iPositionQuery->HandleItemAdditionL();
    ...and destructor:
    Code:
    if(iPositionQuery)
    {
      delete iPositionQuery;
      iPositionQuery = NULL;
    }
    Please give some tips....thanks

    EDIT: Forget to mention...2nd FP3
    Last edited by Norrit_; 2006-10-18 at 18:16.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,692

    Re: Listbox deletion fails

    The posted code snippets seem to be right, although you have an unused member variable (iItemList), a badly named local variable (iItemList), and since deleting a NULL pointer is a perfect C++ statement, the conditional deletion is not necessary in the destructor (nor the NULL of the variable in fact).
    By the way: could you post the whole destructor code? However you have traced it line-by-line, have not you?

  3. #3
    Registered User
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    31

    Re: Listbox deletion fails

    Thaks so much for answering!

    you have an unused member variable (iItemList), a badly named local variable (iItemList)
    O...I see...I have used CDesCArray* accidently (This is already in .h file). I wonder might it be cause of this...hmm. Purpose was to use membervariable! Is it stupid to use member variable in this case?

    And there aren't anything else in destructor...this should be very siple thing. Yes...I have traced the fault placing break point to destructor and when delete statement is executed, emulator crashes!
    Last edited by Norrit_; 2006-10-19 at 08:46.

  4. #4
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: Listbox deletion fails

    Try changing the line
    name.Format(KListItemFormat, (i + 1), (*aDriverArray)[i]);

    to

    name.Format(KListItemFormat, (i + 1), &(*aDriverArray)[i]);

    The problem is that the listbox is panicking before deleting the listbox

  5. #5
    Registered User
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    31

    Re: Listbox deletion fails

    Hmm...Should notice that earlier too...I have written to my "bug log" that using Format, addresses must be used with it, otherwise it has produced panic Des16Align 18

    ok...I made a correction, but now emulator crashes to line, which I just modified

    Code:
    name.Format(KListItemFormat, (i + 1), &(*aDriverArray)[i]);
    ...and it gives panic USER 11. And it doesn't help, if I define a lot more space to "name" descriptor than it should need...what I'm missing again :(

    Here's also the code, where data is come from.

    Code:
    /*Get driver names to array*/
    RPointerArray<HBufC> *racerNameArray = new (ELeave) RPointerArray<HBufC>;
    CleanupStack::PushL(racerNameArray);
    for (TInt i = 0; i < iLanes; i ++)
    {
      TInt driverNbr = iRaceCombinationsArray[i][(iHeatsRaced - 1)] - 1;
      HBufC* driverName = HBufC::NewLC(MaxNameChars);
      *driverName = iDriverArray[driverNbr].GetName();
      racerNameArray->AppendL(driverName);
      CleanupStack::Pop();//driverName
    }	
    	
    iQuery2Container->ShowResultsQueryLstBoxL(racerNameArray, iRacerMaskArray, iLanes);

  6. #6
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: Listbox deletion fails

    There were all sorts of problems with the code provided I just rewrote it.

    Specifically *driverName = iDriverArray[driverNbr].GetName();
    overwrites driverName so you are probably doing a double delete or corrupted descriptor somewhere

    RPointerArray<HBufC> racerNameArray;
    CleanupResetAndDestroy(racerNameArray);
    for (TInt i = 0; i < iLanes; i ++)
    {
    const TInt driverNbr = iRaceCombinationsArray[i][(iHeatsRaced - 1)] - 1;
    HBufC* name = iDriverArray[driverNbr].GetName().AllocL();
    racerNameArray.Append(name);
    }

    ...

    iQuery2Container->ShowResultsQueryLstBoxL(racerNameArray, iRacerMaskArray, iLanes);

    ..
    CleanupStack::PopAndDestroy(&racerNameArray);

  7. #7
    Registered User
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    31

    Re: Listbox deletion fails

    Thank you all for your answers so far. Despite of good advices I have stil same problem...

    I decided to make things simple...

    Code:
    _LIT(KListItem1, "JoU");
    _LIT(KListItem2, "mAn");
    iItemList = new (ELeave) CDesCArrayFlat(2);
    HBufC* name1 = HBufC::NewLC(10);
    HBufC* name2 = HBufC::NewLC(10);
    
    TPtr strPtr1 = name1->Des();
    TPtr strPtr2 = name2->Des();
    	
    strPtr1.Format(KListItemFormat, 1, &KListItem1);
    iItemList->AppendL(*name1);	
    	
    strPtr2.Format(KListItemFormat, 2, &KListItem2);
    iItemList->AppendL(*name2);
    		
    /*Show listbox*/
    iPositionQuery->Model()->SetItemTextArray(iItemList);
    iPositionQuery->Model()->SetOwnershipType(ELbmOwnsItemArray); //or ELbmDoesNotOwnItemArray
    iPositionQuery->HandleItemAdditionL();	
    	
    CleanupStack::Pop(2);
    Very very simple...should be! But still line "delete iItemList" causes emulator to crash. There aren't anything else in desturctor. What on earth is wrong here?

  8. #8
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: Listbox deletion fails

    First of all you have told the listbox that it owns the array (SetOwnershipType(ELbmOwnsItemArray)), so deleting it will almost certainly fail because it would have been deleted by the listbox model.

    So, what error code are you getting?

  9. #9
    Registered User
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    31

    Re: Listbox deletion fails

    Error is: "Unhandled exception at 0xbaadf00d in epoc.exe: 0x0000005: Access violation reading location 0xbaadf00d"

    Though this means something like double deletion etc. (?)

    So...I have missed domething crucial in symbian development. Please tel me like some stupid baby, what is wrong?

    EDIT: If I use another constant, ELbmDoesNotOwnItemArray, result is the same!

  10. #10
    Registered User
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    31

    Re: Listbox deletion fails

    Could you Paul help me? I'm confused, because I have made this as in example. And I can't understand why debugger crashes in list box deletion...

  11. #11
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: Listbox deletion fails

    I think the problem is somewhere else.

    0xbaadf00d means that the memory was allocated but not initialized, so it is probably a tclass you have called with new.

    iItemList can only be deleted if you have set it so the listbox model does not own the data.

  12. #12
    Registered User
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    31

    Re: Listbox deletion fails

    Thanks all for your patience...like Paul said...problem was elsewhere. I just was jammed to stare list box.

    0xbaadf00d means that the memory was allocated but not initialized, so it is probably a tclass you have called with new.
    Where did you dig this out...wanna know too :)

    Thanks again all who answered this post!!

Similar Threads

  1. Query ~ Listbox | functional but no text
    By series60nubee in forum Symbian
    Replies: 5
    Last Post: 2006-03-24, 06:09
  2. Using a "custom" listbox in mobile s60
    By ctpthanh in forum Symbian User Interface
    Replies: 4
    Last Post: 2005-04-17, 14:46
  3. Hide Listbox not working with MakeVisible(EFalse)
    By Salvesh in forum Symbian User Interface
    Replies: 3
    Last Post: 2005-02-04, 05:04
  4. ListBox Fails On app exit
    By Salvesh in forum Symbian User Interface
    Replies: 2
    Last Post: 2005-02-01, 04:27
  5. listbox and model
    By stenlik in forum Symbian
    Replies: 1
    Last Post: 2004-05-27, 07:27

Posting Permissions

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