×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    229

    Talking Why can not push the CConsoleBase-object in CleanupStack?

    Hi:
    Everyone!

    Why can not push the console-object in CleanupStack?


    We can create a CConsoleBase object use below

    Code:
      TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(
    			KConsFullScreen, KConsFullScreen)));
    If we use below

    Code:
    TInt E32Main()
    	{
    	__UHEAP_MARK;
    
    	CTrapCleanup* cleanupStack=CTrapCleanup::New();
    	console=Console::NewL(KTitle,TSize(KConsFullScreen,KConsFullScreen));
    	CleanupStack::PushL(console);
    
    
            CleanupStack::PopAndDestroy(console);
             delete cleanupStack;
    
    	__UHEAP_MARKEND;
    
    	return KErrNone;
    	}
    It will be wrong, and the app will crash!


    what's the reason, please give a hand,very thanks!
    Last edited by GFYsweetwood; 2009-04-11 at 08:06.

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

    Re: Why can not push the CConsoleBase-object in CleanupStack?

    What is the crash code ?
    And does createError contain any error code ?

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    282

    Re: Why can not push the CConsoleBase-object in CleanupStack?

    You cant push anything on cleanup stack untill and unless you are in a trap harness. Thats why you are experiencing the E32User CBase 66 panic.

    Console::NewL or CleanupStack::PushL(console) can leave so it needs a trap harness in its call. That is why call this this method is called inside a TRAP. You need to modify your code to the following to get it working:


    TRAPD(err,
    console=Console::NewL(KTitle,TSize(KConsFullScreen,KConsFullScreen));
    CleanupStack::PushL(console);
    CleanupStack::PopAndDestroy(console);
    );

    Hope that helps,
    VJ
    Last edited by vaibhavjain; 2009-04-11 at 09:31.

  4. #4
    Super Contributor
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: Why can not push the CConsoleBase-object in CleanupStack?

    Quote Originally Posted by vaibhavjain View Post
    You cant push anything on cleanup stack untill and unless you are in a trap harness. Thats why you are experiencing the E32User CBase 66 panic.

    Console::NewL or CleanupStack::PushL(console) can leave so it needs a trap harness in its call. That is why call this this method is called inside a TRAP. You need to modify your code to the following to get it working:


    TRAPD(err,
    console=Console::NewL(KTitle,TSize(KConsFullScreen,KConsFullScreen));
    CleanupStack::PushL(console);
    CleanupStack::PopAndDestroy(console);
    );

    Hope that helps,
    VJ
    Yes you are right, trap harness is needed to push element on cleanup stack. But the way you mentioned will not make any sense, since after execution of TRAPD console is not available anymore. So to push CConsoleBase on cleanup stack you need write one method and call that method from trap harness in E32Main(), and call all other(except creation of cleanup stack)functionality of E32Main() from that method.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    229

    Talking Re: Why can not push the CConsoleBase-object in CleanupStack?

    symbianyucca ,vaibhavjain ,savaj,
    Thank you very much,you give me a big help!

    like vaibhavjain says,the code working fine,below is "helloworld" app main method:

    following, we call it "Code1"

    Code:
    GLDEF_C TInt E32Main()
    	{
    	// Create cleanup stack
    	__UHEAP_MARK;
    	CTrapCleanup* cleanup = CTrapCleanup::New();
    	
    	TRAPD(err,
    	console=Console::NewL(KTextConsoleTitle,TSize(KConsFullScreen,KConsFullScreen));
    	CleanupStack::PushL(console);
    	
    	
    	TRAPD(mainError, DoStartL());
    		if (mainError)
    			console->Printf(KTextFailed, mainError);
    		console->Printf(KTextPressAnyKey);
    		console->Getch();
    		
    		
    	CleanupStack::PopAndDestroy(console);
    	);
    
    	if( err )
    		return err;
    
    	//delete console;
    	delete cleanup;
    	__UHEAP_MARKEND;
    	return KErrNone;
    	}
    it working fine,but we can not make a breakpoint and debug it,I don't know the reason.


    if we run below code,the app will crash
    following, we call it "code2":


    Code:
    GLDEF_C TInt E32Main()
    	{
    	// Create cleanup stack
    	__UHEAP_MARK;
    	CTrapCleanup* cleanup = CTrapCleanup::New();
    
    	// Create output console
    	TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(
    			KConsFullScreen, KConsFullScreen)));
    	if (createError)
    		return createError;
    	
    	TRAPD( err, CleanupStack::PushL( console ) );
    	
    	if (err)
    			return err;
    
    	
    	TRAPD(mainError, DoStartL());
    	if (mainError)
    		console->Printf(KTextFailed, mainError);
    	console->Printf(KTextPressAnyKey);
    	console->Getch();
    	
    	CleanupStack::PopAndDestroy( console );
    		
    	//delete console;
    	delete cleanup;
    	__UHEAP_MARKEND;
    	return KErrNone;
    	}
    when the app run the code:TRAPD( err, CleanupStack::PushL( console ) );
    it will crash , the emulator exit and the TRAPD can not catch the error code.

    why?that's too strange!

  6. #6
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Why can not push the CConsoleBase-object in CleanupStack?

    It more looks like a Panic to me not a Leave.

  7. #7
    Registered User
    Join Date
    Jan 2007
    Posts
    282

    Re: Why can not push the CConsoleBase-object in CleanupStack?

    Hi,

    Another point that you missed while using the cleanupstack :-). The number of cleanupstack elements when entering a trap harness should be same as the number of elements while leaving the trap harness. This rule is applicable when there is no leave in the TRAP.

    In case of the leave all the elements pushed in cleanup stack within this harness are destroyed.

    So in your case the statement TRAPD( err, CleanupStack::PushL( console ) ); will definitly cause a panic E32User CBase 71. As you have pushed an element in the trap harness but havent poped it off at its end. Documentation of E32User CBase 71 panic in sdk doc has more details on this. If you want to get your code running try making following changes:


    TRAPD(mainError,
    CleanupStack::PushL( console );
    DoStartL());
    CleanupStack::PopAndDestroy( console );
    );

    if (mainError)
    console->Printf(KTextFailed, mainError);
    console->Printf(KTextPressAnyKey);
    console->Getch();

  8. #8
    Super Contributor
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: Why can not push the CConsoleBase-object in CleanupStack?

    Quote Originally Posted by vaibhavjain View Post


    TRAPD(mainError,
    CleanupStack::PushL( console );
    DoStartL());
    CleanupStack::PopAndDestroy( console );
    );

    if (mainError)
    console->Printf(KTextFailed, mainError);
    console->Printf(KTextPressAnyKey);
    console->Getch();

    Will console still accessible after destroying it in trap harness???

  9. #9
    Registered User
    Join Date
    Jan 2007
    Posts
    282

    Re: Why can not push the CConsoleBase-object in CleanupStack?

    Oops... may be it was post number #113 tridec effect..:-).
    Thanks for pointing this out. Below is the corrected code:

    TRAPD(mainError,
    CleanupStack::PushL( console );
    DoStartL());
    CleanupStack::Pop( console );
    );

    if (mainError)
    console->Printf(KTextFailed, mainError);
    console->Printf(KTextPressAnyKey);
    console->Getch();

    delete console;

  10. #10
    Super Contributor
    Join Date
    Feb 2006
    Location
    Beijing
    Posts
    4,361

    Re: Why can not push the CConsoleBase-object in CleanupStack?

    Here is the guide from SDK help documents:
    » Symbian OS v9.1 » Symbian OS guide » Base » Using User Library (E32) » Memory Management » Using Cleanup Support » Exception Handling » How to use TRAP
    Stay Hungry. Stay Foolish.
    Sina Weibo:
    http://weibo.com/cxt728
    QQ Weibo:
    http://t.qq.com/Cxt_programmer

  11. #11
    Super Contributor
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: Why can not push the CConsoleBase-object in CleanupStack?

    Or you can move initialization of CConsoleBase to DoStartL(), like.

    LOCAL_C void DoStartL()
    {
    // Create active scheduler (to run active objects)
    CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
    CleanupStack::PushL(scheduler);
    CActiveScheduler::Install(scheduler);

    // Create output console
    console = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen, KConsFullScreen));

    CleanupStack::PushL(console);
    MainL();

    console->Printf(KTextPressAnyKey);
    console->Getch();

    // Delete active scheduler
    CleanupStack::PopAndDestroy(console);
    CleanupStack::PopAndDestroy(scheduler);
    }

    // Global Functions

    GLDEF_C TInt E32Main()
    {
    // Create cleanup stack
    __UHEAP_MARK;
    CTrapCleanup* cleanup = CTrapCleanup::New();

    TRAPD(mainError, DoStartL());
    if (mainError)
    return mainError;

    delete cleanup;
    __UHEAP_MARKEND;
    return KErrNone;
    }

Similar Threads

  1. Replies: 0
    Last Post: 2007-03-27, 12:44
  2. Replies: 9
    Last Post: 2006-08-10, 09:51
  3. Object Push format 6310/7650
    By in forum Bluetooth Technology
    Replies: 1
    Last Post: 2003-03-17, 10:52
  4. Object Push format 6310/7650
    By in forum Bluetooth Technology
    Replies: 0
    Last Post: 2003-03-13, 08:45
  5. Object Push Profile - OBEX
    By Nokia_Archive in forum Bluetooth Technology
    Replies: 1
    Last Post: 2002-05-28, 14:38

Posting Permissions

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