You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a long text with label, cause random crash in windows,
the reason is the size over the limit of texture max size.
Sample code:
std::string str;
for (int i = 0; i < 30; i++) {
str+="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
}
Label* label = Label::create();
label->setFontSize(50);
label->setAnchorPoint(Vec2::ZERO);
label->setTextColor(Color4B::WHITE);
label->setPosition(0, 100);
label->enableWrap(false);
label->setString(str);
addChild(label);
it is better to do some protection in "Device::getTextureDataForText" inside the file:
platform/win32/Device-win32.cpp
platform/android/Device-android.cpp
platform/ios/Device-ios.mm
platform/mac/Device-mac.mm
platform/linux/Device-linux.cpp
protected sample:
Data Device::getTextureDataForText() {
SIZE size = {(LONG)textDefinition._dimensions.width, (LONG)textDefinition._dimensions.height};
AX_BREAK_IF(!dc.drawText(text, size, align, textDefinition._fontName.c_str(), (int)textDefinition._fontSize,
textDefinition._enableWrap, textDefinition._overflow));
auto driver = backend::DriverBase::getInstance(); //<<======== here
int maxSize = driver->getMaxTextureSize();
if (size.cx > maxSize || size.cy > maxSize) {
width = 0;
height = 0;
return ret;
}
}
othe platform is same as so on
i try to let it show normal if oversize, but i think it is bad idea. so i recommend just return false if failed.
auto driver = backend::DriverBase::getInstance();
int maxSize = driver->getMaxTextureSize();
std::string textCut = text.data();
while (size.cx > maxSize || size.cy > maxSize) { //test only code, don't used
float fCut = (float)maxSize / (float)size.cx; //bad
textCut = textCut.substr(0, (size_t)(text.length() * fCut)).data(); //bad
size = { (LONG)textDefinition._dimensions.width, (LONG)textDefinition._dimensions.height };
AX_BREAK_IF(!dc.drawText(textCut, size, align, textDefinition._fontName.c_str(), (int)textDefinition._fontSize,
textDefinition._enableWrap, textDefinition._overflow));
}
text = textCut;
The text was updated successfully, but these errors were encountered:
Create a long text with label, cause random crash in windows,
the reason is the size over the limit of texture max size.
Sample code:
it is better to do some protection in "Device::getTextureDataForText" inside the file:
platform/win32/Device-win32.cpp
platform/android/Device-android.cpp
platform/ios/Device-ios.mm
platform/mac/Device-mac.mm
platform/linux/Device-linux.cpp
protected sample:
Data Device::getTextureDataForText() {
}
othe platform is same as so on
i try to let it show normal if oversize, but i think it is bad idea. so i recommend just return false if failed.
The text was updated successfully, but these errors were encountered: