PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Debugging Axim Problems

My game hangs on the Axim X5 Advanced, seemingly randomly, yet fairly reliably. It doesn't crash or throw an exception, it just hangs. Hekkus continues to play music in its own thread, otherwise I only have one thread (standard GapiDraw 2.04 application).

It doesn't hang like this on other devices.

What could cause this particular behaviour? I hear memory leaks or unaligned data access, but I don't seem to be leaking (I check the structures) and I'm not doing anything fancy like packing data.

So I added a lot of logging to a file to determine where the hang occurs (by know what the last thing logged was). I log using _ftprintf and fflush. I write a line per processFrame, with '<' at the beginning and '>' and a newline at the end. In between I write various numbers.

Now, looking at a log file from an Axim X5 Advanced where it hung, I see thousands of null bytes at the end, presumably where the hang occurred.

However, I see these null bytes can begin right in the middle of a number being printed to the log file. Now, I was doing an fflush to ensure that the log file was accurate. Is this method unreliable? What does it mean?

Does anyone have any idea how to debug this? Approaches to use? Why the app hangs but doesn't crash? Places to look and things to try?
Does it crash on other Axim X5 units?
Many a year ago I spent a long, long time trying to figure out why my PSX game crashed on the debug unit, but not on the dev system. I looked at all the difference between the units... more memory, different CD drivers, blah, blah, blah. Turns out it was just the debug unit was broken!!
Never trust hardware. ;)
Also... we've been getting quite a few reports of freezes when our game is run from SD. Maybe the Axim is running the game from SD??

Cheers,

rcp
I downloaded it and tried it on my Axim X5 and I can confirm that yes it hangs on more than one Axim X5. Very strange and it does seem to act like a memory leak / overrun. Might want to re-check and make sure that your not cutting your self short on a buffer. It feels like something is stepping on the memory and it does tend to hang in different senarios. These are the fun bugs to track down ;). Best of luck!
To my knowledge, it's hung on every X5 Advanced that it's been tested on (about half a dozen, most running 2002, some running 2003), hasn't hung on the one X5 Basic it has been tested on, and hasn't been tested on any X3 devices.

However I have made some progress this evening with the help of egarayblas and denthorq to test on iPAQ 1910.

On the 1910, it was failing to start a new game with an out of bounds exception (0xc0000005). It would replay a recorded game fine.

As with the Axim, I was tracking down the problem by adding more and more logging to a file, having testers run the executable, and checking the log file to see if it narrowed down the problem.

With the 1910 exception, we narrowed the problem down to a small piece of code, and finally adding some logging code that eliminated the problem.

Normally, this indicates two things: that timing affects it, or it is a code generation (typically optimizer) problem. In this case, it was traced to a specific log statement, in a specific location, so it was a code generation problem, not a timing problem.

This is the second major code generation problem I've encountered. I detailed the first here a few months ago:

http://www.pocketmatrix.com/forums/view ... c&start=15

You'll note that the previous one, I reproduced in a minimal sample application. It is indeed a compiler bug, check the code yourself if you doubt this.

So what's happening? The statement after the special logging statement was a call to my repeatKey function. This function only does work during new games, which explains why it doesn't fail during recorded games. Then it uses a series of if-else-if statements to pick a key code (these basically depend on the control orientation). Finally it does some indexing into a container of 256 elements (keys). It only repeats every 4 frames, and the exception occurred on the 4th frame of the game.

Now, the previous compiler bug also happened with if-else-if (and switch) statements. So I thought I had it all figured out. The only intriguing thing is that the log statements in that function didn't fix it, and changing to an if-if statement also didn't fix it (though it did fix the previous compiler bug). Why does the log statement before the function call affect the code generated in that function? I'm not sure why, but I'm pretty sure that's what is happening. I just have to do more testing to isolate the cause and effect, but my 1910 testers are sleeping right now, don't wake them.

Anyways, back to Axim. My 1910 tester, now that he could run the game, had the good fortune to experience a hang while the log file was rolling. Analysis of the log file and the code suggested that it was hung in my custom waitForNextFrame function.

This function has no loops, but does call Sleep. So that's an obvious culprit. If that argument were somehow getting corrupted, my application would sleep for a long time and appear to be hung. Also, one Axim tester actually experienced my application "unhang" itself when left long enough, so this fits the evidence.

