diff --git a/Core/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp b/Core/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp index 2c358cbd1c5..698b9e2079f 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp @@ -647,6 +647,14 @@ Render2DSentenceClass::Allocate_New_Surface (const WCHAR *text, bool justCalcExt int char_height = Font->Get_Char_Height (); + // + // Validate char_height to prevent division by zero + // In rare cases with corrupted fonts, this can be 0 or negative + // + if (char_height <= 0) { + char_height = 1; // Use minimum safe value + } + // // Find the best texture size for the remaining text // @@ -1631,6 +1639,14 @@ FontCharsClass::Create_GDI_Font (const char *font_name) CharOverhang = 0; } + // + // Validate CharHeight to prevent division by zero + // In rare cases with corrupted fonts, tmHeight can be 0 or negative + // + if (CharHeight <= 0) { + CharHeight = 1; // Use minimum safe value + } + return GDIFont != NULL && GDIBitmap != NULL; }