mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-25 13:21:28 +00:00
Fix double delete bug
This commit is contained in:
parent
e68da4331a
commit
459742c840
8 changed files with 40 additions and 8 deletions
|
@ -25,11 +25,18 @@
|
|||
|
||||
GLIndexBuffer::~GLIndexBuffer()
|
||||
{
|
||||
if (Device && mBuffer != 0)
|
||||
Finalize();
|
||||
}
|
||||
|
||||
void GLIndexBuffer::Finalize()
|
||||
{
|
||||
if (Device)
|
||||
{
|
||||
Device->mIndexBuffers.erase(ItBuffer);
|
||||
Device = nullptr;
|
||||
glDeleteBuffers(1, &mBuffer);
|
||||
|
||||
if (mBuffer != 0)
|
||||
glDeleteBuffers(1, &mBuffer);
|
||||
mBuffer = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ class GLIndexBuffer : public IndexBuffer
|
|||
public:
|
||||
~GLIndexBuffer();
|
||||
|
||||
void Finalize();
|
||||
|
||||
GLuint GetBuffer();
|
||||
|
||||
GLRenderDevice* Device = nullptr;
|
||||
|
|
|
@ -87,7 +87,7 @@ GLRenderDevice::~GLRenderDevice()
|
|||
for (GLIndexBuffer* buffer : mIndexBuffers) mDeleteList.IndexBuffers.push_back(buffer);
|
||||
for (GLVertexBuffer* buffer : mSharedVertexBuffers[0]->VertexBuffers) mDeleteList.VertexBuffers.push_back(buffer);
|
||||
for (GLVertexBuffer* buffer : mSharedVertexBuffers[1]->VertexBuffers) mDeleteList.VertexBuffers.push_back(buffer);
|
||||
ProcessDeleteList();
|
||||
ProcessDeleteList(true);
|
||||
|
||||
glDeleteBuffers(1, &mStreamVertexBuffer);
|
||||
glDeleteVertexArrays(1, &mStreamVAO);
|
||||
|
@ -965,13 +965,22 @@ void GLRenderDevice::DeleteObject(GLTexture* texture)
|
|||
delete texture;
|
||||
}
|
||||
|
||||
void GLRenderDevice::ProcessDeleteList()
|
||||
void GLRenderDevice::ProcessDeleteList(bool finalize)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(GLRenderDevice::GetMutex());
|
||||
|
||||
for (auto buffer : mDeleteList.IndexBuffers) delete buffer;
|
||||
for (auto buffer : mDeleteList.VertexBuffers) delete buffer;
|
||||
for (auto texture : mDeleteList.Textures) delete texture;
|
||||
if (!finalize)
|
||||
{
|
||||
for (auto buffer : mDeleteList.IndexBuffers) delete buffer;
|
||||
for (auto buffer : mDeleteList.VertexBuffers) delete buffer;
|
||||
for (auto texture : mDeleteList.Textures) delete texture;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto buffer : mDeleteList.IndexBuffers) buffer->Finalize();
|
||||
for (auto buffer : mDeleteList.VertexBuffers) buffer->Finalize();
|
||||
for (auto texture : mDeleteList.Textures) texture->Finalize();
|
||||
}
|
||||
|
||||
mDeleteList.IndexBuffers.clear();
|
||||
mDeleteList.VertexBuffers.clear();
|
||||
|
|
|
@ -106,7 +106,7 @@ public:
|
|||
static void DeleteObject(GLIndexBuffer* buffer);
|
||||
static void DeleteObject(GLTexture* texture);
|
||||
|
||||
void ProcessDeleteList();
|
||||
void ProcessDeleteList(bool finalize = false);
|
||||
|
||||
std::unique_ptr<IOpenGLContext> Context;
|
||||
|
||||
|
|
|
@ -29,6 +29,11 @@ GLTexture::GLTexture()
|
|||
}
|
||||
|
||||
GLTexture::~GLTexture()
|
||||
{
|
||||
Finalize();
|
||||
}
|
||||
|
||||
void GLTexture::Finalize()
|
||||
{
|
||||
if (Device)
|
||||
Invalidate();
|
||||
|
|
|
@ -32,6 +32,8 @@ public:
|
|||
GLTexture();
|
||||
~GLTexture();
|
||||
|
||||
void Finalize();
|
||||
|
||||
void Set2DImage(int width, int height) override;
|
||||
void SetCubeImage(int size) override;
|
||||
|
||||
|
|
|
@ -72,6 +72,11 @@ void GLSharedVertexBuffer::SetupWorldVAO()
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GLVertexBuffer::~GLVertexBuffer()
|
||||
{
|
||||
Finalize();
|
||||
}
|
||||
|
||||
void GLVertexBuffer::Finalize()
|
||||
{
|
||||
if (Device)
|
||||
{
|
||||
|
|
|
@ -56,6 +56,8 @@ class GLVertexBuffer : public VertexBuffer
|
|||
public:
|
||||
~GLVertexBuffer();
|
||||
|
||||
void Finalize();
|
||||
|
||||
VertexFormat Format = VertexFormat::Flat;
|
||||
|
||||
GLRenderDevice* Device = nullptr;
|
||||
|
|
Loading…
Reference in a new issue