]> git.mxchange.org Git - simgear.git/blobdiff - simgear/screen/screen-dump.cxx
Fix some compiler warnings. size_t/int/unsigned conversions and extra ';'
[simgear.git] / simgear / screen / screen-dump.cxx
index 5ba9f9efa5142afae684d81e8e04dc6884484bf1..ff3e9b71eaa519b166dcf9746f65d9ef1dd0bd15 100644 (file)
@@ -65,21 +65,26 @@ bool sg_glWritePPMFile(const char *filename, GLubyte *buffer, int win_width, int
            for (k = 0; k < RGB3; k++)
                ibuffer[q++] = (unsigned char)
                    *(buffer + (pixelSize*((win_height-1-i)*win_width+j)+k));
-    fwrite(ibuffer, sizeof(unsigned char), RGB3*win_width*win_height, fp);
+    int written = fwrite(ibuffer, sizeof(unsigned char), RGB3*win_width*win_height, fp);
     fclose(fp);
     free(ibuffer);
 
+    if ( written != RGB3*win_width*win_height )
+    {
+        printf("Warning: failed to write %s. File truncated.\n", filename);
+        return false;
+    }
+
     printf("wrote file '%s' (%d x %d pixels, %d bytes)\n",
           filename, win_width, win_height, RGB3*win_width*win_height);
     return true;
 }
 
 
-// dump the screen buffer to a png file
+// dump the screen buffer to a png file, returns true on success
 bool sg_glDumpWindow(const char *filename, int win_width, int win_height) {
   osg::ref_ptr<osg::Image> img(new osg::Image);
   img->readPixels(0,0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE);
-  osgDB::writeImageFile(*img, filename);
-  return true;
+  return osgDB::writeImageFile(*img, filename);
 }