1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-15 06:04:49 +01:00

allocate memory for surfaces on CreateDIBSection failure

This commit is contained in:
FunkyFr3sh 2018-07-01 21:27:44 +02:00
parent 0b12de90e2
commit 897fdb5bbb
2 changed files with 11 additions and 4 deletions

View File

@ -426,7 +426,7 @@ DWORD WINAPI render_main(void)
{
snprintf(
debugText, sizeof(debugText),
"FPS: %lu | Time: %2.2f ms",
"FPS: %lu | Time: %2.2f ms ",
frame_count, frameTime);
frame_count = 0;

View File

@ -51,11 +51,14 @@ ULONG __stdcall ddraw_surface_Release(IDirectDrawSurfaceImpl *This)
ddraw->primary = NULL;
LeaveCriticalSection(&ddraw->cs);
}
if(This->surface)
{
if (This->bitmap)
DeleteObject(This->bitmap);
else if (This->surface)
HeapFree(GetProcessHeap(), 0, This->surface);
if (This->hDC)
DeleteDC(This->hDC);
}
if (This->bmi)
HeapFree(GetProcessHeap(), 0, This->bmi);
@ -519,6 +522,10 @@ HRESULT __stdcall ddraw_CreateSurface(IDirectDrawImpl *This, LPDDSURFACEDESC lpD
Surface->hDC = CreateCompatibleDC(ddraw->render.hDC);
Surface->bitmap = CreateDIBSection(Surface->hDC, Surface->bmi, DIB_RGB_COLORS, (void **)&Surface->surface, NULL, 0);
if (!Surface->bitmap)
Surface->surface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Surface->lPitch * Surface->height * Surface->lXPitch);
SelectObject(Surface->hDC, Surface->bitmap);
}