PocketMatrix forums

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

X Scale freezes

Hola. My first topic here so forgive me if I sound enthusiatic =P

I've recently developed a couple of apps, one using the pocketfrog libraries by Thierry and one using EVC's own MFCs.

My problem is both games can run fine on my ipaq 3870 and someone's 36xx series but I've had a couple of reports that it causes Toshiba (X-scale) and the 3970 (also X-scale) to freeze on some occasions.

I have no idea how that could happen because the one using MFC does not use external classes at all and it can still freeze? Well yes it could be my coding that really sux0rz but I cannot find a clue as to why.

My only assumption is that my file reading/writing routine could cause their systems to freeze. I use a text file as storage (check high scores for the game and ctreectrl items for the app). I access the text file quite often, maybe once in every 2 secs. The way I do it right now is that I read the whole file, store it into an array, edit some entries and write a new file with the same name to save the array. I believe there's a better way to do this but I have no idea how.

Does anyone here think that could be the problem? If so then how come I can do so many things on my strongARM and not encounter the same problem?

If file access is the problem, then is there a better solution? I dont know, if there is, please teach me.

Thanks in advance.

masCh
I access the text file quite often, maybe once in every 2 secs.


Why? If you're reading it into an array, then why output it so often?
So that the data gets saved on any changes.
Ok. Next question is "why save on any change"? Can you not save at the end of a game?
How often are you saving this file? Are you *sure* it freezes or is it just processing so much that it appears to freeze, it doesn't take much to run into the halting problem with such small memory and processor speeds. This has happened to me a few times, however all cases were bugs, only some were true freezes.

I assume this file is some state for your game? It would be a good idea to only save it when needed, likely only when they exit. But if you have a game options menu where this data can be changed you can just save after they leave that, if its game data and you don't have a particular save function, then again do it when they exit or quit.

Another suggestion if the data is strickly options and such is to use the registry instead of files. But if you are accessing this every 2 seconds, then you might run into the same problems. More info on what you are doing now might be useful, like this array you speak of is that declared on the heap (ie new'd)?
Umm okay, I have never new'd an array. Could that be the problem?

You mean like
new datatree[10] = new array[10] right?


Nope never done that =P
masCh wrote:
Umm okay, I have never new'd an array. Could that be the problem?

You mean like
new datatree[10] = new array[10] right?


Nope never done that =P


That syntax isn't correct.
Code:

//This pointer will store the address of the mem we allocate
int *pNumbers;

//Allocate an array of 10 ints and assign to pNumbers
pNumbers=new int[10];


Dan East
My comment on the array was that you should avoid using new, especially if you do this every time you load and save your file (ie every 2 seconds).
Hrmm, I've changed my code so that it doesnt save states every 2 secs. Now if the user presses something then I save to file.

The problem code I think is with my CTreeCtrl object. I cannot detect if the user hit the checkbox or no. I dont know how to use HitTest. So to save myself from headaches I'd just save the file every few secs. If I can detect if the user hits the checkbox then I can get rid of that part of the code. The checkbox was made using the dialog wizard with the checkbox option turned on.

The problem with my game is also during file access. Both in my game and this CTreeCtrl app I used arrays to store file data. So my X-Scale freezing problem could be either the array or the file opening/writing/reading.

My biggest question is probably why does it only happen with X-Scale devices? I dont have an X-Scale device and I could not test my codes extensively on it.
More than likely you have a bug in your code that only manifests on that hardware. I've seen that type of thing happen many, many times. Typically it is from writing past the end of an array.

Dan East
masCh, follow Dan's suggestion and do some "bounds checking" (assert() could be a starter).
I can't believe there is a problem in the OS for reading/writing/accessing files for the relatively LONG time period of once in two seconds. This would be discovered long time ago I think.

Just a question. Why do you want to really save the file that often? Afraid of resets? Do you use that file in different processes/threads (possible deadlock?). You can use memory mapped files for that case, may be worth to try.
Hrmm I have no idea what Dan said =) If you write past an array wont that give you an error? Like out of bounds or something. I thought I've seen that happen. I'm assuming you mean int array[30] and I try to write array[30]=20; That would give it an error wont it?

