Noise: Prevent unittest crash caused by division by zero
[oweals/minetest.git] / src / guiscalingfilter.cpp
index 33e0648ad3a5e7cc9225de1a9afffa3318403099..1b0dfac799d16ba967030af231a8e51e434effc4 100644 (file)
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "settings.h"
 #include "util/numeric.h"
 #include <stdio.h>
+#include "client/renderingengine.h"
 
 /* Maintain a static cache to store the images that correspond to textures
  * in a format that's manipulable by code.  Some platforms exhibit issues
@@ -48,18 +49,18 @@ void guiScalingCache(io::path key, video::IVideoDriver *driver, video::IImage *v
 }
 
 // Manually clear the cache, e.g. when switching to different worlds.
-void guiScalingCacheClear(video::IVideoDriver *driver)
+void guiScalingCacheClear()
 {
        for (std::map<io::path, video::IImage *>::iterator it = g_imgCache.begin();
-                       it != g_imgCache.end(); it++) {
-               if (it->second != NULL)
+                       it != g_imgCache.end(); ++it) {
+               if (it->second)
                        it->second->drop();
        }
        g_imgCache.clear();
        for (std::map<io::path, video::ITexture *>::iterator it = g_txrCache.begin();
-                       it != g_txrCache.end(); it++) {
-               if (it->second != NULL)
-                       driver->removeTexture(it->second);
+                       it != g_txrCache.end(); ++it) {
+               if (it->second)
+                       RenderingEngine::get_video_driver()->removeTexture(it->second);
        }
        g_txrCache.clear();
 }
@@ -72,7 +73,8 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver,
                video::ITexture *src, const core::rect<s32> &srcrect,
                const core::rect<s32> &destrect)
 {
-
+       if (src == NULL)
+               return src;
        if (!g_settings->getBool("gui_scaling_filter"))
                return src;
 
@@ -139,6 +141,8 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver,
 video::ITexture *guiScalingImageButton(video::IVideoDriver *driver,
                video::ITexture *src, s32 width, s32 height)
 {
+       if (src == NULL)
+               return src;
        return guiScalingResizeCached(driver, src,
                core::rect<s32>(0, 0, src->getSize().Width, src->getSize().Height),
                core::rect<s32>(0, 0, width, height));
@@ -154,6 +158,8 @@ void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
 {
        // Attempt to pre-scale image in software in high quality.
        video::ITexture *scaled = guiScalingResizeCached(driver, txr, srcrect, destrect);
+       if (scaled == NULL)
+               return;
 
        // Correct source rect based on scaled image.
        const core::rect<s32> mysrcrect = (scaled != txr)