diff --git a/engines/grim/gfx_base.h b/engines/grim/gfx_base.h index 450dad36e0f..524580eab78 100644 --- a/engines/grim/gfx_base.h +++ b/engines/grim/gfx_base.h @@ -268,6 +268,7 @@ public: virtual Material *getSpecialtyTexture(int n) { return &_specialty[n]; } virtual void createMesh(Mesh *mesh) {} + virtual void destroyMesh(const Mesh *mesh) {} virtual void createEMIModel(EMIModel *model) {} virtual void updateEMIModel(const EMIModel *model) {} diff --git a/engines/grim/gfx_opengl_shaders.cpp b/engines/grim/gfx_opengl_shaders.cpp index 141024fc694..791aef0824b 100644 --- a/engines/grim/gfx_opengl_shaders.cpp +++ b/engines/grim/gfx_opengl_shaders.cpp @@ -1938,6 +1938,24 @@ void GfxOpenGLS::createMesh(Mesh *mesh) { shader->disableVertexAttribute("color", Math::Vector4d(1.f, 1.f, 1.f, 1.f)); } +void GfxOpenGLS::destroyMesh(const Mesh *mesh) { + ModelUserData *mud = static_cast(mesh->_userData); + + for (int i = 0; i < mesh->_numFaces; ++i) { + MeshFace *face = &mesh->_faces[i]; + if (face->_userData) { + uint32 *data = static_cast(face->_userData); + delete data; + } + } + + if (!mud) + return; + + delete mud->_shader; + delete mud; +} + } diff --git a/engines/grim/gfx_opengl_shaders.h b/engines/grim/gfx_opengl_shaders.h index a3b24455d70..1a6da798777 100644 --- a/engines/grim/gfx_opengl_shaders.h +++ b/engines/grim/gfx_opengl_shaders.h @@ -201,6 +201,7 @@ public: virtual void createSpecialtyTextures() override; virtual void createMesh(Mesh *mesh) override; + virtual void destroyMesh(const Mesh *mesh) override; virtual void createEMIModel(EMIModel *model) override; virtual void updateEMIModel(const EMIModel* model) override; diff --git a/engines/grim/model.cpp b/engines/grim/model.cpp index e7422bf0688..bce5c483690 100644 --- a/engines/grim/model.cpp +++ b/engines/grim/model.cpp @@ -407,6 +407,8 @@ Mesh::Mesh() : Mesh::~Mesh() { + g_driver->destroyMesh(this); + delete[] _vertices; delete[] _verticesI; delete[] _vertNormals;