From d57841bcb80999845ef7e8d1cb712a8a39c97fd1 Mon Sep 17 00:00:00 2001 From: Benau Date: Tue, 3 Jan 2017 12:35:05 +0800 Subject: [PATCH] Fix crash if skybox / SH shares textures from track --- src/graphics/skybox.cpp | 6 ++++-- src/graphics/spherical_harmonics.cpp | 6 ++++-- src/graphics/stk_tex_manager.cpp | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/graphics/skybox.cpp b/src/graphics/skybox.cpp index 58eaa8944..cfa80d443 100644 --- a/src/graphics/skybox.cpp +++ b/src/graphics/skybox.cpp @@ -161,8 +161,10 @@ void Skybox::generateCubeMapFromTextures() for (unsigned i = 0; i < 6; i++) { unsigned idx = texture_permutation[i]; - static_cast(m_skybox_textures[idx])->getTextureImage() - ->copyToScaling(rgba[i], size, size); + video::IImage* img = static_cast + (m_skybox_textures[idx])->getTextureImage(); + assert(img != NULL); + img->copyToScaling(rgba[i], size, size); #if defined(USE_GLES2) for (unsigned int j = 0; j < size * size; j++) diff --git a/src/graphics/spherical_harmonics.cpp b/src/graphics/spherical_harmonics.cpp index cd6c3a718..55198c217 100644 --- a/src/graphics/spherical_harmonics.cpp +++ b/src/graphics/spherical_harmonics.cpp @@ -406,8 +406,10 @@ void SphericalHarmonics::setTextures(const std::vector &spher for (unsigned i = 0; i < 6; i++) { unsigned idx = texture_permutation[i]; - static_cast(m_spherical_harmonics_textures[idx]) - ->getTextureImage()->copyToScaling(sh_rgba[i], sh_w, sh_h); + video::IImage* img = static_cast + (m_spherical_harmonics_textures[idx])->getTextureImage(); + assert(img != NULL); + img->copyToScaling(sh_rgba[i], sh_w, sh_h); } //for (unsigned i = 0; i < 6; i++) Color *float_tex_cube[6]; diff --git a/src/graphics/stk_tex_manager.cpp b/src/graphics/stk_tex_manager.cpp index 8372f5894..7137e95ce 100644 --- a/src/graphics/stk_tex_manager.cpp +++ b/src/graphics/stk_tex_manager.cpp @@ -72,7 +72,7 @@ STKTexture* STKTexManager::getTexture(const std::string& path, bool srgb, bool mesh_tex, bool no_upload) { auto ret = m_all_textures.find(path); - if (ret != m_all_textures.end()) + if (!no_upload && ret != m_all_textures.end()) return ret->second; STKTexture* new_texture = NULL; @@ -82,7 +82,7 @@ STKTexture* STKTexManager::getTexture(const std::string& path, bool srgb, new_texture = findTextureInFileSystem(path, &full_path); if (full_path == "") return NULL; - if (new_texture) + if (!no_upload && new_texture) return new_texture; }