Browse Source

allow zero sized image

[email protected] 8 years ago
parent
commit
a215fada07
2 changed files with 13 additions and 8 deletions
  1. 6 4
      oxygine/src/oxygine/Image.cpp
  2. 7 4
      oxygine/src/oxygine/core/ImageDataOperations.cpp

+ 6 - 4
oxygine/src/oxygine/Image.cpp

@@ -749,9 +749,9 @@ namespace oxygine
     void Image::init(int w, int h, TextureFormat Format)
     {
         int bytesPerPixel = getBytesPerPixel(Format);
-
-        _buffer.resize(h * w * bytesPerPixel);
-        _image = ImageData(w, h, w * bytesPerPixel, Format, &_buffer.front());
+        int size = h * w * bytesPerPixel;
+        _buffer.resize(size);        
+        _image = ImageData(w, h, w * bytesPerPixel, Format, size ? &_buffer.front() : 0);
     }
 
 
@@ -790,7 +790,9 @@ namespace oxygine
 
         ImageData im = _image;
 
-        void* ptr = &_buffer.front() + rect.getX() * _image.bytespp + rect.getY() * _image.pitch + _offset;
+        void* ptr = 0;
+        if (!_buffer.empty())//zero size image
+            ptr = &_buffer.front() + rect.getX() * _image.bytespp + rect.getY() * _image.pitch + _offset;
 
         return ImageData(rect.getWidth(), rect.getHeight(), _image.pitch, _image.format, ptr);
     }

+ 7 - 4
oxygine/src/oxygine/core/ImageDataOperations.cpp

@@ -10,10 +10,13 @@ namespace oxygine
         {
             OX_ASSERT(dest.w == src.w);
             OX_ASSERT(dest.h == src.h);
-            OX_ASSERT(src.data);
-            OX_ASSERT(dest.data);
-            OX_ASSERT(src.pitch);
-            OX_ASSERT(dest.pitch);
+            if (src.w)
+            {
+                OX_ASSERT(src.data);
+                OX_ASSERT(dest.data);
+                OX_ASSERT(src.pitch);
+                OX_ASSERT(dest.pitch);
+            }            
             OX_ASSERT(src.bytespp);
             OX_ASSERT(dest.bytespp);
             if (dest.w != src.w ||