|
|
User login
Feeds |
More High Score tutorial woes (USER 11)
|
|||||
| Fri, 2003-09-19 10:05 | |
|
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 |
|
Forum posts: 2029
This was my early time in Symbian Application development.
Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant
Forum posts: 15
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
Forum posts: 15
Gareth Poulton
Forum posts: 2029
Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant
Forum posts: 142
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
Forum posts: 363
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