check the result of lzo1x_optimize
authorJonathan Marshall <jmarshall@never.you.mind>
Sun, 6 Jan 2013 02:24:42 +0000 (15:24 +1300)
committerS. Davilla <davilla@4pi.com>
Sun, 6 Jan 2013 13:36:21 +0000 (08:36 -0500)
tools/TexturePacker/XBMCTex.cpp

index 488e909..21404df 100644 (file)
@@ -210,8 +210,15 @@ CXBTFFrame appendContent(CXBTFWriter &writer, int width, int height, unsigned ch
       else
       { // success
         lzo_uint optimSize = size;
-        lzo1x_optimize(packed, packedSize, data, &optimSize, NULL);
-        writer.AppendContent(packed, packedSize);
+        if (lzo1x_optimize(packed, packedSize, data, &optimSize, NULL) != LZO_E_OK || optimSize != size)
+        { //optimisation failed
+          packedSize = size;
+          writer.AppendContent(data, size);
+        }
+        else
+        { // success
+          writer.AppendContent(packed, packedSize);
+        }
       }
       delete[] working;
       delete[] packed;