PocketMatrix forums

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

CreateSurface(BYTE *buffer, DWORD size) function fails ??

Has anyone tried using the CreateSurface(BYTE *buffer, DWORD size) method to load a bitmap from a bitmap image file in memory ?? When I try, the call crashes without yielding an error code.

for example:

CGapiSurface *s = new CGapiSurface();
s->CreateSurface(buffer, size);

where buffer is a BYTE[] of length 'size' that was pre-filled with a .bmp file that was loaded into buffer[]. I simply used CFile::Read() to load a 'test.bmp' into memory.

Am I doing something wrong or does this method require a different image of a .bmp ?

If I put the same .bmp file in the resource fork and use the other CreateSurface() call and it works fine.

Any help is greatly appreciated.

Thanks.
Jeff
Hi Jeff,

I will look into this on Saturday. A quick glance through the source code indicates that the only thing that could cause GapiDraw to crash, is that the CreateSurface function currently does not correctly validate the pBitmapFile parameter.

Could you please verify that you are not passing a NULL memory pointer to CreateSurface()? I will add verification of the pBitmapFile parameter in GapiDraw 1.1. If you are not, my guess is that it could be a memory alignment issue. No matter what I will look into it seriously on Saturday.

Best regards,
Johan
Johan,
I looked into it and it's definately not a NULL pointer being passed. To test it out, I read in a bitmap file from disk into a buffer using CFile::Read(). For testing, I then wrote out that buffer's contents to a file ("test.bmp") using CFile::Write(). If I call sur1->CreateSurface("test.bmp") it works fine. If I call sur2->CreateSurface(buffer, size) it crashes out.

The whole reason I'm doing this is because I want to be able to load images stored as jpegs into GapiDraw surfaces.. the only way I know is to load the jpeg onto a CBitmap object and then ultimately call CreateSurface() with the bits stored in the CBitmap object. I figured I'd try it with a raw .bmp first and that's where I found this issue.

Thanks.
Jeff
Ok! :)

I'll correct it this weekend.

/Johan