@@ -78,6 +78,7 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver,
7878{
7979 if (src == NULL )
8080 return src;
81+
8182 if (!g_settings->getBool (" gui_scaling_filter" ))
8283 return src;
8384
@@ -114,6 +115,14 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver,
114115
115116 // Create a new destination image and scale the source into it.
116117 imageCleanTransparent (srcimg, 0 );
118+
119+ if (destrect.getWidth () <= 0 || destrect.getHeight () <= 0 ) {
120+ errorstream << " Attempted to scale texture to invalid size " << scalename.c_str () << std::endl;
121+ // Avoid log spam by reusing and displaying the original texture
122+ src->grab ();
123+ g_txrCache[scalename] = src;
124+ return src;
125+ }
117126 video::IImage *destimg = driver->createImage (src->getColorFormat (),
118127 core::dimension2d<u32 >((u32 )destrect.getWidth (),
119128 (u32 )destrect.getHeight ()));
@@ -160,6 +169,10 @@ void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
160169 const core::rect<s32> *cliprect, const video::SColor *const colors,
161170 bool usealpha)
162171{
172+ // 9-sliced images might calculate negative texture dimensions. Skip them.
173+ if (destrect.getWidth () <= 0 || destrect.getHeight () <= 0 )
174+ return ;
175+
163176 // Attempt to pre-scale image in software in high quality.
164177 video::ITexture *scaled = guiScalingResizeCached (driver, txr, srcrect, destrect);
165178 if (scaled == NULL )
0 commit comments