I'm still not sure why the argument would be corrupted. It's calculated from QueryPerformanceCounter, but not checked. I'm going to add some checking of the value to try to detect if it is becoming abnormal. I still have to check the code for coding errors, but if I don't find any, I will have to figure out why it would become bad.

I still wonder if QueryPerformanceCounter is affected by the XScale's scaling capabilities. The docs say no but I remain suspicious. I asked this a few weeks ago but never received an answer.

I had my tester capture another hang to compare for reproducibility. Thi s hang's log was different. It was like the Axim log which stopped right in the middle of fprintfing a %d integer. Again I'm not sure why that would be the case, with fflush, but I'll continue to suspect the Sleep argument until I can prove otherwise.

So to sum up, I believe a compiler bug is the cause of the 1910 exception, though I'm unsure of the exact trigger at the moment. And I believe a wild sleep could be the cause of my hang, though again I'm unsure of the mechanism which would cause this (and it's definitely more prevalent on some devices).

I don't suspect memory leaks or memory trampling. I use the STL throughout, both 4.5.3 and the newer 5.0 beta. So I'm not allocating or deallocating my own data structures. The STL containers mostly contain ints by value, not pointers or objects. Only a few of them change size once the application has run (using insert and erase). And most traversals are straightforward begin to end.

It's possible that the STL itself is being corrupted by compiler bugs. I do not trust eVC3 anymore.
I very highly suggest a tool like DevPartner Studio for things like this, and just in general anyway. It'll catch a great many things that you may not without pulling all your hair out. I'm not sure if it would have helped you in this case or not, but that doesn't change it's worth in my mind.
It looks good Frank but it's nearly us$ 900 so while I might go for their 14 day trial period I'm unlikely to buy. VS.NET 2003 cost me several hundred UKĀ£ and in my mind an add on should cost a lot less.

Can it be used with eVC in any way? All my problems happen on the ARM device not in the VC6 version so that's where the problem solving has to happen ( mainly memory allocation / allignment errors which others seem to have as well )

ps: What's happening with your latest game? saw the 'removed' post on the GD forum :?:
mlepage wrote:I'm still not sure why the argument would be corrupted. It's calculated from QueryPerformanceCounter, but not checked. I'm going to add some checking of the value to try to detect if it is becoming abnormal. I still have to check the code for coding errors, but if I don't find any, I will have to figure out why it would become bad.

I still wonder if QueryPerformanceCounter is affected by the XScale's scaling capabilities. The docs say no but I remain suspicious. I asked this a few weeks ago but never received an answer.


QueryPerformanceCounter() is really unreliable on some desktop PC with certain motherboards. I've seen the counter jump forward or backward several hours for no apparent reason. Some other desktop CPU don't support it at all or have a "counter" that simply stay stucked on a number.

It could be that you are encountering similar problem. I would suggest to use GetTickCount() on the PPC and see if it solves the issue. In any case, GetTickCount() is safer and should provide you with enough precision to control your frame rate.
I just added some checking to tell if that is the problem.

I will consider switching to GetTickCount. If QueryPerformanceCounter has any problems and GetTickCount is adequate, then it's a good idea.
Yes, DevPartner is rather expensive. I have the good fortunate of having a copy at work, so I can run my code against it there, but not at home. I couldn't afford it myself at this point.

I don't think it works with eVC (although I have a vague memory of a version for CE)... However, it finds flaws in your code that you may not notice until they bite you, even if your desktop builds are usually no problem.

From my own experience with my current project, I can say that my desktop build has had just about zero problems throughout development, but when the inevitable problems arises on the PPC, I then run DevPartner against the desktop build and sure enough it'll find something that when fixed takes care of the PPC problem. For whatever reason (I'd better memory management and availability 99.99% of the time!), the desktop build tends to be more fault-tolerant in general.

I'm just about ready for beta, and I'm happy to say I can run with DevPartner error checking and it finds nothing, and my PPC build is very stable at this point, so it has helped me immensely.

