Noob needing some help please

Started by
4 comments, last by JasVic 20 years, 5 months ago
I always seem to get the funky errors... I''m trying to load an image using the GDI then create a compatable D3D surface to load the image onto, but when I try to create the surface I get: HEAP[DXBitmap.exe]: Invalid allocation size - a3d70a60 (exceeded 7ffdefff) **Could not create surface for bitmap (**this line is an self defined error message) I think the problem is in LoadImage().. LoadImage() doesn''t seem to be working for me.. here''s the code.. HRESULT r = 0; HANDLE hImage; BITMAP Bitmap; //create the the bitmap using the GDI to obtain bitmap info char Path[] = "ZEN PIC.BMP"; // Load the image from disk into memory hImage = LoadImage( NULL, Path, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); if(hImage = NULL) { //wrong path or file doesn''t exist probably SetError("Unable to load bitmap"); return E_FAIL; } //get info on object GetObject(hImage, sizeof(BITMAP), &Bitmap); //unload the object once info obtained DeleteObject(hImage); //code to output width and height in pixels to debug win char error[50]; itoa(Bitmap.bmHeight,error,10); SetError(error); itoa(Bitmap.bmWidth, error, 10); SetError(error); When I output the Bitmap height and width to the debug window I get: -858993460 -858993460 Which seems really wrong, and I assume is why the surface it tries to create is too big. The program works fine when I take the Bitmap code out, and Loadimage works fine in my other programs.. Any info or suggestions would be greatly appreciated! Thanks! Sean
Advertisement
I''m not sure about this, as I''m a pretty novice coder myself...

But it looks like you are creating hImage without setting it to NULL. So it has some random value.

You then try to load a bitmap to it, and check to see if it''s NULL. The bitmap may or may not have loaded correctly, but hImage was never NULL, so the code to check to see if it loaded correctly will always return that it did.

set hImage to NULL when you create it, and see if that helps. I bet you''ll see after you do that, that your Bitmap isn''t loading correctly.

Good luck!

~~~~~~~~~~~
Chris Vogel
~~~~~~~~~~~
WyrmSlayer RPG - In Early Development
That helped, but it wasn''t HBITMAP.. Even if I set it to NULL and zero the memory I don''t get the error after creation, but what you said caused me to set the BITMAP structure to NULL and zero it first too, now when I output the Height and Width I get 0''s so it seems the problem has to do with:

GetObject(hBitmap, sizeof(BITMAP), &Bitmap);

It seems the Bitmap structure isn''t getting the info, of course I still have no idea why but it''s a start! heh thanks!
OMG I''m laughing my ass off.. what a true noob mistake.. here it is..

if(hImage = NULL) {
//wrong path or file doesn''t exist probably
SetError("Unable to load bitmap");
return E_FAIL;
}


Duh!
asjkfhqejf

Thanks for the help!
heh, I missed that too.

if (hImage = NULL)...if (hImage == NULL)


Makes a big difference =)

[edited by - Radagar on November 13, 2003 2:58:30 PM]
WyrmSlayer RPG - In Early Development
That''s why I write comparisons like this

if(NULL == hImage)

that way if you write

if(NULL = hImage)

You''ll get a compile error instead of a runtime error.
---CyberbrineDreamsSuspected implementation of the Windows idle loop: void idle_loop() { *((char*)rand()) = 0; }

This topic is closed to new replies.

Advertisement