Skip to main content
gamedev.net
🔒 Locked

Problem with Direct/x basic surface creation

Started by Anneoldon Jul 31, 2002 at 8:25 PM 8 replies 250+ views
Original Post
Anneoldon
Anneoldon
Hi, I''ve a little problem. The function bellow is called in a while, but it work one time and the second time (in the while) the application shut down suddently, i''ve indicated you where is the bug... i don''t know why the creating function don''t work two times... the call is like: for (y = 0; y < j; y++) { for (x=0;x); i++; } } zone is a structure thank you very much. ps: The is a lot of message box, but it''s to know where the function stop LPDIRECTDRAWSURFACE7 bitmap_surface(LPCTSTR file_name) { HDC hdc; HBITMAP bit; LPDIRECTDRAWSURFACE7 surf; bit=(HBITMAP) LoadImage(NULL,file_name,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE); if (!bit) return NULL; BITMAP bitmap; GetObject( bit, sizeof(BITMAP), &bitmap); int surf_width = bitmap.bmWidth; int surf_height = bitmap.bmHeight; DDSURFACEDESC2 DDSD2Desc; memset (&DDSD2Desc, 0, sizeof (DDSURFACEDESC2)); DDSD2Desc.dwSize = sizeof (DDSURFACEDESC2); DDSD2Desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; DDSD2Desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; DDSD2Desc.dwHeight = surf_height; DDSD2Desc.dwWidth = surf_width; MessageBox(hWindow,"creation of the surface","prob",MB_OK); HResult = lpDD7Interface->CreateSurface (&DDSD2Desc, &surf, NULL); // here the application bug the second time MessageBox(hWindow,"surface created","prob",MB_OK); if (HResult!=DD_OK) { MessageBox(hWindow,"surface BMP","prob",MB_OK); Jeux_Quit(); return(0); }else{ MessageBox(hWindow,"surface BMP","prob",MB_OK); surf->GetDC(&hdc); HDC bit_dc = CreateCompatibleDC(hdc); SelectObject(bit_dc,bit); BitBlt(hdc, 0,0, surf_width, surf_height,bit_dc,0,0,SRCCOPY); surf->ReleaseDC(hdc); DeleteDC(bit_dc); DeleteObject(bit); return surf; } } thanks again
Anneoldon
Anneoldon
plz :,(
it''s been 3 days hat im on it
Carrot
Carrot
There''s nothing obviously wrong to me in the code.
Whats happening in between the calls to bitmap_surface?

Have you tried checking the return code (HResult) from CreateSurface to see what the error actually is?

Are you loading different bitmaps each time? Maybe the card you have doesn''t support the surface size you are attempting to create.

Sorry I can''t be much help...
Pipo DeClown
Pipo DeClown
what is i++ ?
can you show me your whilepart?
I think that the bug is there.

[edited by - pipo declown on August 1, 2002 8:27:57 AM]
Anneoldon
Anneoldon
the while parti is:

for (y = 0; y < j; y++)
{
for (x=0;x{


zone[y][x].nx = x;
zone[y][x].ny = y;
zone[y][x].hax = x*8;
zone[y][x].hay = y*6;
zone[y][x].lpsurface = bitmap_surface(img(i)); // the () replace the ][
i++;
}
}

img is a LPCSTR aray with "surf1.bmp" "surf2.bmp" etc...
the bmps are 800*600, and as the flag says, the surface is stocked in SYSTEMMEMORY

The is a HResult verif, but the apply stop without continue, it close... the bug is situated exactly at the CreateSurface method...

thanks for your posts

[edited by - Anneoldon on August 1, 2002 10:13:10 AM]
Anneoldon
Anneoldon
if that can help, here s the zone struct

struct Zone
{
int nx, ny; //nb of zone
int hax, hay; // abs Coord up left
LPDIRECTDRAWSURFACE7 lpsurface;
};

//typdef

typedef struct Zone ZONE;
typedef struct Zone FAR *LPZONE;
Pipo DeClown
Pipo DeClown
do it this way:

typedef struct ZONE{
//
///
////
/////
};

ZONE zone;

AND:
    
bitmap_surface(img[i]); instead of img(i)


can you show me the whole while part?
while(...){..}

[edited by - pipo declown on August 1, 2002 10:40:28 AM]
Anneoldon
Anneoldon
hu?
the while part is the one i show u on the last post.

the declaration of zone is:
ZONE zone[1][1];

is the fundment of my application (i want to stock different zone in a awray of struct)

[edited by - Anneoldon on August 1, 2002 11:07:08 AM]
Anneoldon
Anneoldon
well i fund!
look, that works

for (int x = 0; x<4;x++)
Zone[x].lpsurface=fonccreation();

but not that

for (int y = 0; y<2;y++)
for (int x = 0; x<2;x++)
Zone[y][x].lpsurface=fonccreation();

Topic Locked

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

Sign in to reply to this topic.