Default Sdk Not Respecting #pragma Pack(x)


Daid

Member
Joined
Jun 13, 2006
Messages
267
Location
Netherlands
Website
Visit site
Traced back the not loading of clonk to the failure of loading the bmp images. What traced back to this function:

Code:
BOOL CBitmap256Info::Valid()
	{
  if (Head.bfType != *((WORD*)"BM") ) return FALSE;
  if ((Info.biBitCount!=8) || (Info.biCompression!=0)) return FALSE;
	return TRUE;
	}
In this class:
Code:
#pragma pack(1)

class CBitmap256Info
	{
	public:
		CBitmap256Info();
	public:
		BITMAPFILEHEADER Head;
		BITMAPINFOHEADER Info;
		RGBQUAD Colors[256];
	public:
		void Default();
		void Set(int iWdt, int iHgt, BYTE *bypPalette);
		BOOL Valid();
		int FileBitsOffset();
	};

#pragma pack()

If I add this debug line:
Code:
printf("%i %i %i %i\n", (int)this - (int)&Head, (int)this - (int)&Info, sizeof(Head), sizeof(Info));
in the IsValid function, then I get this:
Window/Linux, x86: 0 -14 14 40
Linux, GP2x: 0 -16 16 40

And thus, it doesn't pack the Head structure correctly.

Traced back to this code:
Code:
#pragma pack(2)
typedef struct tagBITMAPFILEHEADER {
	WORD	bfType;
	DWORD	bfSize;
	WORD	bfReserved1;
	WORD	bfReserved2;
	DWORD	bfOffBits;
} BITMAPFILEHEADER,*LPBITMAPFILEHEADER,*PBITMAPFILEHEADER;
#pragma pack()

Any ideas?
 
Solved it, a slightly diffrent way.

Changed the loading code:
Code:
	if (!hGroup.Read(&BitmapInfo,sizeof(BitmapInfo))) return NULL;
To:
Code:
	if (!hGroup.Read(&BitmapInfo.Head,14)) return NULL;
	if (!hGroup.Read(&BitmapInfo.Info,40)) return NULL;
	if (!hGroup.Read(&BitmapInfo.Colors,1024)) return NULL;
Clonk Planet runs now :D Still segfails, but only on exit.

Just need to build some frontend now.
 
You could try __attribute__((__packed__)) instead, works with oopo's toolchain

E.g.

Code:
struct RGB {
		unsigned char red, green, blue;
} __attribute__((__packed__));
 
Back
Top