From f3ea511c40c8a157010e170b75993cb1df4ff994 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 17 Sep 2010 04:59:32 +0000 Subject: [PATCH] - attempt to help poor kobe and his mad need to press E continuously - also cleanup a memory leak from code that was thus far unused --- source/glest_game/graphics/renderer.cpp | 28 +++++++++++++++++-- source/glest_game/graphics/renderer.h | 3 ++ source/shared_lib/sources/graphics/pixmap.cpp | 2 +- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 4297573bd..59154fa9f 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -155,6 +155,8 @@ Renderer::Renderer() { lastRenderFps=MIN_FPS_NORMAL_RENDERING; shadowsOffDueToMinRender=false; + pixmapScreenShot = NULL;; + //resources for(int i=0; i < rsCount; ++i) { modelManager[i] = NULL; @@ -208,6 +210,8 @@ Renderer::~Renderer(){ fontManager[i] = NULL; } + delete pixmapScreenShot; + this->menu = NULL; this->game = NULL; } @@ -2858,11 +2862,29 @@ void Renderer::saveScreen(const string &path){ const Metrics &sm= Metrics::getInstance(); - Pixmap2D pixmap(sm.getScreenW(), sm.getScreenH(), 3); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //Pixmap2D pixmap(sm.getScreenW(), sm.getScreenH(), 3); + if( pixmapScreenShot == NULL || + pixmapScreenShot->getW() != sm.getScreenW() || + pixmapScreenShot->getH() != sm.getScreenH()) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + delete pixmapScreenShot; + pixmapScreenShot = new Pixmap2D(sm.getScreenW(), sm.getScreenH(), 3); + } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); glFinish(); - glReadPixels(0, 0, pixmap.getW(), pixmap.getH(), GL_RGB, GL_UNSIGNED_BYTE, pixmap.getPixels()); - pixmap.saveTga(path); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + glReadPixels(0, 0, pixmapScreenShot->getW(), pixmapScreenShot->getH(), + GL_RGB, GL_UNSIGNED_BYTE, pixmapScreenShot->getPixels()); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + pixmapScreenShot->saveTga(path); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } // ==================== PRIVATE ==================== diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index c82b4d289..8289f23a1 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -240,6 +240,9 @@ private: bool shadowsOffDueToMinRender; bool useQuadCache; + + Pixmap2D *pixmapScreenShot; + private: Renderer(); ~Renderer(); diff --git a/source/shared_lib/sources/graphics/pixmap.cpp b/source/shared_lib/sources/graphics/pixmap.cpp index 6df3c457c..f76b5d129 100644 --- a/source/shared_lib/sources/graphics/pixmap.cpp +++ b/source/shared_lib/sources/graphics/pixmap.cpp @@ -725,7 +725,7 @@ void Pixmap2D::subCopy(int x, int y, const Pixmap2D *sourcePixmap){ } } - delete pixel; + delete [] pixel; } bool Pixmap2D::doDimensionsAgree(const Pixmap2D *pixmap){