From 8d3dd1449898d116ba8d1692c17b9d9152c51111 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Tue, 18 Nov 2025 12:47:09 +0800 Subject: [PATCH] [Fix] (MG_Impl/Texture): don't malloc if unnecessary --- MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp index 64672f32..53475b14 100644 --- a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp +++ b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp @@ -395,13 +395,15 @@ namespace MobileGL { processedPixels = MG_Util::PixelStoreProcessor::ProcessTexturePixelsDataUnpack( originalPixels, MG_State::pGLContext->GetPixelStoreParameters(true), bytesPerPixel, {width, height, 1}, false, imageSize); + } else { + MGLOG_D("TexImage2D_State: No input pixel, do allocate only"); } MG_State::GLState::MipmapLevelInput mipmap = MG_State::GLState::MipmapLevelInput({width, height, 1}, level, false, 0, - {isProxy ? nullptr : malloc(totalBytes), isProxy ? 0 : totalBytes}); + {(isProxy || originalPixels == nullptr) ? nullptr : malloc(totalBytes), isProxy ? 0 : totalBytes}); - if (!isProxy && !mipmap.inputData.data) { + if (!isProxy && originalPixels != nullptr && !mipmap.inputData.data) { MGLOG_E("TexImage2D_State: Failed to allocate memory for mipmap level data, size: %zu", totalBytes); free(processedPixels); processedPixels = nullptr;