# Big problem

This topic is 5055 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

##### Share on other sites
Probably a GDI problem and not a DirectX problem, but a couple of things you can check.

Are you sure you are calling GetObject on DIB and not a DDB?
If you use a DDB the bmBits can (will?) be NULL.

Are you calling DeleteObject on the bitmap bandles when you have finished with them?

HTH,
Cambo_frog

##### Share on other sites
Yes! I think is a GDI problem.
This is the code i'm using from ddutil

HRESULT CDisplay::CreateSurfaceFromBitmap( CSurface** ppSurface,                                           TCHAR* strBMP,                                           DWORD dwDesiredWidth,                                            DWORD dwDesiredHeight, char tip ){//	tkz =1;    HRESULT        hr;    HBITMAP        hBMP = NULL;    BITMAP         bmp;    DDSURFACEDESC2 ddsd;    if( m_pDD == NULL || strBMP == NULL || ppSurface == NULL )         return E_INVALIDARG;    *ppSurface = NULL;    if( hBMP == NULL )    {        hBMP = (HBITMAP) LoadImage( NULL, strBMP,                                     IMAGE_BITMAP, dwDesiredWidth, dwDesiredHeight,                                     LR_LOADFROMFILE | LR_CREATEDIBSECTION );        if( hBMP == NULL )		{			DWORD dw = GetLastError();			if (dw!=2) 			dw=0;  //skip file does not exist            return E_FAIL;		}    }    // Get size of the bitmap    GetObject( hBMP, sizeof(bmp), &bmp );if (bmp.bmBits == NULL)			{				DWORD dw = GetLastError();				dw=0; // this is where i get code 8			}    // Create a DirectDrawSurface for this bitmap    ZeroMemory( &ddsd, sizeof(ddsd) );    ddsd.dwSize         = sizeof(ddsd);    ddsd.dwFlags        = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;    ddsd.dwWidth        = bmp.bmWidth;    ddsd.dwHeight       = bmp.bmHeight;    (*ppSurface) = new CSurface();    if( FAILED( hr = (*ppSurface)->Create( m_pDD, &ddsd ) ) )    {        delete (*ppSurface);        return hr;    }    // Draw the bitmap on this surface    if( FAILED( hr = (*ppSurface)->DrawBitmap( hBMP, 0, 0, 0, 0 ) ) )    {        DeleteObject( hBMP );        return hr;    }DeleteObject( hBMP );    return S_OK;}

I also have teh code where i'm puting the bmp images in one big file but that code is biger.. the main problem is that this code dosn't work rightly and i don't want to use MFC in my game ...

I have also tried to load the bmp witn one code of my one(not realy my code .. i just make the conection betwen this code and that code) but is not working too good either ..

I dont realy char what is the error i just need a posibility to take the images from bmp files and put them in one big file, and after that a function what it will take the images from the file and put them on the surface (using GDI or not). I don't want to save the image from the surface because of the diferent pixel formats.

Edited by Coder: Use source tags, my friend. Check GDNet Forums FAQ

[Edited by - Coder on August 17, 2004 3:19:55 PM]

##### Share on other sites
Quote:
 // Get size of the bitmapGetObject( hBMP, sizeof(bmp), &bmp );if (bmp.bmBits == NULL){DWORD dw = GetLastError();dw=0; // this is where i get code 8}

I don't understand how bmBits could be NULL here either!

LoadImage is creating a Dib Section here so bmBits should be valid.

hBMP is actually a handle to a Dib Section so you could try GetObject with a DIBSECTION structure instead of a BITMAP structure.
DIBSECTION ds;GetObject(hBMP, sizeof(ds), &ds);if (ds.dsBm.bmBits == NULL){  ...}

But seeing as bmBits is sometimes valid and dsBm (BITMAP strucure)is the first member of DIBSECTION structure, it probably wouldn't help but I can't think of anything else to suggest at the moment.

Cambo_frog

##### Share on other sites
Im getting the same result: a null DIB;
the size: width an weith are set to 13/13
the field bmWidthbytes is set to 2
bmplanes and bmbitpixel are set to 0
the pointer to the bmBits is stil NULL

When i'm drawing that is droawing an image like teh one what is on the the place of maximize window when is selected (the two rectangles) (from the menu of IE, or any window ..)

When i call GetLastError is returning 183 ... what is Cannot create a file when that file already exists. ERROR_ALREADY_EXISTS
I'm not even get the 8 code .. probabily if i will restart the computer i will get the 8 code.
If hBMP is actually a handle to a Dib probabily there is a problem with the handle, and the handle is returned by LoadImage

At the begining only GetObject return bad code but after few appeals of the function the LoadImage is returning a NULL handle and error 183.

What sense makes that error?? Is an other posibility to get an gandle to the bmp?
There are many games. Why i haven't found some information about this error? How are they reading the images? After i get the image i put it on the surface and i'm freeing the handle. I read that the number of handles is limited ... but anyway i'm freeing them ..

I have also tried to read the bitmap diferently .. but i don' know how to put code in the smal window. If you chan tell me i wiil post the class and how i'm tring to use'it ..

Thx very much 4 trying to help me.

##### Share on other sites
I have izolated the problem to be sure is not an other problem (like writing in pointers what were not allocate ..who knows)
I have take the windowedmode sample and i just add in it after the loading the directx.bmp the folowing code

// Create a surface, and draw a bitmap resource on it.
if( FAILED( hr = g_pDisplay->CreateSurfaceFromBitmap( &g_pLogoSurface, MAKEINTRESOURCE( IDB_DIRECTX ),
SPRITE_DIAMETER, SPRITE_DIAMETER ) ) )
return hr;

//MY CODE
CSurface *a[10000];
for (int i=0;i<10000;i++)
if( FAILED( hr = g_pDisplay->CreateSurfaceFromBitmap( &a, "directx.bmp", 0, 0 ) ) )
//return hr;

... some times i get bmp.bmBits = NULL (after is loading the image 291 times ... )
ant code 1814 The specified resource name cannot be found in the image file. ERROR_RESOURCE_NAME_NOT_FOUND ...

when i try loading a big image (800/600/24b) i don't get any error .. and i load images until my swap run out

When i try to load this image 96/55/24b the program give me Unhandled exception at 0x02a91368 in windowedmode.exe: 0xC0000005: Access violation writing location 0x00000000.
and is breaking me in asm ... i beleve in the code where is loading the the bits of the image

Now i'm realy thinking that there is a problem with the LoadImage and GetObject
There is any other posibility to load the bmp on the surfaces?? with out this pseudo random errors??

How is somewone supose to develop games when not iven the basics, loading an image is not working good.
(This is not a hardware problem .. i was having this problem on my old hardware and i stil have'it on my new hardware, of curse this is an operating sistem problem because that are functions from the OS ...)
My email is solriasi@yahoo.com and i stay on mesenger .. if somewone want i can send them the test program to see how it's working ..

• 17
• 11
• 13
• 9
• 49
• ### Forum Statistics

• Total Topics
631393
• Total Posts
2999761
×