Sprites - what am I doing wrong (loading it)

Started by
0 comments, last by gerbenvanderlubbe 21 years, 11 months ago
This is my code: struct SDATA { public: LPDIRECTDRAWSURFACE7 Surface; DDSURFACEDESC2 SurfaceDesc; }; struct SPRITE { private: SDATA Data; void CreateSurface(DDSURFACEDESC2* ddsd) { Data.Surface = (struct IDirectDrawSurface7 *)new LPDIRECTDRAWSURFACE7(); DD->CreateSurface(ddsd, &Data.Surface, NULL); Data.SurfaceDesc.dwSize = sizeof(Data.Surface); Data.Surface->GetSurfaceDesc(&Data.SurfaceDesc); } public: void LoadSpriteFromFile(char* filename, int width, int height) { HBITMAP Bitmap; BITMAP bmp; DDSURFACEDESC2 ddsd; Bitmap = (HBITMAP)LoadImage(GetModuleHandle(NULL), filename, IMAGE_BITMAP, width, height, LR_CREATEDIBSECTION); if( Bitmap == NULL ) { Bitmap = (HBITMAP) LoadImage( NULL, filename, IMAGE_BITMAP, width, height, LR_LOADFROMFILE | LR_CREATEDIBSECTION ); } GetObject(Bitmap, sizeof(bmp), &bmp); 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; CreateSurface(&ddsd); } void Render() { // Data.Surface->BltFast(0, 0, Data.Surface, NULL, NULL); //Data.Surface->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, NULL); } }; When I run the program, an error occurs. When I exit the game (Using Control+Alt+Delete), The line "Data.Surface->GetSurfaceDesc(&Data.SurfaceDesc);" is highlighted, and a messagebox shows the text "ACCES VIOLATION". What am I doing wrong? Please Help Gerben
Advertisement
you dont normally exit ANYTHING using ctrl alt delete unless the app is broken. your app should be able to terminate normally without using crtl-alt-del.

you are creating surfaces wrong. CreateSurface() creates the surface for you, you dont use new. look over the sdk samples.

This topic is closed to new replies.

Advertisement