PocketMatrix forums

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

How to tell when running in emulator?

Is there an easy programmatic way to tell when my application is running in the PocketPC emulator?

I have a section of code that is GPF'ing within the emulator but not on any real device, and rather than slow down to spend time trying to figure it out, I'd rather just turn off some things when running in the emulator.

I'm sure there's any easy way, but I don't see it at the moment. Thanks all!
Code:

#if defined(_WIN32_WCE) && defined(__x86__)
// Running on emulator...
#endif
I knew it had to be simple. Thanks Thierry!
I'm interested to know what sort of problems you might be having when trying to run your app under the emulator. Knowing this might keep me from being bit by the same thing in the future. I realize you mentioned that you don't have the time to dig into this, but if you do can you let us know what you find out? Thanks.
It has to do with the PocketFrog extensions that gersen has done...

I'm playing a MOD file, and it GPF's in the emulator (ironically, it looks like the player thread or something is dieing because the actual game keeps going, until I click through the GPF message anyway).

I know it's the MOD stuff because as soon as I comment out the line to start playing, no problems occur. Hasn't hiccuped even once on a real device, hence my attitude that it's not worth the time to figure out.

I kind of suspect it's a timing thing, might be calling something I shouldn't be at a time I am (how's that for nebulous thinking!!)...

I know the MOD file is fine (it plays just fine if I use it in the sample app that comes with the library), so it's probahly something silly (isn't it always?).
There is a routine in PocketGL's Matrix.cpp that will not behave properly for an x86 build if optimization is enabled. It casts shorts to ints before performing various operations.

I think I can get by posting a line of source:
Code:

p[INDEX(0,0)] = ((((int)m[INDEX(0,0)] * M2->m[INDEX(0,0)] + (int)m[INDEX(0,1)] * M2->m[INDEX(1,0)]) + (int)m[INDEX(0,2)] * M2->m[INDEX(2,0)] ) >> COS_SIN_SHIFT );


The routine only contains several more lines almost exactly like that one. It doesn't throw an exception for the PC build, but it certainly does not produce the expected results if optimization is enabled. So I disable optimization just for that routine (#pragma optimize ("g", off)) for x86 builds. As those builds are just for testing, I've not bothered to hunt down the exact cause. Disabling the optimizer for x86 is one of the least of my concerns, and is a simple fix for this problem. :)

Dan East
Sorta off topic here, but I was wondering if anyone else has problems with the emulator not wanting to run code that runs perfectly on the actual device. I even have one instance of the almost exact same code in two separate projects: one runs fine the other has a fatal exception and shuts down my prgram. The part that locks up the second one is identical to the first one up until that point. It bails on createwindow. I'm going to try turning off the optimization to see if that works, but are there any other suggestions?
No other suggestions, but your not the only one that has trouble with the emulator.

I've personally had pretty good luck with the emulator, this thread and maybe one or two other relatively minor instances are the only times I've had trouble.

However, it seems a great many people aren't happy with the emulator in general, so there should at least be a good bunch of reference for you to dig up on the net to help.
I have to say that in my experience if the x86 emulator crashes in Debug mode so far it has always pointed to a bug in my code, not the emulator code that is at fault.


For example one time I was destroying a window in one thread as it was being operated on in another thread directly (i.e. it was actually accessing memory which was being deallocated mid-access). This as I'm sure you can see is a bug in my code not the emulator, since I should have shut down the thread, waited till the thread had actually terminated and them and only then destroyed the window.

However it had previously runs for weeks on many iPAQ and Toshibas without ever crashing once. The timing and maybe the lack of the memory being overridden meant it never actually crashed. However I'm sure you can see given enough future versions of Windows CE, it probably would have eventually :(