src/client/tile.cpp: Fix reference counting
authorBřetislav Štec <valsiterb@gmail.com>
Sun, 2 Aug 2015 16:42:03 +0000 (18:42 +0200)
committerest31 <MTest31@outlook.com>
Sun, 2 Aug 2015 17:26:15 +0000 (19:26 +0200)
src/client/tile.cpp

index 03badd8177fafff716f053b26c070e93eaf2a66c..79ed4a07210f44e49de1babccc039fc3765a6777 100644 (file)
@@ -1011,7 +1011,7 @@ video::IImage* TextureSource::generateImage(const std::string &name)
 
        std::string last_part_of_name = name.substr(last_separator_pos + 1);
 
-       /* 
+       /*
                If this name is enclosed in parentheses, generate it
                and blit it onto the base image
        */
@@ -1209,21 +1209,22 @@ bool TextureSource::generateImagePart(std::string part_of_name,
                        s32 frame_count = stoi(sf.next(":"));
                        s32 progression = stoi(sf.next(":"));
 
-                       /*
-                               Load crack image.
+                       if (progression >= 0) {
+                               /*
+                                       Load crack image.
 
-                               It is an image with a number of cracking stages
-                               horizontally tiled.
-                       */
-                       video::IImage *img_crack = m_sourcecache.getOrLoad(
+                                       It is an image with a number of cracking stages
+                                       horizontally tiled.
+                               */
+                               video::IImage *img_crack = m_sourcecache.getOrLoad(
                                        "crack_anylength.png", m_device);
 
-                       if (img_crack && progression >= 0)
-                       {
-                               draw_crack(img_crack, baseimg,
+                               if (img_crack) {
+                                       draw_crack(img_crack, baseimg,
                                                use_overlay, frame_count,
                                                progression, driver);
-                               img_crack->drop();
+                                       img_crack->drop();
+                               }
                        }
                }
                /*
@@ -1612,6 +1613,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
                        if (img) {
                                apply_mask(img, baseimg, v2s32(0, 0), v2s32(0, 0),
                                                img->getDimension());
+                               img->drop();
                        } else {
                                errorstream << "generateImage(): Failed to load \""
                                                << filename << "\".";