×

Discussion Board

Results 1 to 9 of 9

Thread: HBufC problem

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    20

    Smile HBufC problem

    Hi,

    I am facing problem when using the HBufC, I am instantiating a class(which contains HBufC) in the AppUI of the application and trying to access the same data from a view.
    However, when i try to access the HBufC (frm view) it is giving a panic citing that the memory i am referring to is not valid. So, i had to reallocate memory again. Isnt this accounting to a memory leak ? Or Am i doing something stupid ?

    ==========
    Regards,
    Eswar.

  2. #2
    Super Contributor
    Join Date
    Mar 2004
    Location
    Czech Republic
    Posts
    2,037

    Re: HBufC problem

    Hi,

    well to be able to give the advice, please cut&paste here piece of your code. If you have a PANIC, then something went really wrong...
    BR
    STeN

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    20

    Re: HBufC problem

    Hi,

    I have declared the HBufC in a class which i use in the appui

    I am doing this in the constructor

    iUname = HBufC::NewL( 15 );

    however, when i try to copy some data ( another view is activated ) by accessing through the appui at this point

    iUname->Des().Copy(aUname);

    it is giving a panic of user 42 which says that the data isnt available any more. Even trying to reallocate the buffer is giving the same panic. Can you please explain, why this strange behaviour ? I am testing this in the emulator.

    Thanks

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,763

    Re: HBufC problem

    What is aUname? Can it happen that you pass a local variable to it? I am not sure if view-activation is a synchronous process. Anyway, you can check the control flow in a debugger.

  5. #5
    Super Contributor
    Join Date
    Mar 2004
    Location
    Czech Republic
    Posts
    2,037

    Re: HBufC problem

    Hi,

    the aUname data could not be valid anymore I guess. Instead of allocating the fixed lenght buffer use something like:

    Code:
    iUname = aUname.AllocL();
    BR
    STeN

  6. #6
    Registered User
    Join Date
    May 2007
    Posts
    20

    Re: HBufC problem

    Since it is a copy i dont think it should matter if it is a local variable. Even AllocL does the same copy but allocates memory to a HBuf, if i am right.
    The problem seems to be in the AppUI, I added a class so that it can hold application level data to it. However, surprisingly the heap allocated data for the class added to it simply disappears( sorry i couldnt find a better word ) though the T variable data is usable. When i use the class with the Document class of the application it is fine again.
    Could someone be kind enough to explain this behaviour to me ?

  7. #7
    Registered User
    Join Date
    Jan 2004
    Posts
    44

    Re: HBufC problem

    Maybe you are copying your "aUname" through a superclass type that holds no data?
    Make sure you are using a reference or pointer in this case (e.g. "TDesC& aUname" or "TDesC* aUname")

    You could post some actual code too...

  8. #8
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: HBufC problem

    Then in a debugger, step through your constructor, look at the address of iUname and look at its memory location contents in the debugger, now run to the code where the panic is happening and see if the memory or contents has changed in an unexpected way. If it has then you are scribbling over it so use the debugger to find out where.

  9. #9
    Registered User
    Join Date
    May 2007
    Posts
    20

    Wink Re: HBufC problem

    @mikaellaine : Yes, I am using a reference that contains a data.
    @hotcheese : I have used the debugger the memory becomes invalid as soon as a new view is launched. The class isnt turning to NULL though.

    Sorry for the trouble guys. I have found an alternate way as said in the previous post. Simply using the class in the document class instead of appui solved the problem. I would have loved to post the code but 300-400 lines for some silly problem i might have done seems inappropriate. I dont want to waste the champions time here . I just wanted to know it is not due to the framework.

    Thanks. Have fun.

Similar Threads

  1. netcards - Problem with opening adapter
    By kernj in forum Symbian Tools & SDKs
    Replies: 5
    Last Post: 2007-01-10, 09:56
  2. WAP service problem on Apache
    By bigg_o in forum Browsing and Mark-ups
    Replies: 3
    Last Post: 2005-04-17, 16:05
  3. Problem: S60 SDK for CW in PC with .NET
    By anttij in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2005-02-28, 12:36
  4. HBufC and CleanupStack problem
    By Rx-lee in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2005-02-01, 20:54

Posting Permissions

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