As for my game, the post that was removed was my bitch post, but I am still working on K&G; Arcade using GD (I may in fact even be moving to v3.01, I'll decide later this weekend), and in fact beta testing is supposed to begin this week. Coding is all done, I'm just waiting for a few late-arriving final graphics and it can go out to testers. I'm hoping no later tham this weekend. I was trying for a 3/31 release, but it's looking like the first week in April now, assuming no major problems found during testing. The official site is up by the way (http://www.kgarcade.com), and it's even RELATIVELY up to date!
Pejo Software - Per · 25 Mar 2004, 17:50 UTC
Marc,
I could give you a working version of Beshaped 2. It uses QueryPerformanceCounter and if it also hangs your will strengthen the hypothesis that this is the error and if it doesn't I guess you can exclude QureyPerformanceCounter from being the villain.
Pejo Software - Per wrote:Marc,
I could give you a working version of Beshaped 2. It uses QueryPerformanceCounter and if it also hangs your will strengthen the hypothesis that this is the error and if it doesn't I guess you can exclude QureyPerformanceCounter from being the villain.


Just because your game uses QueryPerformanceCounter() doesn't mean it can't be the cause of Marc's problem.

Marc: Use GetTickCount(). If it still freeze, you can look elsewhere.
Related to evc3 compiler bugs just give a look at http://www.pocketmatrix.com/forums/view ... hp?t=12005
Here you can find info on how to use evc4 compiler and linker for your evc3 apps. Just for fun I have tested the bug you have descrived here http://www.pocketmatrix.com/forums/view ... c&start=15 and with the latest compiler the bug gone away. It should fix several optimizing bug so it worth a try.
It doesn't hang on my iPAQ 3970, only on Dell Axim X5 Advanced and iPAQ 1910. So I can't test the problem myself, I have to rely on other testers. In the future I will look into getting one of these "problem" devices, but that doesn't help me today.

I added some logging to tell me if the application is going to sleep for a "bad" amount of time. If an X5 or 1910 owner could PM me to test this, then we'll know.

Pejo: have an X5 Advanced owner try your program.

Right now, this fits the data. It seems my app hangs while others do not (they get exceptions or crashes). I don't suspect memory access errors or leaks, but I do calculate my own sleep times using QueryPerformanceCounter results. If these were incorrect, my app would sleep and appear to be hung. In fact, one tester did say it "unhung" once after tens of minutes, and this could happen if it happened to sleep for that length of time. Others don't have this problem because they typically do not do their own sleep calculations, or if they do, use GetTickCount.

So I want to see if logging shows the smoking gun to be the sleep time, then fix it by changing to GetTickCount. But either way, I can't test on my device, it doesn't exhibit the problem.
Gersen, I could swear I read somewhere that using the eVC4 compiler/linker causes some compatibility issues for PPC2000 (and maybe 2002?) devices... Anyone remember anything like that?
Is eVC4 free? How much does it cost?

Can you produce a build that works on 2002, 2003, and 2000?

Are there any gotchas with it, or is it universally better than eVC3?
Pejo Software - Per · 25 Mar 2004, 18:24 UTC
Thierry":3caap81f]

Yes, of course! don't know what I was thinking!
mlepage wrote:Is eVC4 free? How much does it cost?

Can you produce a build that works on 2002, 2003, and 2000?

Are there any gotchas with it, or is it universally better than eVC3?


You are still compiling with EVC3? Ouch!

EVC4.0 can be downloaded just like EVC3.0. What I did is simply add EVC4.0's \bin directory to my EVC3's executable path as described by Refractor (?) and others.

This way, when I work in EVC3, it uses EVC4's compiler. You can then target PPC2000/2002 with EVC3 and it will use EVC4's compiler. The resulting code will work on all PPCs.
You have to wonder if it is truly a defect within QPC on this Dell device, why hasn't any other game suffered the same sort of hanging problem?

If I had to guess, I'd say that your app is not taking into account possible roll-over of QPC values and you're incorrectly calculating how long to sleep.
To add to Digby's comment: if it was a compiler bug, I would expect your game to fail on all devices. Not only 1 or 2.
If I had to guess I'd say you've got some really obscure bug hidden deep in your code and it only manifests on that specific hardware. I've seen that happen so many times that I would automatically assume it in this case. The problem was even more pronounced with MIPS and SH3 builds. ARM was generally the most forgiving platform, and certain bugs would only manifest for MIPS and SH3 even though they were in the ARM build too.

Dan East
There are two problems.

I believe the compiler bug produces an out of index error which just happens to work on most devices, but causes an exception on iPAQ 1910. I still have to confirm this. At any rate, this is unrelated to the QPC and timing issue.

I believe the timing issue is likely caused by QPC only on Dell devices. It's possible the QPC is wrapping, my new version will discover if that is the case.

I don't believe there is a bug lurking in my code that is causing the first problem. It may be the case, but I don't believe so, a compiler bug is simply more likely at this point. Try to understand that I am not trying to blame the compiler, it's simply the most likely culprit at this point given the physical evidence and past history.
Thierry":37tula9v]

Yes I mentioned earlier I was using eVC3. Ideally, I'd track down these two problems, everything would test OK on all devices, I'd release, then I'd upgrade to eVC4, test again, and release an update. I'd rather not switch at this time if I can help it, I just don't have the beta testers I had a few weeks ago to ensure other problems haven't cropped up.
Well, I copied over a BIN directory from eVC4 WCE400 as detailed in the linked thread and tried to compile. It chokes on STLport 5.0 BETA. I went to the STLport forums to see if there are issues with eVC4, but the forums are currently out of order, hopefully they didn't lose everything.

I suppose I could try the compiler from WCE420, or revert to STLport 4.5.3, but this is getting ridiculous.
Mmm you don't need to copy anything, just add EVC4's bin directory to your executable path in EVC3.0.

I don't know about STLport... I had to work quite hard to make it work inside EVC4.0's environment, but it still works in EVC3.0's environment (using EVC4.0's compiler).

Are you following all this? =)
I made a build using STLport 4.5.3 and the WCE400 compiler. It's about 13KB smaller.It seems about 1ms faster on my iPAQ 3970.
Downloading EVC4 just now (over 200Mb). I notice there's an SP3 download, another 50+ meg. Should I install as well?

