• Advertisement

Archived

This topic is now archived and is closed to further replies.

BltFast crashing program

This topic is 5805 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

Well I finally pinpointed my problem using a log. Here''s my code (taken from the Ddraw demo): LogData("C:/Windows/Desktop/Log.dat","Blitting..."); ddrval = lpDDSBack->BltFast( 10, 10, lpDDSGameBackground, &rcRect,DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT); LogData("C:/Windows/Desktop/Log.dat","Testing..."); but on my log all i see is: "Blitting..." and that''s it! And yes I know my log works. I load the bitmap using it''s DDLoadBitmap function, and the loggs say it goes through succesfully, and I set the color key (16 bit mode, not palatized) and that goes through fine. But I have no clue why it just crashes the program on BltFast, anyone have any suggestions? I use: LPDIRECTDRAWSURFACE lpDDSGameBackground; to hold the background image. And yes the rect is the same size as the image... Any help would be greatly appreciated!

Share this post


Link to post
Share on other sites
Advertisement
Do you have DX debug installed? If not then perhaps the debugging information it provides would help.

Share this post


Link to post
Share on other sites
Well i discovered that the directX libs i had are from directX 2... Since I have the DX8 toolkit and i now have a patch, i''ll spend all day today trying that, and if that doesn''t get to work, i''ll go back to openGL.

Share this post


Link to post
Share on other sites
You give up to easily...

It''s obviously not DirectX''s fault - it''s either your code or the drivers for your card, and i''m betting on it being your code...

If BltFast() had some huge bug that made it crash all the time, don''t you think others would have been complaining here for ages...

Why don''t you post us some of you initialisation code or whatever to show us what your doing...

Jx

Share this post


Link to post
Share on other sites
I don't give up easily, I've been trying to get this to work for 20 straight hours (and I do mean straight)... Ok i'll just randomly show you some of my code (I removed all my logging code since it's pretty lengthy) :


void StartupStuff()
{
DirectDrawInit(EditorWnd,640,480,16);
DDCOLORKEY ColorKey;
ColorKey.dwColorSpaceLowValue = RGB(255,255,255);
ColorKey.dwColorSpaceHighValue = RGB(255,255,255);
// Lets try this as GRASS..........
lpDDSGameBackground = DDLoadBitmap(lpDD,"Grass.bmp");
lpDDSGameBackground->SetColorKey( DDCKEY_SRCBLT, &ddck );
return;
}


IDirectDrawSurface * DDLoadBitmap(IDirectDraw *pdd, LPCSTR szBitmap)
{
HBITMAP hbm;
BITMAP bm;
IDirectDrawSurface *pdds;
hbm = (HBITMAP)LoadImage(NULL, szBitmap, IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);

if (hbm == NULL)
{
return NULL;
};

GetObject(hbm, sizeof(bm), &bm); // get size of bitmap

pdds = CreateOffScreenSurface(pdd, bm.bmWidth, bm.bmHeight);

DDCopyBitmap(pdds, hbm, bm.bmWidth, bm.bmHeight);
DeleteObject(hbm);
return pdds;
}



IDirectDrawSurface * CreateOffScreenSurface(IDirectDraw *pdd, int dx, int dy)
{
DDSURFACEDESC ddsd;
IDirectDrawSurface *pdds;
//
// 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 = dx;
ddsd.dwHeight = dy;

if (lpDD->CreateSurface(&ddsd, &pdds, NULL) != DD_OK)
{
return NULL;
} else {
return pdds;
}
}


HRESULT DDCopyBitmap(IDirectDrawSurface *pdds, HBITMAP hbm, int dx, int dy)
{
HDC hdcImage;
HDC hdc;
HRESULT hr;
HBITMAP hbmOld;

//
// select bitmap into a memoryDC so we can use it.
//
hdcImage = CreateCompatibleDC(NULL);
hbmOld = (HBITMAP)SelectObject(hdcImage, hbm);

if ((hr = pdds->GetDC(&hdc)) == DD_OK)
{
BitBlt(hdc, 0, 0, dx, dy, hdcImage, 0, 0, SRCCOPY);
pdds->ReleaseDC(hdc);
}

SelectObject(hdcImage, hbmOld);
DeleteDC(hdcImage);

return hr;
}




void UpdateFrame()
{
RECT rcRect;
HRESULT ddrval;
int xpos, ypos;


SetRect(&rcRect, 0, 0, 32, 32);
ddrval = lpDDSBack->BltFast( 10, 10, lpDDSGameBackground, &rcRect,DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
if( ddrval != DD_OK )
{
return;
}
ddrval = lpDDSPrimary->Flip( NULL, DDFLIP_WAIT );
return;
}


And of course the thingy in winmain:
while(!done)
{
if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if( !GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage(&msg); // Translate The Message
DispatchMessage(&msg); // Dispatch The Message
}
}
else
{
UpdateFrame();
}
}



Well that's 80% of my C++ code (I got code waiting to port if i ever get this to work ^_^). Grass.bmp is in the same dir as the game, and it's a 16-bit BMP file. Need any more info? Hopefully this helps ^_^

Edited by - Dreq on February 26, 2002 7:38:20 AM

Edited by - Dreq on February 26, 2002 7:40:01 AM

Share this post


Link to post
Share on other sites
First of all why don''t you use DirectX7 interfaces???

The problem could be in your rect. If your rect is not specified correctly it would probably cuase an access violation and that''s why your program could crash there.
Also if you don''t want a colorkey set for the blit, just don''t specify it.
BltFast(........, DDBLTFAST_WAIT) - no color key
BltFast(........, DDBLTFAST_WAIT | DDBLTFAST_SRCCOLORKEY) - using the color key set

I am not sure if DDBLTFAST_NOCOLORKEY is correctly supported (though it should be). And try using just DDSetColorKey as you use DDLoadBitmap for setting the colorkey.
)


Rusenec

Share this post


Link to post
Share on other sites
It seems you are having problems with randomn crashing. make sure all your pointers are valid and you ZeroMemory any structures you use etc...

Also try implementing a windowed mode, it will alteast give and error and let you dubug instead of kickinh you back to the desktop

Share this post


Link to post
Share on other sites
I could be wrong, but I''ve never used the * operator with any direct draw variables... maybe thats a problem.

Share this post


Link to post
Share on other sites

  • Advertisement