Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User KhaledMahmood's Avatar
    Join Date
    Mar 2008
    Posts
    8
    This very simple app to get cell ID raised Panic USER 42 on Exit. Pls help me to come out from this.

    In the emulator the code shows Cell ID as 0, but while exiting it raises the panic: USER 42.
    As USER 42 is abt heap cell pointer, I checked the code throughly, but can't trace any invalid pointer in the code that may cause this panic. I am using Visual Studio 2003 and Carbide 2.0.

    Below the code is given

    Code:
    // CCellIDAppUi.cpp
    
    void CCellIDAppUi::ConstructL()
        {
        // Initialise app UI with standard value.
        BaseConstructL();
    
        // Create view object
        iAppView = CCellIDAppView::NewL( ClientRect() );
    	
        //Create Net Info retriever
        iNetInformer = CNetworkInfo::NewL();
        }
    CCellIDAppUi::CCellIDAppUi()
        {
        // No implementation required
        }
    
    CCellIDAppUi::~CCellIDAppUi()
        {
        if ( iAppView )
            {
            delete iAppView;
            iAppView = NULL;
            }
    
        if(iNetInformer)
    	{
    	delete iNetInformer;
    	iNetInformer = NULL;
    	}
        }
    
    void CCellIDAppUi::HandleCommandL( TInt aCommand )
        {
        switch( aCommand )
            {
            case EEikCmdExit:
            case EAknSoftkeyExit:
                Exit();
                break;
            case ECellIDGetCellID:
                {
    		iNetInformer->GetNetworkInfoL();
                }
                break;
            //default:
                //Panic( ECellIDUi );
                //break;
            }
        }
    
    //NetworkInfo.h
    
    #include <e32base.h>	// For CActive, link against: euser.lib
    #include <etel3rdparty.h> // CTelephony, Link against etel3rdparty.lib
    
    class CNetworkInfo : public CActive
    {
    public:
            static CNetworkInfo* NewL();
            ~CNetworkInfo();
            void GetNetworkInfoL();
     
        protected:
            // from CActive
            void RunL();
            TInt RunError(TInt aError);
            void DoCancel();
     
        private:
            CNetworkInfo();
            void ConstructL();
     
        private:
            CTelephony* iTelephony;
            CTelephony::TNetworkInfoV1 iNwInfo;
            CTelephony::TNetworkInfoV1Pckg iNwInfoPckg;
    };
    
    // NetworkInfo.cpp
    
    #include <aknnotewrappers.h>
    #include "NetworkInfo.h"
    
    CNetworkInfo::CNetworkInfo()
        : CActive(EPriorityStandard),
          iNwInfoPckg(iNwInfo)
        {
        CActiveScheduler::Add(this);
        }
     
    CNetworkInfo* CNetworkInfo::NewL()
        {
        CNetworkInfo* self = new (ELeave) CNetworkInfo;
        CleanupStack::PushL(self);
        self->ConstructL();
        CleanupStack::Pop();
        return self;
        }
     
    void CNetworkInfo::ConstructL()
        {
        iTelephony = CTelephony::NewL();
        }
     
    CNetworkInfo::~CNetworkInfo()
        {
        Cancel();
        delete iTelephony;
        }
     
    // This function is used by our class' users to start getting network info.
    void CNetworkInfo::GetNetworkInfoL()
        {
        __ASSERT_ALWAYS(!IsActive(), User::Leave(KErrInUse));
     
        // Start async call to receive current network information
        iTelephony->GetCurrentNetworkInfo(iStatus, iNwInfoPckg);
        SetActive();
        }
     
    void CNetworkInfo::DoCancel()
        {
        iTelephony->CancelAsync(CTelephony::EGetCurrentNetworkInfoCancel);
        }
     
    void CNetworkInfo::RunL()
        {
        User::LeaveIfError(iStatus.Int());
        // Request completed successfully.
    
        _LIT(KFormatter, "Current Cell ID is: %d");
        HBufC *msg = HBufC::NewLC(31);
    
        msg->Des().Format(KFormatter, iNwInfo.iCellId);
    
        CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
        informationNote->ExecuteLD( *msg );
        CleanupStack::PopAndDestroy(msg);
        }
     
    TInt CNetworkInfo::RunError(TInt aError)
        {
        // There was an error retrieving current network info.
        
         _LIT(KFormatter, "CActive::RunError !!!");
         HBufC *msg = HBufC::NewLC(31);
    
         msg->Des().Format(KFormatter);
    
        CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
        informationNote->ExecuteLD( *msg );
        CleanupStack::PopAndDestroy(msg);
     
        return KErrNone;
        }

  2. #2
    Registered User sriky27's Avatar
    Join Date
    Dec 2005
    Posts
    1,236
    Hi,

    You could try logging and then check at this moment I cannot think of anything else.
    Regards,
    Sriky

  3. #3
    Nokia Developer Champion stenlik's Avatar
    Join Date
    Mar 2004
    Location
    Czech Republic
    Posts
    2,037
    Hi,

    I'm not 100% sure, but you delete in the CCellIDAppUi destructor the CNetworkInfo object, while in the CNetworkInfo destructor you call the Cancel() method, which calls CancelAsync() - as this is asynchronous cancel method - the result might be that OS tries to call the CNetworkInfo::RunL() to inform you that the cancel is complete, while the CNetworkInfo object was already deleted...

    Regards,
    STeN

  4. #4
    Registered User yogpan's Avatar
    Join Date
    Jun 2006
    Location
    India
    Posts
    1,043
    Hi,
    I think StenLik is right .In the destructor of CNetworkInfo class you are directly calling the Cancel() without checking whether there is any request pending or not. It is always a good practice to check if there is any pending request before calling DoCancel() something like
    if(IsActive())
    {
    Cancel();
    }
    Maximus
    S60 Developer
    Impossible is nothing

  5. #5
    Registered User KhaledMahmood's Avatar
    Join Date
    Mar 2008
    Posts
    8
    Cancel()

    IMPORT_C void Cancel();

    Description
    Cancels the wait for completion of an outstanding request.

    If there is no request outstanding, then the function does nothing.

    If there is an outstanding request, the function:

    1. calls the active object's DoCancel() function, provided by the derived class to implement cancellation of the request.

    2. waits for the cancelled request to complete; this must complete as fast as possible.

    3. marks the active object's request as complete (i.e. the request is no longer outstanding).
    And this is the description taken from SDK Doc.

    So how the problem could arise for Cancel() on destructor???

    Regards.

  6. #6
    Registered User yogpan's Avatar
    Join Date
    Jun 2006
    Location
    India
    Posts
    1,043
    Hi,
    Yes u are correct in the description. Thanks for pointing the fact. But the code which you have provided I am not able to figure out any other logical reason for the error. Are you working on emulator then you can try HookLogger to track the issue.
    Maximus
    S60 Developer
    Impossible is nothing

  7. #7
    Nokia Developer Moderator ltomuta's Avatar
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,335
    Yes, the documentation is correct, Cancel includes the check for IsActive internally.

    However,stenlik is saying something entirely different, and that is that CancelAsync is a asynchronous call which will end-up triggering your RunL with a KErrCancel status. One would assume that only after receiving this notification the active object could in fact be deleted

  8. #8
    Nokia Developer Moderator wizard_hu_'s Avatar
    Join Date
    Feb 2006
    Location
    Mallorca, Holiday
    Posts
    27,683
    You should also check that on a real device (enable the panic codes if you have not done so: http://wiki.forum.nokia.com/index.ph...ded_panic_code), telephony support in the emulator may have some problems.

  9. #9
    Registered User KhaledMahmood's Avatar
    Join Date
    Mar 2008
    Posts
    8
    you delete in the CCellIDAppUi destructor the CNetworkInfo object, while in the CNetworkInfo destructor you call the Cancel() method, which calls CancelAsync() - as this is asynchronous cancel method - the result might be that OS tries to call the CNetworkInfo::RunL() to inform you that the cancel is complete, while the CNetworkInfo object was already deleted...
    As told by Stenlik, do u think such situation may arise in my app where CancelAsync() isn't getting called when there are no outstanding request.

    Thanks wizard_hu_ for the link.

    Thanks all for ur prompt response. It’s really encouraging for new Symbian developers.

    Regards.

  10. #10
    Registered User shixuehuiab's Avatar
    Join Date
    Feb 2009
    Posts
    10
    Try this:

    //CleanupStack::PopAndDestroy(msg);

  11. #11
    Registered User sumit.rathi's Avatar
    Join Date
    Jun 2008
    Location
    India
    Posts
    1,048
    Quote Originally Posted by shixuehuiab View Post
    Try this:

    //CleanupStack::PopAndDestroy(msg);
    What would it going to do? Where to put this?

    Well..Trying this will not do anything as it is already commented.

Similar Threads

  1. USER 8 panic with HBUFC - help plzz
    By pranav.g10 in forum Symbian C++
    Replies: 8
    Last Post: 2008-06-28, 13:19
  2. USER 42 Panic Problem!
    By chenhxtony in forum Symbian C++
    Replies: 1
    Last Post: 2008-01-11, 10:30
  3. USER 42 panic
    By Norrit_ in forum Symbian C++
    Replies: 3
    Last Post: 2006-09-14, 05:17
  4. User 11 Panic
    By liadalex in forum Symbian User Interface
    Replies: 0
    Last Post: 2005-01-31, 09:17
  5. user panic 11
    By ebinder in forum Symbian C++
    Replies: 1
    Last Post: 2003-09-26, 14:53

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved