diff --git a/engines/grim/bitmap.cpp b/engines/grim/bitmap.cpp index f163bb575cb..b0b26a2c4ee 100644 --- a/engines/grim/bitmap.cpp +++ b/engines/grim/bitmap.cpp @@ -232,7 +232,7 @@ BitmapData::~BitmapData() { } void BitmapData::freeData() { - if (!_keepData) { + if (!_keepData && _data) { for (int i = 0; i < _numImages; ++i) { _data[i].free(); } diff --git a/engines/grim/gfx_opengl_shaders.cpp b/engines/grim/gfx_opengl_shaders.cpp index e941335568e..fbc2754f030 100644 --- a/engines/grim/gfx_opengl_shaders.cpp +++ b/engines/grim/gfx_opengl_shaders.cpp @@ -1218,9 +1218,10 @@ void GfxOpenGLS::selectTexture(const Texture *texture) { void GfxOpenGLS::destroyTexture(Texture *texture) { GLuint *textures = static_cast(texture->_texture); - glDeleteTextures(1, textures); - - delete[] textures; + if (textures) { + glDeleteTextures(1, textures); + delete[] textures; + } } void GfxOpenGLS::createBitmap(BitmapData *bitmap) { diff --git a/engines/grim/gfx_tinygl.cpp b/engines/grim/gfx_tinygl.cpp index ced4cb68685..e1389b3348e 100644 --- a/engines/grim/gfx_tinygl.cpp +++ b/engines/grim/gfx_tinygl.cpp @@ -1247,8 +1247,11 @@ void GfxTinyGL::selectTexture(const Texture *texture) { } void GfxTinyGL::destroyTexture(Texture *texture) { - tglDeleteTextures(1, (TGLuint *)texture->_texture); - delete[] (TGLuint *)texture->_texture; + TGLuint *textures = (TGLuint *)texture->_texture; + if (textures) { + tglDeleteTextures(1, textures); + delete[] textures; + } } void GfxTinyGL::prepareMovieFrame(Graphics::Surface *frame) {