From 775b752f853ce746e18244c5ef7a08692ad7ecf4 Mon Sep 17 00:00:00 2001 From: halx99 Date: Fri, 6 Dec 2024 00:37:54 +0800 Subject: [PATCH] Fix #2256 --- core/platform/mac/Device-mac.mm | 4 ++-- core/platform/win32/Device-win32.cpp | 4 ++-- core/renderer/Texture2D.cpp | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/core/platform/mac/Device-mac.mm b/core/platform/mac/Device-mac.mm index fad9f69b414..a20042f12e9 100644 --- a/core/platform/mac/Device-mac.mm +++ b/core/platform/mac/Device-mac.mm @@ -429,8 +429,8 @@ static bool _initWithString(std::string_view text, { break; } - height = (short)info.height; - width = (short)info.width; + height = static_cast(info.height); + width = static_cast(info.width); ret.fastSet(info.data, width * height * 4); hasPremultipliedAlpha = true; } while (0); diff --git a/core/platform/win32/Device-win32.cpp b/core/platform/win32/Device-win32.cpp index 322e66a451d..630d6f7ce9d 100644 --- a/core/platform/win32/Device-win32.cpp +++ b/core/platform/win32/Device-win32.cpp @@ -450,8 +450,8 @@ Data Device::getTextureDataForText(std::string_view text, bi.bmiHeader.biSize = sizeof(bi.bmiHeader); AX_BREAK_IF(!GetDIBits(dc.getDC(), dc.getBitmap(), 0, 0, nullptr, (LPBITMAPINFO)&bi, DIB_RGB_COLORS)); - width = (short)size.cx; - height = (short)size.cy; + width = static_cast(size.cx); + height = static_cast(size.cy); // copy pixel data bi.bmiHeader.biHeight = (bi.bmiHeader.biHeight > 0) ? -bi.bmiHeader.biHeight : bi.bmiHeader.biHeight; diff --git a/core/renderer/Texture2D.cpp b/core/renderer/Texture2D.cpp index 601cfbc68f5..99c46e9f21b 100644 --- a/core/renderer/Texture2D.cpp +++ b/core/renderer/Texture2D.cpp @@ -549,7 +549,13 @@ bool Texture2D::initWithString(std::string_view text, const FontDefinition& text bool hasPremultipliedAlpha; Data outData = Device::getTextureDataForText(text, textDef, align, imageWidth, imageHeight, hasPremultipliedAlpha); if (outData.isNull()) + return false; + + const auto maxTextureSize = backend::DriverBase::getInstance()->getMaxTextureSize(); + if (imageWidth > maxTextureSize || imageHeight > maxTextureSize) { + AXLOGW("Texture2D::initWithString fail, the texture size:{}x{} too large, max texture size:{}", imageWidth, + imageHeight, maxTextureSize); return false; }