DXGL r514 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r513‎ | r514 | r515 >
Date:22:35, 1 September 2014
Author:admin
Status:new
Tags:
Comment:
Refcount fixes for glDirectDraw interfaces.
Make CreateSurface call AddRef on DDraw interface and give it to surface to clean up upon deletion.
Modified paths:
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.h (modified) (history)

Diff [purge]

Index: ddraw/glDirectDraw.cpp
@@ -645,7 +645,6 @@
646646 TRACE_ENTER(1,14,this);
647647 if(initialized)
648648 {
649 - if(glD3D7) glD3D7->Release();
650649 RestoreDisplayMode();
651650 if(clippers)
652651 {
@@ -897,7 +896,14 @@
898897 if(!lpDDSurfaceDesc2) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
899898 if(pUnkOuter) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
900899 if(lpDDSurfaceDesc2->dwSize < sizeof(DDSURFACEDESC2)) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
901 - TRACE_RET(HRESULT,23,CreateSurface2(lpDDSurfaceDesc2,lplpDDSurface,pUnkOuter,TRUE));
 900+ HRESULT ret = CreateSurface2(lpDDSurfaceDesc2,lplpDDSurface,pUnkOuter,TRUE);
 901+ if (ret == DD_OK)
 902+ {
 903+ this->AddRef();
 904+ ((glDirectDrawSurface7*)lplpDDSurface)->creator = this;
 905+ }
 906+ TRACE_EXIT(23, ret);
 907+ return ret;
902908 }
903909
904910
@@ -2028,6 +2034,8 @@
20292035 {
20302036 lpDDS7->QueryInterface(IID_IDirectDrawSurface,(LPVOID*) lplpDDSurface);
20312037 lpDDS7->Release();
 2038+ this->AddRef();
 2039+ ((glDirectDrawSurface7*)lpDDS7)->creator = this;
20322040 TRACE_VAR("*lplpDDSurface",14,lplpDDSurface);
20332041 TRACE_EXIT(23,DD_OK);
20342042 return DD_OK;
@@ -2221,7 +2229,9 @@
22222230 {
22232231 lpDDS7->QueryInterface(IID_IDirectDrawSurface,(LPVOID*) lplpDDSurface);
22242232 lpDDS7->Release();
2225 - TRACE_EXIT(23,DD_OK);
 2233+ this->AddRef();
 2234+ ((glDirectDrawSurface7*)lpDDS7)->creator = this;
 2235+ TRACE_EXIT(23, DD_OK);
22262236 return DD_OK;
22272237 }
22282238 TRACE_EXIT(23,err);
@@ -2394,13 +2404,13 @@
23952405 {
23962406 TRACE_ENTER(1,14,this);
23972407 if(!this) TRACE_RET(ULONG,8,0);
2398 - TRACE_RET(ULONG, 8, glDD7->AddRef());
 2408+ TRACE_RET(ULONG, 8, glDD7->AddRef4());
23992409 }
24002410 ULONG WINAPI glDirectDraw4::Release()
24012411 {
24022412 TRACE_ENTER(1,14,this);
24032413 if(!this) TRACE_RET(ULONG,8,0);
2404 - TRACE_RET(ULONG, 8, glDD7->Release());
 2414+ TRACE_RET(ULONG, 8, glDD7->Release4());
24052415 }
24062416 HRESULT WINAPI glDirectDraw4::Compact()
24072417 {
@@ -2433,7 +2443,9 @@
24342444 {
24352445 lpDDS7->QueryInterface(IID_IDirectDrawSurface4,(LPVOID*) lplpDDSurface);
24362446 lpDDS7->Release();
2437 - TRACE_EXIT(23,DD_OK);
 2447+ this->AddRef();
 2448+ ((glDirectDrawSurface7*)lpDDS7)->creator = this;
 2449+ TRACE_EXIT(23, DD_OK);
24382450 return DD_OK;
24392451 }
24402452 TRACE_EXIT(23,err);
Index: ddraw/glDirectDrawSurface.cpp
@@ -40,6 +40,7 @@
4141 glDirectDrawPalette *palettein, TEXTURE *parenttex, DWORD miplevel)
4242 {
4343 TRACE_ENTER(5,14,this,14,lpDD7,14,lpDDSurfaceDesc2,14,error,14,palettein);
 44+ creator = NULL;
4445 overlay = false;
4546 hasstencil = false;
4647 dirty = 2;
@@ -397,6 +398,7 @@
398399 if(miptexture) miptexture->Release();
399400 if(device) device->Release();
400401 ddInterface->DeleteSurface(this);
 402+ if (creator) creator->Release();
401403 TRACE_EXIT(-1,0);
402404 }
403405 HRESULT WINAPI glDirectDrawSurface7::QueryInterface(REFIID riid, void** ppvObj)
Index: ddraw/glDirectDrawSurface.h
@@ -140,6 +140,7 @@
141141 FBO fbo;
142142 FBO stencilfbo;
143143 glDirectDrawClipper *clipper;
 144+ IUnknown *creator;
144145 private:
145146 int swapinterval;
146147 ULONG refcount;