×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    6

    My setting item crashes machine but not the emulator

    I have a normal setting item list, where I create 2 integer setting items (CMyIntegerSettingItem).
    It creates the list and the items can be edited.

    When one item is pressed it opens an integer query dialog,
    number can be entered, but when OK is pressed the application
    crashes with 'KERN-EXEC 3'. This does not happen in emulator,
    or when CANCEL is pressed.

    Here the code involved:

    //CAlarmMyIntegerSettingItem header
    class CAlarmMyIntegerSettingItem : public CAknIntegerSettingItem
    {
    public:
    CMyAlarmIntegerSettingItem(TInt aIdentifier, TInt& aValue);
    void SetValue(TInt &aValue);
    void EditItemL( TBool /*aCalledFromMenu*/ );
    private:
    TInt myIndex;
    };

    //CMyIntegerSettingItem .cpp
    CAlarmMyIntegerSettingItem::CAlarmMyIntegerSettingItem(TInt aIdentifier, TInt& aValue)
    : CAknIntegerSettingItem(aIdentifier, aValue), myIndex(aIdentifier)
    {
    }

    void CAlarmMyIntegerSettingItem::SetValue(TInt& aValue)
    {
    SetExternalValue(aValue);
    LoadL();
    UpdateListBoxTextL();
    }

    void CAlarmMyIntegerSettingItem::EditItemL( TBool /*aCalledFromMenu*/ )
    {
    TInt number;
    CAlarmModel::GetSnoozeRepeat(number);
    CAknNumberQueryDialog* numberDialog = CAknNumberQueryDialog::NewL(number);
    if (numberDialog->ExecuteLD(R_ALARM_SNOOZE_INTERVAL_LAYOUT))
    {
    SetValue(number);
    CAlarmModel::SetSnoozeRepeatL(number);
    }
    }

    //Setting list data (create setting item)
    CAknSettingItem* CAlarmListbox::CreateSettingItemL( TInt aIdentifier )
    {
    CAknSettingItem* settingItem = NULL;
    TInt *num;

    switch (aIdentifier)
    {
    case EAlarmSettingSnoozeInterval:
    CAlarmModel::GetSnoozeInterval(*num);
    settingItem = new (ELeave) CAlarmMyIntegerSettingItem(aIdentifier, *num);
    break;
    .
    .
    .
    }

    The application crashes even if the CAlarmModel function
    GetSnoozelInterval did nothing but simply put a value in the
    given parameter and SetSnoozeInterval function was empty.

    How can one determine which part of the code crashes the
    application when it does not crash in the emulator?

    Thanks

    -Pepe

  2. #2
    Regular Contributor
    Join Date
    May 2003
    Location
    Nice, France
    Posts
    123
    Well, you have many reasons why it could crash...

    -----------------------------------------------

    //Setting list data (create setting item)
    CAknSettingItem* CAlarmListbox::CreateSettingItemL( TInt aIdentifier )
    {
    CAknSettingItem* settingItem = NULL;
    TInt *num;

    switch (aIdentifier)
    {
    case EAlarmSettingSnoozeInterval:
    CAlarmModel::GetSnoozeInterval(*num);
    settingItem = new (ELeave) CAlarmMyIntegerSettingItem(aIdentifier, *num);
    break;
    .
    .
    .
    }

    Err...
    TInt *num;
    At that point <num> is undefined - it may contain everything..
    Then, you are using it:
    CAlarmModel::GetSnoozeInterval(*num);

    You are dereferencing an undefined value. So, it's not surprising that it is crashing :-)

    -----------------------------------------------

    void CAlarmMyIntegerSettingItem::EditItemL( TBool /*aCalledFromMenu*/ )
    {
    TInt number;
    ...
    SetValue(number);
    ...
    }

    Your SetValue stores the <address> of number, not its value (you have a TInt& parameter, so the address of the TInt is pushed, not its value). But as soon as you leave the EditItemL, that address is no more valid, so if you use the address you stored in SetValue, it's a potential crash too!

    Good luck,
    Daniel.
    Last edited by dchiaramello; 2003-07-30 at 17:35.

Posting Permissions

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