mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-29 07:01:55 +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()
|
GLIndexBuffer::~GLIndexBuffer()
|
||||||
{
|
{
|
||||||
if (Device && mBuffer != 0)
|
Finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLIndexBuffer::Finalize()
|
||||||
|
{
|
||||||
|
if (Device)
|
||||||
{
|
{
|
||||||
Device->mIndexBuffers.erase(ItBuffer);
|
Device->mIndexBuffers.erase(ItBuffer);
|
||||||
Device = nullptr;
|
Device = nullptr;
|
||||||
glDeleteBuffers(1, &mBuffer);
|
|
||||||
|
if (mBuffer != 0)
|
||||||
|
glDeleteBuffers(1, &mBuffer);
|
||||||
mBuffer = 0;
|
mBuffer = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@ class GLIndexBuffer : public IndexBuffer
|
||||||
public:
|
public:
|
||||||
~GLIndexBuffer();
|
~GLIndexBuffer();
|
||||||
|
|
||||||
|
void Finalize();
|
||||||
|
|
||||||
GLuint GetBuffer();
|
GLuint GetBuffer();
|
||||||
|
|
||||||
GLRenderDevice* Device = nullptr;
|
GLRenderDevice* Device = nullptr;
|
||||||
|
|
|
@ -87,7 +87,7 @@ GLRenderDevice::~GLRenderDevice()
|
||||||
for (GLIndexBuffer* buffer : mIndexBuffers) mDeleteList.IndexBuffers.push_back(buffer);
|
for (GLIndexBuffer* buffer : mIndexBuffers) mDeleteList.IndexBuffers.push_back(buffer);
|
||||||
for (GLVertexBuffer* buffer : mSharedVertexBuffers[0]->VertexBuffers) mDeleteList.VertexBuffers.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);
|
for (GLVertexBuffer* buffer : mSharedVertexBuffers[1]->VertexBuffers) mDeleteList.VertexBuffers.push_back(buffer);
|
||||||
ProcessDeleteList();
|
ProcessDeleteList(true);
|
||||||
|
|
||||||
glDeleteBuffers(1, &mStreamVertexBuffer);
|
glDeleteBuffers(1, &mStreamVertexBuffer);
|
||||||
glDeleteVertexArrays(1, &mStreamVAO);
|
glDeleteVertexArrays(1, &mStreamVAO);
|
||||||
|
@ -965,13 +965,22 @@ void GLRenderDevice::DeleteObject(GLTexture* texture)
|
||||||
delete texture;
|
delete texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLRenderDevice::ProcessDeleteList()
|
void GLRenderDevice::ProcessDeleteList(bool finalize)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(GLRenderDevice::GetMutex());
|
std::unique_lock<std::mutex> lock(GLRenderDevice::GetMutex());
|
||||||
|
|
||||||
for (auto buffer : mDeleteList.IndexBuffers) delete buffer;
|
if (!finalize)
|
||||||
for (auto buffer : mDeleteList.VertexBuffers) delete buffer;
|
{
|
||||||
for (auto texture : mDeleteList.Textures) delete texture;
|
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.IndexBuffers.clear();
|
||||||
mDeleteList.VertexBuffers.clear();
|
mDeleteList.VertexBuffers.clear();
|
||||||
|
|
|
@ -106,7 +106,7 @@ public:
|
||||||
static void DeleteObject(GLIndexBuffer* buffer);
|
static void DeleteObject(GLIndexBuffer* buffer);
|
||||||
static void DeleteObject(GLTexture* texture);
|
static void DeleteObject(GLTexture* texture);
|
||||||
|
|
||||||
void ProcessDeleteList();
|
void ProcessDeleteList(bool finalize = false);
|
||||||
|
|
||||||
std::unique_ptr<IOpenGLContext> Context;
|
std::unique_ptr<IOpenGLContext> Context;
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,11 @@ GLTexture::GLTexture()
|
||||||
}
|
}
|
||||||
|
|
||||||
GLTexture::~GLTexture()
|
GLTexture::~GLTexture()
|
||||||
|
{
|
||||||
|
Finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLTexture::Finalize()
|
||||||
{
|
{
|
||||||
if (Device)
|
if (Device)
|
||||||
Invalidate();
|
Invalidate();
|
||||||
|
|
|
@ -32,6 +32,8 @@ public:
|
||||||
GLTexture();
|
GLTexture();
|
||||||
~GLTexture();
|
~GLTexture();
|
||||||
|
|
||||||
|
void Finalize();
|
||||||
|
|
||||||
void Set2DImage(int width, int height) override;
|
void Set2DImage(int width, int height) override;
|
||||||
void SetCubeImage(int size) override;
|
void SetCubeImage(int size) override;
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,11 @@ void GLSharedVertexBuffer::SetupWorldVAO()
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
GLVertexBuffer::~GLVertexBuffer()
|
GLVertexBuffer::~GLVertexBuffer()
|
||||||
|
{
|
||||||
|
Finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLVertexBuffer::Finalize()
|
||||||
{
|
{
|
||||||
if (Device)
|
if (Device)
|
||||||
{
|
{
|
||||||
|
|
|
@ -56,6 +56,8 @@ class GLVertexBuffer : public VertexBuffer
|
||||||
public:
|
public:
|
||||||
~GLVertexBuffer();
|
~GLVertexBuffer();
|
||||||
|
|
||||||
|
void Finalize();
|
||||||
|
|
||||||
VertexFormat Format = VertexFormat::Flat;
|
VertexFormat Format = VertexFormat::Flat;
|
||||||
|
|
||||||
GLRenderDevice* Device = nullptr;
|
GLRenderDevice* Device = nullptr;
|
||||||
|
|
Loading…
Reference in a new issue