diff --git a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp index 9cf31a07..97c50655 100644 --- a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp +++ b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp @@ -117,6 +117,7 @@ namespace MobileGL { free(processedPixels); mipmap.dirty = true; + mipmap.hasData = true; } void TexSubImage1D_State(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, @@ -396,7 +397,7 @@ namespace MobileGL { if (!isProxy && !mipmap.inputData.data) { MGLOG_E("TexImage2D_State: Failed to allocate memory for mipmap level data, size: %zu", totalBytes); - if (processedPixels) free(processedPixels); + free(processedPixels); processedPixels = nullptr; } @@ -410,9 +411,9 @@ namespace MobileGL { const SizeT copySize = std::min(imageSize, totalBytes); Memcpy(mipmap.inputData.data, processedPixels, copySize); free(processedPixels); - } else if (pixels && !isProxy) { + } else if (processedPixels && !isProxy) { MGLOG_E("TexImage2D_State: Failed to process pixel data, initializing with original data."); - Memcpy(mipmap.inputData.data, pixels, totalBytes); + Memcpy(mipmap.inputData.data, originalPixels, totalBytes); } else { if (mipmap.inputData.data) { free(mipmap.inputData.data); @@ -421,7 +422,7 @@ namespace MobileGL { } textureObject->SetInternalFormat(textureInternalFormat); textureObject->SetMipmapLevel(mipmap); - if (mipmap.inputData.data) free(mipmap.inputData.data); + free(mipmap.inputData.data); } void TexImage1D_State(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLint border, diff --git a/MobileGL/MG_State/GLState/TextureState/TextureObject.h b/MobileGL/MG_State/GLState/TextureState/TextureObject.h index cca487c6..878eef9a 100644 --- a/MobileGL/MG_State/GLState/TextureState/TextureObject.h +++ b/MobileGL/MG_State/GLState/TextureState/TextureObject.h @@ -200,12 +200,14 @@ namespace MobileGL { struct MipmapLevelInternal : MipmapLevelBase { Data data; Bool dirty = true; + Bool hasData = false; MipmapLevelInternal(const MipmapLevelInput& input) : MipmapLevelBase(input) { - data.resize(input.inputData.size); + data.resize(input.inputData.size, 0); if (input.inputData.data && input.inputData.size > 0) { const Uint8* src = static_cast(input.inputData.data); Memcpy(data.data(), src, input.inputData.size); + hasData = true; } } };