More High Score tutorial woes (USER 11)

Login to reply to this topic.
Fri, 2003-09-19 10:05
Joined: 2003-08-20
Forum posts: 15
Hi,
I've written a method for the NewLC high score tutorial to return a TBuf<15> string containing a single line of the high score table, thus:
Code:
TBuf<15> CHighScore::ScoreDisplay(TInt aPosition) const
{
TBuf<15> ret;
TInt score;
TPlayerName name;

score=(&(*iScoreTable)[aPosition-1])->Score(name);
ret.Format(_L("%d. %d - %s"), aPosition, score, name.Ptr());
 return ret;
}

Here's the weird thing: In debug mode, it works fine. Entries displayed as they should. But in release mode (and on the phone itself), it panics with USER 11. If I take 'name' out of the equation then it works fine, so I'm assuming it's something going badly wrong with how it works, but since I can't use the debugger to see what's going wrong I'm completely lost.

Here's what the docs say about USER 11:
Quote
This panic is raised when any operation that moves or copies data to a 16 bit variant descriptor, causes the length of that descriptor to exceed its maximum length. It may be caused by any of the copying, appending or formatting member functions and, specifically, by the Insert(), Replace(), Fill(), Fillz() and ZeroTerminate() descriptor member functions. It can also be caused by the SetLength() function. See TDes16.

Any ideas / suggestions?

Gareth

Gareth Poulton


Fri, 2003-09-19 10:17
NewLC AdministratorSymbian AccreditedForum Nokia Champion
Joined: 2003-01-14
Forum posts: 2029
More High Score tutorial woes (USER 11)
I think that I really should rewrite this stuff   Sad
This was my early time in Symbian Application development.

Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant

Fri, 2003-09-19 10:43
Joined: 2003-08-20
Forum posts: 15
More High Score tutorial woes (USER 11)
hmm. replacing the Format line with

Code:
ret.Format(_L("%1d. %4d - %3s"), aPosition, score, name.Ptr());

seems to have stopped the USER 11s. Now all I have to figure out is the random garbage bytes that have started seeping in...

Gareth Poulton

Fri, 2003-09-19 11:12
Joined: 2003-08-20
Forum posts: 15
More High Score tutorial woes (USER 11)
(and just to qualify to the passing reader, neither of these things are the fault of the High Score tutorial, which is most helpful and useful. Keep 'em coming, eric! Smiley )

Gareth Poulton

Fri, 2003-09-19 13:22
NewLC AdministratorSymbian AccreditedForum Nokia Champion
Joined: 2003-01-14
Forum posts: 2029
More High Score tutorial woes (USER 11)
Tx  Cheezy

Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant

Mon, 2003-09-22 03:58
Joined: 2003-04-01
Forum posts: 142
More High Score tutorial woes (USER 11)
Hi

Just wanted to have a comment on your code. The biggest problem with your implementation is that you are declaring a automatic variable, that is supposed to be used only inside the function it self, but instaed you go and return it to the caller, in most cases it propably works fine, but there is most definetely times that it will fail, just depends on is somebody actually uses the memory location for something else before you'll use it.
Anyway, easy fix goes like this:

Code:

void CHighScore::ScoreDisplay(TInt aPosition, TDes& aString) const
{
   TInt score;
   TPlayerName name;

   score=(&(*iScoreTable)[aPosition-1])->Score(name);
  aString.Format(_L("%d. %d - %s"), aPosition, score, name.Ptr());
}  


yucca
Mon, 2003-09-22 08:17
Joined: 2003-05-27
Forum posts: 363
More High Score tutorial woes (USER 11)
Hi Yucca,

What you said is not correct - there are no automatic variables returned in that piece of code, because the "return" statement creates a copy of the buffer. So there should be no problem there. I do agree, however, that the method signature is highly misleading and should be changed.

Cheers,
Pawel
  • Login to reply to this topic.