Prevent to decode png when the pixel buffer cannot be created
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / common / loader-png.cpp
index a84b205..8351aa7 100644 (file)
@@ -300,6 +300,18 @@ bool LoadBitmapFromPng(const Dali::ImageLoader::Input& input, Dali::Devel::Pixel
         break;
     }
   }
+
+  // decode the whole image into bitmap buffer
+  auto pixels = (bitmap = Dali::Devel::PixelBuffer::New(bufferWidth, bufferHeight, pixelFormat)).GetBuffer();
+
+  DALI_ASSERT_DEBUG(pixels);
+
+  if(!pixels)
+  {
+    DALI_LOG_ERROR("PixelBuffer couldn't be created\n");
+    return false;
+  }
+
   rows = reinterpret_cast<png_bytep*>(malloc(sizeof(png_bytep) * height));
   if(DALI_UNLIKELY(!rows))
   {
@@ -307,11 +319,6 @@ bool LoadBitmapFromPng(const Dali::ImageLoader::Input& input, Dali::Devel::Pixel
     return false;
   }
 
-  // decode the whole image into bitmap buffer
-  auto pixels = (bitmap = Dali::Devel::PixelBuffer::New(bufferWidth, bufferHeight, pixelFormat)).GetBuffer();
-
-  DALI_ASSERT_DEBUG(pixels);
-
   for(y = 0; y < height; y++)
   {
     rows[y] = pixels + y * stride;