GP32 Crashing When I Change The Palette


TheMrCul

Still Fresh
Joined
Apr 18, 2003
Messages
52
Hello to all again, I've run into a really strange problem! :(
This code used to work, and after I added a few features into my program, it's started crashing when I change the palette (or more specifically, when I build a new palette)
So I started chopping all of the other code out and basically now all I have is creating a screen surface, then changing the palette. But it still crashes then!
This is the line it hates:
Code:
h_pal = GpPaletteCreate(256, (GP_PALETTEENTRY*)Clouds_Pal);
GeePee32 asks me to send an error message to micro$oft, and the Gp32 gives the following error:

Code:
Exception: Translation

Registers:        CP15 Registers:

...
(I can post the full error message here if it's important)

this is gpmain.c: (chopped down to almost nothing)

Code:
#include "gpdef.h"
#include "gpstdlib.h"
#include "gpgraphic.h"
#include "gpmain.h"
#include "gpstdio.h"
#include "gpfont.h"
#include "gpmm.h"

int  nflip, ExKey;

//----------------------------------------------------------------------------------//

//Pallete, memory and file loading crap
GP_HPALETTE h_pal, old_pal;
BGFONTINFO  tInfo;
F_HANDLE  fh;
ERR_CODE  err;
unsigned long n_size,n_read;
char *  	app_path;
BGFONTINFO  game_font;
extern const unsigned char fontresEng1[];
extern const unsigned char fontresKor1[];

//----------------------------------------------------------------------------------//

//Include all of the graphics here
#include "Graphics\Clouds.h"

//Include the custom fonts
#include "Fonts\fontdat.c"

//----------------------------------------------------------------------------------//

void GpMain(void *arg)
{
	int i, j;

	//Set up screen surface
  	nflip = 1;
	GpLcdSurfaceGet(&gpDraw[0], 0);
	GpLcdSurfaceGet(&gpDraw[1], 1);
	GpSurfaceSet(&gpDraw[0]);

	//Change Pallete
	h_pal = GpPaletteCreate(256, (GP_PALETTEENTRY*)Clouds_Pal);
	GpPaletteSelect(h_pal);
	GpPaletteRealize();
	GpPaletteDelete(h_pal);
	h_pal = NULL;
}

and gpmain.h:
Code:
#ifndef __gpmain_h__
#define __gpmain_h__

void GpMain(void * arg);

//Load the graphics buffer
GPDRAWSURFACE gpDraw[2];

#endif /*__gpmain_h__*/

incase it's important, clouds.h looks like any other graphics file converted with gp32convertor:

Code:
/////////////////////////////////////////
//
// Header file for GP32
//
// convertion of Clouds.bmp file :
// Width     = 60
// Heigth    = 60
// GP32 Mode = 8 Bits per Pixel
//
// with GP32Converter coded by Edorul :
//    http://www.ifrance.com/edorul/
//    edorul@free.fr
//
/////////////////////////////////////////

#define Clouds_width      60
#define Clouds_height     60

#define Clouds_palnb      256

#include "gpgraphic.h"

GP_PALETTEENTRY Clouds_Pal[256] = {
      0x1, 0xEF, 0xF1, 0xF3, 0x12D, 0x12F, 0x927, 0x929, 0x92B, 0x92D, 0x1085, 0x20C7, 0x2109, 0x2909, 0x294B, 0x314B, 
      0x318B, 0x39CD, 0x420D, 0x4211, 0x4A4F, 0x5293, 0x5295, 0x5909, 0x5AD3, 0x5AD5, 0x5AD7, 0x6109, 0x6315, 0x6317, 0x6319, 0x6359, 
      0x6907, 0x6B57, 0x6B59, 0x6B5B, 0x70C7, 0x7107, 0x7399, 0x739B, 0x739D, 0x78C7, 0x7A11, 0x7AD7, 0x7BDB, 0x7BDD, 0x80C5, 0x80C7, 
      0x8211, 0x841F, 0x8421, 0x88C5, 0x8C63, 0x8C9F, 0x90C5, 0x9461, 0x94A1, 0x94A5, 0x9883, 0x9885, 0x9CA3, 0x9CE1, 0x9CE3, 0x9CE7, 
      0xA083, 0xA2D7, 0xA525, 0xA527, 0xA529, 0xA565, 0xA883, 0xAD67, 0xAD69, 0xAD6B, 0xADA7, 0xB081, 0xB083, 0xB5A7, 0xB5A9, 0xB5AB, 
      0xB5AD, 0xB5E9, 0xB841, 0xBA11, 0xBCA5, 0xBDED, 0xBDEF, 0xC041, 0xC549, 0xC54B, 0xC589, 0xC58B, 0xC58D, 0xC58F, 0xC5EF, 0xC62D, 
      0xC62F, 0xC631, 0xC6BB, 0xC6BD, 0xC6FB, 0xC6FD, 0xC841, 0xCD89, 0xCD8B, 0xCD8D, 0xCD8F, 0xCDC9, 0xCDCB, 0xCDCF, 0xCDD1, 0xCDD3, 
      0xCDD5, 0xCE71, 0xCE73, 0xCEFB, 0xCEFD, 0xD39D, 0xD3DF, 0xD5C9, 0xD5CB, 0xD5CD, 0xD5CF, 0xD609, 0xD60B, 0xD60D, 0xD60F, 0xD611, 
      0xD613, 0xD615, 0xD617, 0xD619, 0xD61B, 0xD65B, 0xD65D, 0xD6B3, 0xD6B5, 0xD6FB, 0xD6FD, 0xD73B, 0xD73D, 0xDE09, 0xDE0B, 0xDE0D, 
      0xDE0F, 0xDE11, 0xDE4D, 0xDE4F, 0xDE51, 0xDE55, 0xDE57, 0xDE59, 0xDE5B, 0xDE5D, 0xDE5F, 0xDE9F, 0xDEA1, 0xDEA3, 0xDEF5, 0xDEF7, 
      0xDF3B, 0xDF3D, 0xDF7D, 0xE651, 0xE653, 0xE695, 0xE697, 0xE699, 0xE69B, 0xE69D, 0xE69F, 0xE6A3, 0xE6A5, 0xE6DB, 0xE6DD, 0xE6DF, 
      0xE6E5, 0xE6E7, 0xE6E9, 0xE6EB, 0xE72B, 0xE737, 0xE739, 0xE73D, 0xE77D, 0xEA95, 0xEEDD, 0xEEDF, 0xEEE1, 0xEEE3, 0xEEE5, 0xEF23, 
      0xEF25, 0xEF27, 0xEF29, 0xEF2B, 0xEF2D, 0xEF2F, 0xEF31, 0xEF71, 0xEF73, 0xEF7B, 0xF729, 0xF76B, 0xF76D, 0xF76F, 0xF771, 0xF773, 
      0xF775, 0xF7B3, 0xF7B5, 0xF7B7, 0xF7B9, 0xF7BD, 0xF801, 0xF83F, 0xF885, 0xF94B, 0xF98D, 0xFA11, 0xFB19, 0xFB5B, 0xFB9D, 0xFBDF, 
      0xFC21, 0xFC63, 0xFCA5, 0xFCE7, 0xFD27, 0xFD6B, 0xFDED, 0xFDEF, 0xFE31, 0xFE73, 0xFF39, 0xFF7B, 0xFFB5, 0xFFB7, 0xFFB9, 0xFFBB, 
      0xFFBD, 0xFFF9, 0xFFFB, 0xFFFD, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF
      
};


const unsigned char Clouds[3600] = {
      0x62, 0x62, 0x62, 0x62, 0x62, 0x62, 0x62, 0x62, 0x62, 0x62, 0x62, 0x62, 
...      
};

If someone could help me i would really appreciate it - many hours of work will go down the drain otherwise! I'm totally at a loss at what the problem could be!
 
Well, the full error message from MultiFW would help, but from the few lines you've given us, it seems like your either accessing invalid memory, or trying to access data on a non-aligned memory address.

I'd suggest you ensure your palette is aligned to a dword (4-byte) boundary first, before posting however.

EDIT: Hmm, if GeePee is crashing too, that would pretty much rule out unaligned memory accesses, and point towards accessing memory at strange locations in memory.
 
Thankyou very much for looking at it Squidge, here is full error message from the GP32: (GeePee32 asks to send a report to Micro$oft) I don't know how to read this error message! :unsure: So thanks :)

Exception: Translation
Registers: CP15 Registers:

r0: 00000001 0: 41129200 ID and Cache
r1: 0C01E148 1: C000107F Control
r2: 00000001 2: 0C79C000 TLB Address
r3: 00000000 3: 55555551 Domain
r4: 00000000 4: 00000000 MMU Reserved
r5: 00000000 5: 00000025 Fault Status
r6: 00000000 6: FFFFFFF4 Fault Address
r7: 00000000 9: 00000000 DCache Lock
r8: 00000000 9: 00000000 ICache Lock
r9: 00000000 10: 00F00000 TLB DLockdwn
r10: 00000000 10: 01F00000 TLB ILockdwn
r11: 00000000 13: 00000000 Process ID
r12: 0C01E0C0 15: 00000000 Impl Defined
r13: 0C037F58
r14: 0C0014E4 SPSR: 60000053
lr: 0C0014F0 CPSR: 600000D7

EDIT: I have tried reconverting the graphics file and using other graphics files aswell - it's just that when I added something totally unrelated to palette changing the whole thing blew up - now that I've taken everything else away it still doesn't work! My other older programs compile fine aswell :(
 
On some computers, you can have Geepee32 crash if you have your screen in 24 bits colors. Try 16 bits colors.

Well that's something that happens to me at work, and not on my notebook.
 
@woogal: I tried adding GpGraphicModeSet(8, NULL); but both (GP32 and PC) still crash.

@OanKali: But my GP32 crashes too, and GeePee32 worked before and still works now with my other programs

Thankyou for your input! Do you have any other ideas on what this could be? :unsure:

EDIT: I should add that if I take out chaging palettes (or even just that particular line where I create the new palette, (this one: h_pal = GpPaletteCreate(256, (GP_PALETTEENTRY*)Clouds_Pal);)) the whole program works just fine, just the colours are all skrewed up. So for some reason it hates creating a palette. But I need to change the colours!
 
Probably not going to help you much, but from the data you have posted, it looks like something is trying to dereference a null pointer. Considering your code, I'd say it was within the GPSDK, so something is probably not being initialised correctly, or some required function is not being called.

I don't actually have any code that uses GpPaletteCreate - so I can't help much more, I just modify the current palette, or use 16-bit mode.

Take a look into Rattboi's Wonderswan code, I know he still uses the GPSDK, and uses both 8-bit and 16-bit.
 
Tried replacing the SDK with the backup I have on cd, but to no avail
However I followed your advide Squidge and looked into the SDK to see if I could change the palette without creating a new one and switching to it.
With a bit of playing around it works!!! Thanks so much!! My hours were'nt wasted after all!
If this happens to anyone else please look here:
change:
Code:
	newPalette = GpPaletteCreate(256, (GP_PALETTEENTRY*)Clouds_Pal);
	GpPaletteSelect(newPalette);
	GpPaletteRealize();
	GpPaletteDelete(newPalette);
	newPalette = NULL;

to:
Code:
GpPaletteEntryChange(0, 256, (GP_PALETTEENTRY*)Clouds_Pal, 0);

Hooray!!
 
I've used the gamepark function palette only one time, and it's very complicate only for simple palette !!

I suggess you to use poke function :)

long *pal = (long *)0x14a00400;

void init_palette()
{
for (i=0;i<255;++i)
pal=your_palette;
}

JYCET
 
Back
Top