Just to be clear, as well as adding the evc4 compiler's path to evc3 should I remove the evc3 path (if it's there? haven't looked yet)

ps: I hope 4 is not on the vs.net 2003 cd's cause if it is I'm downloading without need
I did the directory swap-n-copy trick.
Conan wrote:Just to be clear, as well as adding the evc4 compiler's path to evc3 should I remove the evc3 path (if it's there? haven't looked yet)


No, you don't need to remove the EV3 path. Just put the EV4 one before the EVC3 one and you will be fine.
OK, with the invaluable help of my Axim testers, I have discovered the cause of the Axim hang. It occurs when the QPC wraps. However, the problem is more complicated than that. I wrote my code to handle QPC wrapping, but it still fails. The reason is that the Axim uses only 32 bits of the 64 bit QPC. Basically, it wraps every 19.41 minutes, and it doesn't actually wrap but rather jumps 32 bits in value.

What's even more strange, though, is that the version I made which uses GetTickCount instead, doesn't work at all on Axim. it works on PC, and on iPAQ 3970 and iPAQ 1910, but not Axim X5 Advanced. I can't think of why this would be. I'm still investigating it.
What do you mean by "jump 32 bits in value"?

Say the QPC is at 00000000FFFFFFFFh, what will be the next value?

The GetTickCount() problem could be related?
On Axim, it only uses the lower 32 bits of value for the QPC. So when it "wraps" it effectively jumps values. You can't just rely on subtraction to take care of it, you have to detect it and handle it.

I was told via PM that Axim did this, and in fact that's what I narrowed it down to and confirmed to be the cause of the hangs.

Actually, it never hung, it just slept for about 20 minutes every 20 minutes. :-)
That's just evil. Please let us know what the deal is with GetTickCount and if it has some sort of problem too.
I don't think GetTickCount has problems, it's just something in my current codebase isn't agreeing with it. (Part of the problem is having timing code which can use either method, and keeping everything organized.) I fixed one thing, so games play properly with GetTickCount now, but my timing code still thinks something is wrong when a game is finished. I don't see anything bad in the code, and I don't have a device to test on myself, so it'll be a few days before I can figure it out. At least everything is working properly with QPC.