]> git.tdb.fi Git - gldbg.git/blobdiff - source/grabber.cpp
Fix several problems reported by valgrind
[gldbg.git] / source / grabber.cpp
index e56622f4d9949f21936358550a278d7a023e7cbd..c7f34ab92d8e002c59d66cca1bd45cc33b410b9a 100644 (file)
@@ -1,21 +1,14 @@
-/* $Id$
-
-This file is part of gldbg
-Copyright © 2011  Mikko Rasa, Mikkosoft Productions
-Distributed under the GPL
-*/
-
 #include <algorithm>
+#include <stdexcept>
 #include <png.h>
-#include <msp/io/print.h>
 #include "arraysize.h"
 #include "breakpoint.h"
 #include "functions.h"
 #include "gldbg.h"
 #include "grabber.h"
+#include "strformat.h"
 
 using namespace std;
-using namespace Msp;
 
 Grabber::Grabber(GlDbg &g):
        gldbg(g),
@@ -46,6 +39,11 @@ Grabber::Grabber(GlDbg &g):
        flavor_init();
 }
 
+Grabber::~Grabber()
+{
+       gldecoder_delete(decoder);
+}
+
 void Grabber::decode(const char *data, unsigned len)
 {
        gldecoder_decode(decoder, data, len);
@@ -124,7 +122,7 @@ void Grabber::cmd_autograb(const string &args)
                }
        }
        else
-               throw InvalidParameterValue("Invalid autograb mode");
+               throw runtime_error("Invalid autograb mode");
 }
 
 void Grabber::grab()
@@ -220,13 +218,13 @@ void Grabber::glReadPixels(void *user_data, int, int, int width, int height, GLe
 {
        Grabber *self = reinterpret_cast<Grabber *>(user_data);
        
-       string fn = Msp::format("grab-%04d-%04d.png", self->frame_num, self->grab_num);
+       string fn = strformat("grab-%04d-%04d.png", self->frame_num, self->grab_num);
        if(format==GL_RGBA && type==GL_UNSIGNED_BYTE)
        {
                if(self->write_png(fn, width, height, data)<0)
-                       IO::print("Failed to write png file %s\n", fn);
+                       printf("Failed to write png file %s\n", fn.c_str());
                else
-                       IO::print("Grabbed %dx%d png image to %s\n", width, height, fn);
+                       printf("Grabbed %dx%d png image to %s\n", width, height, fn.c_str());
        }
 
        ++self->grab_num;