Skip to main content
gamedev.net
🔒 Locked

Memory Errors

Started by Zdman 5 replies 450+ views
Original Post
Zdman
Zdman
I keep getting Unhandled exception in Pong.exe(DDRAW.DLL): 0xC0000005: Access Violation. I assume this is a memory error and has something to do with the way i load an image onto the surface. This happens when I try to BltFast onto the back buffer. this is what I call my_dx.CreateBitmapSurface(sample, "test.bmp" ,128, 128); this is the required functions void cDX::CreateSurface(LPDIRECTDRAWSURFACE7 *lpSource, int xs, int ys) { DDSURFACEDESC2 ddsd2; ZeroMemory(&ddsd2, sizeof(ddsd2)); ddsd2.dwSize = sizeof(ddsd2); ddsd2.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd2.dwWidth = xs; ddsd2.dwHeight = ys; lpDD->CreateSurface(&ddsd2, lpSource, NULL); } void cDX::CreateBitmapSurface(LPDIRECTDRAWSURFACE7 lpSurface, char *fname, int xs, int ys) { HBITMAP hBitmap; CreateSurface(&lpSurface, xs, ys); hBitmap = (HBITMAP)LoadImage(NULL, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); DrawHBitmap(lpSurface, hBitmap, 0, 0, xs, ys); DeleteObject(hBitmap); } void cDX::DrawHBitmap(LPDIRECTDRAWSURFACE7 lpSurface, HBITMAP hBitmap, int x, int y, int width, int height) { HDC hdcImage; HDC hdc; BITMAP bm; if (lpSurface == NULL || hBitmap == NULL) return; lpSurface->Restore(); hdcImage = CreateCompatibleDC(NULL); SelectObject(hdcImage, hBitmap); GetObject(hBitmap, sizeof(bm), &bm); width = width == 0 ? bm.bmWidth : width; height = height == 0 ? bm.bmHeight : height; lpSurface->GetDC(&hdc); BitBlt(hdc, x, y, width, height, hdcImage, 0, 0, SRCCOPY); lpSurface->ReleaseDC(hdc); DeleteDC(hdcImage); } I've tried to learn from several different tutorials including several from this site and I keep getting the same error. Can someone please shed some light so I can get somewhere. :)
mike25025
mike25025
change these lines

void cDX::CreateBitmapSurface(LPDIRECTDRAWSURFACE7 lpSurface, char *fname, int xs, int ys){HBITMAP hBitmap;CreateSurface(&lpSurface, xs, ys);


to

void cDX::CreateBitmapSurface(LPDIRECTDRAWSURFACE7& lpSurface, char *fname, int xs, int ys){HBITMAP hBitmap;CreateSurface(lpSurface, xs, ys);


that should work
Zdman
Zdman
Now It shows something but now there's a bunch of mess all over the screen.
mike25025
mike25025
are you clearing the buffers?
Zdman
Zdman
DRRR. I fixed it and now it shows nothing... maybe it's the path of the bitmap or something. And yes i'm clearing then blitting then flipping.
mike25025
mike25025
try using IDirectDrawSurface7::Blt insted of BitBlt
Zdman
Zdman
THX ALOT... Now how do I close this thread and award you the credit?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.