Deje, how do you use assert and what does it do? Will it terminate the program if it finds a buggy array or something?

Answer to your question, yeah afraid of resets and crashes and all data will be lost. I only use one data file per app so far. But I dont think its because I access files often.. because in my other software (the game) I only check/write high scores and that causes problems in some 39xx series. I only do that once.

What is a memory mapped file? Dont need a major description, just a small one so I can decide if I want to really take a look at it and then I'll search for it on the web.

I'm starting to think that its because I save file states in the array and the problem could be somewhere there.

I dont have my code with me here at work or I could post what I'm doing.

By the way, thanks for all the help so far guys, I just realized there are so many things I've overlooked
No, you won't get an error if you write past the bounds of an array. Unfortunately in that respect, this isn't Java!

I know this from recent experience... My current project I had an array that gets cleared at the beginning of various screens in the game. Well, I was off by 1 when clearing the array, and what would happen is that if I compiled the program as a debug build, no problem manifested itself. However, when I switched to a release build, a completely unrelated screen was giving me problems.

I know that release builds by default turn off array bounds checking, and my assumption is that those checks, which would be present in a debug build usually, just stop the overwrite from happening, but still give no error. I could be wrong about that.

It was either that, or it must have been laying the allocated array memory out differently in release vs. debug and the off-by-one loop was only causing a problem when it was layed out a certain way, i.e., how it was in the release build (spent the better part of a day walking through code line-by-line banging my head against the desk before I figured that one out).

So, ignoring my pointless and somewhat off-topic babbling...

Could it be a debug vs. release build issue?

And in either case, you won't get any error if you overwrite bounds arrays. C just isn't that nice!

Also, your thought that if might not be the file access but the array maniulations should be easy to test: simply comment out the code that writes to a file, but leave all the array stuff intact. If it's the array code, you should still see your freezes.

A memory-mapped file by the way is basically just a file that you treat as a chunk of memory. Not sure that would really benefit you much here, but that's a very simplistic explanation anyway.
One thing to bear in mind is that you shouldn't let the software read+write to a flash-media frequently (because it'll destroy the media).
I have since removed arrays altogether but still have reports of it freezing. File access isnt done very often now. How do you use text files? Do you use FILE * stream or is there another way?

One thing to note is that xscale freezes when the user switches to Transcriber mode and tries to key in data at the input field. It doesnt always happen, but when it happens, transriber was used. Any ideas?
Does the Debug build crash too? Try debugging directly on your device, then break into the code when it freezes. If an exception is being thrown then eVC will alert you. If you're stuck in an infinite loop then when you hit break you'll see where the problem is at.

Debugging is very slow over USB, so hopefully you have ethernet or WiFi connectivity to your Pocket PC.

Dan East
Thanks Dan, I'm sure that is a very good idea. The problem is I'm an absolute newbie and I have no idea how to use the debug build and how to debug with it. I dont even know why you need a debug build in the first place if you can MessageBox all your variables at certain places.

So I'm going to have to learn more about debugging before I dive in to your suggestion. Thanks =)
That's funny, I'm from that school of thought as well... When I'm doing my day job it's almost all server-based Java work, and my debugging consists of tons of println's throughout the code, debuggers be damned!

That being said, I've used the debugger in eVC++ more than any other.

My suggestion: if you can somewhat narrow down where the problem is, what I find effective is to set a break point on a line right before where you think the trouble is, then hit F5 to start and when you hit the breakpoint, just step through the code line-hy-line (or do a run to cursor to get through large loops). I find that I rarely use watches and all the other stuff available, just breakpoints and stepthroughs.
I remember having simillar issues a year or so ago... from what I "deduced" the OS (device) did not like opening read/writing, then closing a few 100 times a second... it sparatically just crashed or locked the device up.

I have noticed even recently if the device is "busy", it seems to take a while to preocess the file? (close it etc), I had my game opening files that it claimed didn't exist yet, but if you waited, it was fine!

so basically I can't be 100% sure whats causing it, but I guess the os is still stuffing about closing the file / updating the directory structure, and hasen't finished before you try and open it again....

ot I could be just wafflin.... and dont know what I'm talking about....

I'd guess the latter.....

-B