PocketMatrix forums

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

Compiling PF Game for Desktop...

Well... I did a ton of searching and I still can't figure it out. I can get my game to compile for desktop (using MS VC 6.0) and I can even run it. However, when ever it hits a line that does a Blit or a SetColorMask it crashes saying:

The instruction at "0x0040014a" referenced memory at "0x00000010". The memory could not be "written".

Although it gets past the LoadImage just fine. I'm sure it's using the right libs for PocketFrog and all.

Are there any other tricks to compiling to the desktop?
GeoffSulcer · 03 Jun 2004, 20:17 UTC
Just a guess...

PF uses imgdcmp.dll (sp?) to load images. This dll is different on a desktop then on the Pocket PC.

On the desktop it only loads .bmp and .dib IIRC, but on Pocket PC it can also load .jpg and .png

Anyway, I had a similar problem and the result was I had to have different image formats for the desktop and the Pocket PC, so I ended up with 2 different resource.h files and used a #ifdef to include the right one depending on the target platform.

HTH

Geoff
"PF uses imgdcmp.dll (sp?) to load images. This dll is different on a desktop then on the Pocket PC. "
Not entirely correct. The desktop doesn't even use imgdcmp.dll.

"On the desktop it only loads .bmp and .dib IIRC, but on Pocket PC it can also load .jpg and .png"
Again not entirely correct.. this is from the image.h in pocketfrog root dir:

"The PocketPC and the desktop PC versions of this function are implemented differently. On PocketPC, we use the "imgdecmp.dll" decompression library to load different file formats without having to deal with legal issues such as GIF decompression.

On the desktop, we use the OleLoadPicture() function to load image files.
This give us access to a similar set of image formats.

The following formats are supported:
PocketPC: .BMP, .GIF, .JPG, .PNG and .XBM
Desktop: .BMP, .GIF, .JPG, .WMF and .ICO"


So you see, using either BMP, GIF or JPG you can have the same code and resources running on the desktop as on your pda. PNG files are only supported on the PDA.

One thing to keep in mind if you work with external resources (i.e. files) is that the paths will be different for the PDA and the desktop so you have to do some #ifdef _WIN32_WCE #else #endif here. Also, WinCE uses widechar/unicode and desktops doesn't (hmm.. perhaps this has changed since XP.. havn't used PF on XP (yet)).

What could the error be then? Hard to say really without more info. It does sound like a MT race condition error (i.e. two threads are trying to write to the same area at the same time) but then PF 0.6.0 is not running multiple threads. What version of PF are you using?. If you are running multiple threads, then you must link to the MT libs on your desktop. There is no distinction between ST and MT (single/multi thread) libraries on WinCE so that's why you won't be able to produce the same errors on your PDA.

What you should do is try to compile and run one of the PF samples on your desktop since they should work on your desktop as well, and they all do the Blit. (I seem to recall they have a project file for VC6). If that works then look at how it links all the stuff together and do your stuff exactly like that.

Hope this info helps. If not there are several threads in this forum that handles the issues of getting your application running on the desktop. I seem to recall I helped Conan with this about a year ago.
Yeah I thought of the graphic formats already. And I am using PNG on the PDA but I'm using BMP on the desktop so it should work. This is what I'm doing in code.

Code:

#ifdef _WIN32_WCE
MessageBox("A","DEBUG",MB_OK);
gMenu = LoadImage(gScreen, IDR_MENU, TEXT("IMAGE"));
#else
MessageBox("B","DEBUG",MB_OK);
gMenu = LoadImage(gScreen, IDB_MENU);
#endif
MessageBox("C","DEBUG",MB_OK);
gMenu->SetColorMask(Color(255, 0, 255));
MessageBox("D","DEBUG",MB_OK);


It's crashing after the message box "C". I'm getting "B", "C", then crash. I'm using PF 7.0 with MSVC 6.0. I'm not doing anything out of the ordinary.

I will try your suggestion and see if I can get an example to work. I'm sure I'm missing something simple. Problem is that I've been looking at it for too long :-). Thanks for the help.
The samples worked. So I started comparing them to mine and the only difference was that I have two sets of graphics. I have the PNGs for the PDA and the BMPs for the desktop. I simply removed the PNGs and everything worked. I need to move to one format that works on both the PDA and desktop... but I really do like the PNG format. Oh well, I guess I'll move to JPGs :-).

Thanks again for pointing me in the right direction. I figured it had to do with my graphics not loading, but I thought I had worked around it by using two sets in the same resource file. I could always use two resource files but I rather move to JPGs for both platforms.
Ok.. glad I could help.

Still want to make a few remarks though:

1. If on a PPC you will load from a resource with id=IDR_MENU from the resource group=IMAGE. And on the desktop you're trying to load a resource with id=IDB_MENU from the group=image. Remember that if you do not specify the gruop you will get the default which is:
Surface* LoadImage( DisplayDevice* display, unsigned resourceID, const TCHAR* resclass = _T("image"), HINSTANCE hModule = 0 );

Not sure if this has anything to do with it (I always use external resources, i.e. files) but it's worth a shot. Just look at the resource file (named something.rc) and see what group and id your BMP files actually got. My guess it that JPG's end up in group IMAGE and BMP end up in group BITMAP. This is the case for Blit.rc, the resource for the Blit sample.

2. Using PNG is not very clever. It might seem like a good idea since the PNG format is far superior to the other alternatives. But if you look closer to what actually happens when the PNG gets decoded you notice that it will be rendered as a normal bitmap. I.e. the alpha channel is simply discarded and hence you might as well use JPG format since then you could atleast use the same resources for both the PDA and the desktop.

3. I found that for using transparent images the best way would be to have it as a JPG resource using a designated transparecy color (I used black). Then simply call SetColorMask(0) to enable it (or the equivalent color). I never got the transparent GIF:s to work and besides: with JPG you get better quality.

4. You should always compare your surface to NULL (or 0) before dereferencing it calling a function. What I mean is that if you do something like:
Code:
gMenu = LoadImage(gScreen, IDB_MENU);
if (gMenu)
gMenu->SetColorMask(0);
else
MessageBox("Unable to load image","DEBUG",MB_OK);

You will be able to take actions and exit gracefully (or possibly resolve the situation loading another resource instead). This naturally goes for all objects you create. Always validate them before you use them since otherwise you will be thrown out of your program with a segment fault.
GeoffSulcer · 04 Jun 2004, 14:02 UTC
adde wrote:"PF uses imgdcmp.dll (sp?) to load images. This dll is different on a desktop then on the Pocket PC. "
Not entirely correct. The desktop doesn't even use imgdcmp.dll.

"On the desktop it only loads .bmp and .dib IIRC, but on Pocket PC it can also load .jpg and .png"
Again not entirely correct.. this is from the image.h in pocketfrog root dir:


Damn, the old memory just isn't what it used to be. Sorry for the misinformation.

Geoff
Well, as I think FZammetti wrote a few topics ago, we all make mistakes. Or as I tend to frase it "Even the sun has it's dark spots"
I tend to make that point often, being as I tend to make mistakes so often :)