From 39e6d4f2b559a0542dadd650e2f214ac0b0d16b5 Mon Sep 17 00:00:00 2001 From: wrenczes Date: Mon, 27 Dec 2010 20:00:33 +0000 Subject: [PATCH] Reworked some fixes submitted to us by ittobaal. Several fclose calls he suggested had no bearing (if fopen fails, calling fclose on a null pointer is pointless), but the (missing) array deletions were definitely valid bugs. The fix for CreateTexture() was a little loose, so I cleaned it up somewhat. Issue: 566 --- JGE/src/JDistortionMesh.cpp | 2 +- JGE/src/JGBKFont.cpp | 4 +-- JGE/src/JGfx.cpp | 6 +++- JGE/src/pc/JGfx.cpp | 72 ++++++++++++++++++++----------------- 4 files changed, 47 insertions(+), 37 deletions(-) diff --git a/JGE/src/JDistortionMesh.cpp b/JGE/src/JDistortionMesh.cpp index 7b9a6993f..2c3433d26 100644 --- a/JGE/src/JDistortionMesh.cpp +++ b/JGE/src/JDistortionMesh.cpp @@ -53,7 +53,7 @@ JDistortionMesh::~JDistortionMesh() { delete mQuad; - delete mVertices; + delete[] mVertices; // JGERelease(); } diff --git a/JGE/src/JGBKFont.cpp b/JGE/src/JGBKFont.cpp index 7063e0ef4..c22914513 100644 --- a/JGE/src/JGBKFont.cpp +++ b/JGE/src/JGBKFont.cpp @@ -44,9 +44,9 @@ JGBKFont::JGBKFont() JGBKFont::~JGBKFont() { - SAFE_DELETE(mEngFont); + SAFE_DELETE_ARRAY(mEngFont); - SAFE_DELETE(mChnFont); + SAFE_DELETE_ARRAY(mChnFont); SAFE_DELETE(mTexture); diff --git a/JGE/src/JGfx.cpp b/JGE/src/JGfx.cpp index 6cc16bab4..b2ec1606b 100644 --- a/JGE/src/JGfx.cpp +++ b/JGE/src/JGfx.cpp @@ -800,7 +800,11 @@ void JRenderer::ScreenShot(const char* filename) fp = fopen(filename, "wb"); if (!fp) return; png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (!png_ptr) return; + if (!png_ptr) + { + fclose(fp); + return; + } info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_write_struct(&png_ptr, (png_infopp)NULL); diff --git a/JGE/src/pc/JGfx.cpp b/JGE/src/pc/JGfx.cpp index d4281e42b..db89e1284 100644 --- a/JGE/src/pc/JGfx.cpp +++ b/JGE/src/pc/JGfx.cpp @@ -2198,41 +2198,47 @@ void JRenderer::TransferTextureToGLContext(JTexture& inTexture) JTexture* JRenderer::CreateTexture(int width, int height, int mode __attribute__((unused))) { - checkGlError(); - int size = width * height * sizeof(PIXEL_TYPE); // RGBA - - BYTE* buffer = new BYTE[size]; - - JTexture *tex = new JTexture(); - - if (buffer && tex) - { - tex->mFilter = TEX_FILTER_LINEAR; - tex->mWidth = width; - tex->mHeight = height; - tex->mTexWidth = width; - tex->mTexHeight = height; - - GLuint texid; - glGenTextures(1, &texid); - tex->mTexId = texid; - - memset(buffer, 0, size); - - mCurrentTex = texid; - glBindTexture(GL_TEXTURE_2D, mCurrentTex); - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); - - delete[] buffer; - checkGlError(); + JTexture *tex = new JTexture(); + + if (tex) + { + int size = width * height * sizeof(PIXEL_TYPE); // RGBA + BYTE* buffer = new BYTE[size]; + if (buffer) + { + tex->mFilter = TEX_FILTER_LINEAR; + tex->mWidth = width; + tex->mHeight = height; + tex->mTexWidth = width; + tex->mTexHeight = height; + + GLuint texid; + glGenTextures(1, &texid); + tex->mTexId = texid; + + memset(buffer, 0, size); + + mCurrentTex = texid; + glBindTexture(GL_TEXTURE_2D, mCurrentTex); + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + + delete[] buffer; + + checkGlError(); + + } + else + { + delete tex; + tex = NULL; + } + } + return tex; - } - else - return NULL; }