From acef9af5d42e1389ce6088c2defb13b696fe8e9b Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sat, 28 Jan 2017 23:16:37 +0100 Subject: [PATCH] Fix a bug in TextureUtil, may help #9248 --- UI/TextureUtil.cpp | 13 +++++++------ UI/TextureUtil.h | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/UI/TextureUtil.cpp b/UI/TextureUtil.cpp index d82e1c6960..1acd66fbc7 100644 --- a/UI/TextureUtil.cpp +++ b/UI/TextureUtil.cpp @@ -79,13 +79,12 @@ static bool LoadTextureLevels(const uint8_t *data, size_t size, ImageFileType ty bool ManagedTexture::LoadFromFileData(const uint8_t *data, size_t dataSize, ImageFileType type) { using namespace Draw; - int width[16], height[16]; - uint8_t *image[16] = { nullptr }; + int width[16]{}, height[16]{}; + uint8_t *image[16]{}; - int num_levels; - int zim_flags; + int num_levels = 0; + int zim_flags = 0; DataFormat fmt; - if (!LoadTextureLevels(data, dataSize, type, width, height, &num_levels, &fmt, image, &zim_flags)) { return false; } @@ -95,8 +94,10 @@ bool ManagedTexture::LoadFromFileData(const uint8_t *data, size_t dataSize, Imag num_levels = 1; } - if (texture_) + if (texture_) { delete texture_; + texture_ = nullptr; + } TextureDesc desc{}; desc.type = TextureType::LINEAR2D; diff --git a/UI/TextureUtil.h b/UI/TextureUtil.h index c1b6ea3aaa..5d5d1d2d0f 100644 --- a/UI/TextureUtil.h +++ b/UI/TextureUtil.h @@ -21,6 +21,7 @@ public: } void GLLost() override { delete texture_; + texture_ = nullptr; } void GLRestore() override { if (!filename_.empty()) {