Sign in to follow this  

Big problem

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have this problem, and i'm trying to solve it from about one year ago... What i'm trying to do is load some bmp's on surfaces, using the function from ddutil. The problem is with the loading function. Load image is not returning any error but sometimes (random) some images just dosn't load in the game. After the GetObject( hBMP, sizeof(bmp), &bmp ); all the filds from bmp are ok except (sometimes) bmp.bmBits what is null; when i call GetLastError it return to me the code 183 Cannot create a file when that file already exists. ERROR_ALREADY_EXISTS ald if i'm skiping that image and i'm just trying to load other images the LoadImage function is returning a null handle and with GetLastError i get code 8 what is Not enough storage is available to process this command. ERROR_NOT_ENOUGH_MEMORY I just dont get'it! Why the pointer to the bmp is null sometimes.. Chan somewone help me? Does anybody know what memory need the LoadImage function? What i'm realy trying to do is to load the images and save them all in 2 files, in one file the description and in the other file the pointers to dib .. but i can't because of this loadin error what i recive even if i'm just trying to load the images and use put them on surfaces .. The error is harder to observe if you just use the images witout verifing them .... Some times when the pointer from BITMAP does not load the image in their place appears a grey rectangle with an triangle in him with the size of the image. I realy hope you chan help me someway.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
// 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
}


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 this post


Link to post
Share on other sites
I tried your code.
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 this post


Link to post
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[i], "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 ..

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this