Skip to content

Commit

Permalink
Resolve some GL Pipeline memory leaks & crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Aug 8, 2024
1 parent b6867d3 commit 24adbae
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ void plGLDevice::Shutdown()
{
if (fImpl)
fImpl->Shutdown();

delete fImpl;
}

void plGLDevice::SetRenderTarget(plRenderTarget* target)
Expand Down
2 changes: 2 additions & 0 deletions Sources/Plasma/FeatureLib/pfGLPipeline/plGLDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class plGLDeviceImpl
: fWindow(window), fDevice(device) {};

public:
virtual ~plGLDeviceImpl() { };

virtual void Shutdown() = 0;
virtual bool BeginRender(ST::string& error) = 0;
virtual bool EndRender(ST::string& error) = 0;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/FeatureLib/pfGLPipeline/plGLDeviceRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class plGLRenderTargetRef: public plGLTextureRef

virtual ~plGLRenderTargetRef();

void Release();
void Release() override;

virtual void SetOwner(plRenderTarget* targ) { fOwner = (plBitmap*)targ; }
};
Expand Down
7 changes: 5 additions & 2 deletions Sources/Plasma/FeatureLib/pfGLPipeline/plGLDeviceRefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ You can contact Cyan Worlds, Inc. by email [email protected]
Mead, WA 99021
*==LICENSE==*/
#include "plPipeline/hsWinRef.h"

#include "plGLPipeline.h"
#include "plGLDeviceRef.h"

#include "plProfile.h"
#include "plStatusLog/plStatusLog.h"

plProfile_Extern(MemVertex);
plProfile_Extern(MemIndex);
Expand Down Expand Up @@ -105,6 +103,11 @@ void plGLVertexBufferRef::Release()
glDeleteBuffers(1, &fRef);
fRef = 0;
}

if (fData) {
delete[] fData;
}

SetDirty(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ void plGLMaterialShaderRef::ICompile()
LOG_GL_ERROR_CHECK("Create Program failed");

if (plGLVersion() >= 43) {
const char* name = ST::format("hsGMaterial::{}", fMaterial->GetKeyName()).c_str();
glObjectLabel(GL_PROGRAM, fRef, strlen(name), name);
ST::string name = ST::format("hsGMaterial::{}", fMaterial->GetKeyName());
glObjectLabel(GL_PROGRAM, fRef, strlen(name.c_str()), name.c_str());
}

glAttachShader(fRef, fVertShaderRef);
Expand Down
8 changes: 8 additions & 0 deletions Sources/Plasma/FeatureLib/pfGLPipeline/plGLPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,15 @@ plGLPipeline::~plGLPipeline()
if (plGLPlateManager* pm = static_cast<plGLPlateManager*>(fPlateMgr))
pm->IReleaseGeometry();

delete fPlateMgr;
fPlateMgr = nullptr;

while (fTextFontRefList)
delete fTextFontRefList;

delete fDebugTextMgr;
fDebugTextMgr = nullptr;

fDevice.Shutdown();
}

Expand Down Expand Up @@ -736,6 +742,7 @@ void plGLPipeline::RenderSpans(plDrawableSpans* ice, const std::vector<int16_t>&
if (mRef == nullptr) {
mRef = new plGLMaterialShaderRef(material, this);
material->SetDeviceRef(mRef);
hsRefCnt_SafeUnRef(mRef);
}

if (!mRef->IsLinked())
Expand Down Expand Up @@ -1482,6 +1489,7 @@ void plGLPipeline::IDrawPlate(plPlate* plate)
if (mRef == nullptr) {
mRef = new plGLMaterialShaderRef(material, this);
material->SetDeviceRef(mRef);
hsRefCnt_SafeUnRef(mRef);
}

if (!mRef->IsLinked())
Expand Down
18 changes: 18 additions & 0 deletions Sources/Plasma/PubUtilLib/plPipeline/pl3DPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,24 @@ pl3DPipeline<DeviceType>::~pl3DPipeline()
while (fActiveLights)
UnRegisterLight(fActiveLights);

while (fVtxBuffRefList) {
typename DeviceType::VertexBufferRef* ref = fVtxBuffRefList;
ref->Release();
ref->Unlink();
}

while (fIdxBuffRefList) {
typename DeviceType::IndexBufferRef* ref = fIdxBuffRefList;
ref->Release();
ref->Unlink();
}

while (fTextureRefList) {
typename DeviceType::TextureRef* ref = fTextureRefList;
ref->Release();
ref->Unlink();
}

IReleaseAvRTPool();
IClearClothingOutfits(&fClothingOutfits);
IClearClothingOutfits(&fPrevClothingOutfits);
Expand Down
2 changes: 2 additions & 0 deletions Sources/Plasma/PubUtilLib/plPipeline/plNullPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class plNullPipelineDevice
uint32_t fVertexSize;
uint32_t fFormat;

void Release() { }
void Link(NullDeviceRef** back) { }
void Unlink() { }
bool IsLinked() { return true; }
bool Volatile() const { return false; }
};
Expand Down

0 comments on commit 24adbae

Please sign in to comment.