Skip to content

Commit

Permalink
Fix textures memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
SaiyansKing committed Sep 18, 2021
1 parent 5e4e9bf commit 1d08855
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
10 changes: 9 additions & 1 deletion D3D11Engine/D3D7/FakeDirectDrawSurface7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ FakeDirectDrawSurface7::FakeDirectDrawSurface7() {
Data = nullptr;
}

FakeDirectDrawSurface7::~FakeDirectDrawSurface7() {
// Release mip-map chain first
for ( LPDIRECTDRAWSURFACE7 mipmap : AttachedSurfaces ) {
mipmap->Release();
}

delete[] Data;
}

void FakeDirectDrawSurface7::InitFakeSurface( const DDSURFACEDESC2* desc, MyDirectDrawSurface7* Resource, int mipLevel ) {
OriginalDesc = *desc;
this->Resource = Resource;
Expand All @@ -33,7 +42,6 @@ ULONG FakeDirectDrawSurface7::Release() {
RefCount--;

if ( RefCount == 0 ) {
delete [] Data;
delete this;
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions D3D11Engine/D3D7/FakeDirectDrawSurface7.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MyDirectDrawSurface7;
class FakeDirectDrawSurface7 : public IDirectDrawSurface7 {
public:
FakeDirectDrawSurface7();
~FakeDirectDrawSurface7();

/*** IUnknown methods ***/
HRESULT __stdcall QueryInterface( REFIID riid, LPVOID* ppvObj );
Expand Down
3 changes: 0 additions & 3 deletions D3D11Engine/D3D7/MyDirectDraw.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ class MyDirectDraw : public IDirectDraw7 {
FakeDirectDrawSurface7* lastMip = nullptr;
int level = 1;
while ( desc.dwMipMapCount > 1 ) {

FakeDirectDrawSurface7* mip = new FakeDirectDrawSurface7;
desc.dwMipMapCount--;
//desc.dwHeight /= 2;
Expand All @@ -241,8 +240,6 @@ class MyDirectDraw : public IDirectDraw7 {
lastMip = mip;
level++;
}


}

*lplpDDSurface = mySurface;
Expand Down
5 changes: 5 additions & 0 deletions D3D11Engine/D3D7/MyDirectDrawSurface7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ MyDirectDrawSurface7::MyDirectDrawSurface7() {
MyDirectDrawSurface7::~MyDirectDrawSurface7() {
Engine::GAPI->RemoveSurface( this );

// Release mip-map chain first
for ( LPDIRECTDRAWSURFACE7 mipmap : attachedSurfaces ) {
mipmap->Release();
}

// Sometimes gothic doesn't unlock a surface or this is a movie-buffer
delete[] LockedData;

Expand Down

0 comments on commit 1d08855

Please # to comment.