From 57726c7324f165c70671fc5b05d6c0964f56b870 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 28 Aug 2013 16:30:50 +0300 Subject: improve debug checkers. add missing surface functions for debugging. --- src/resources/image.cpp | 10 +++++----- src/resources/resource.cpp | 14 ++++++++++++++ src/resources/sdlimagehelper.cpp | 8 ++++---- src/resources/subimage.cpp | 8 ++++++++ 4 files changed, 31 insertions(+), 9 deletions(-) (limited to 'src/resources') diff --git a/src/resources/image.cpp b/src/resources/image.cpp index cd8231e7b..71c29ba53 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -69,7 +69,7 @@ Image::Image(SDL_Texture *const image, const int width, const int height) : mIsAlphaCalculated(false) { #ifdef DEBUG_IMAGES - logger->log("created: %p", this); + logger->log("created image: %p", this); #endif mBounds.x = 0; @@ -115,7 +115,7 @@ Image::Image(SDL_Surface *const image, const bool hasAlphaChannel0, mIsAlphaCalculated(false) { #ifdef DEBUG_IMAGES - logger->log("created: %p", static_cast(this)); + logger->log("created image: %p", static_cast(this)); #endif mBounds.x = 0; @@ -159,7 +159,7 @@ Image::Image(const GLuint glimage, const int width, const int height, mIsAlphaCalculated(false) { #ifdef DEBUG_IMAGES - logger->log("created: %p", static_cast(this)); + logger->log("created image: %p", static_cast(this)); #endif mBounds.x = 0; @@ -182,8 +182,8 @@ Image::Image(const GLuint glimage, const int width, const int height, Image::~Image() { #ifdef DEBUG_IMAGES - logger->log("delete: %p, %s, %s", static_cast(this), - mIdPath.c_str(), mSource.c_str()); + logger->log("delete image: %p", static_cast(this)); + logger->log(" %s, %s", mIdPath.c_str(), mSource.c_str()); #endif unload(); } diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp index b67fe644b..b12e2f511 100644 --- a/src/resources/resource.cpp +++ b/src/resources/resource.cpp @@ -35,11 +35,21 @@ Resource::~Resource() void Resource::incRef() { +#ifdef DEBUG_IMAGES + logger->log("before incRef for: %p", static_cast(this)); mRefCount++; + logger->log("after incRef: %p, %d", static_cast(this), mRefCount); +#else + mRefCount++; +#endif } void Resource::decRef() { +#ifdef DEBUG_IMAGES + logger->log("before decRef for: %p", static_cast(this)); +#endif + // Reference may not already have reached zero if (mRefCount == 0) { @@ -49,6 +59,10 @@ void Resource::decRef() mRefCount--; +#ifdef DEBUG_IMAGES + logger->log("after decRef: %p, %d", static_cast(this), mRefCount); +#endif + if (mRefCount == 0 && !mNotCount) { // Warn the manager that this resource is no longer used. diff --git a/src/resources/sdlimagehelper.cpp b/src/resources/sdlimagehelper.cpp index cf8d1d04a..e7d7bacd6 100644 --- a/src/resources/sdlimagehelper.cpp +++ b/src/resources/sdlimagehelper.cpp @@ -156,11 +156,11 @@ Image *SDLImageHelper::createTextSurface(SDL_Surface *const tmpImage, // Convert the surface to the current display format if (hasAlpha) { - image = SDL_DisplayFormatAlpha(tmpImage); + image = MSDL_DisplayFormatAlpha(tmpImage); } else { - image = SDL_DisplayFormat(tmpImage); + image = MSDL_DisplayFormat(tmpImage); // We also delete the alpha channel since // it's not used. @@ -252,11 +252,11 @@ Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage) const // Convert the surface to the current display format if (hasAlpha) { - image = SDL_DisplayFormatAlpha(tmpImage); + image = MSDL_DisplayFormatAlpha(tmpImage); } else { - image = SDL_DisplayFormat(tmpImage); + image = MSDL_DisplayFormat(tmpImage); // We also delete the alpha channel since // it's not used. diff --git a/src/resources/subimage.cpp b/src/resources/subimage.cpp index a13a885bb..d3dec55d5 100644 --- a/src/resources/subimage.cpp +++ b/src/resources/subimage.cpp @@ -185,6 +185,10 @@ SubImage::SubImage(Image *const parent, const GLuint image, SubImage::~SubImage() { +#ifdef DEBUG_IMAGES + logger->log("delete subimage: %p", static_cast(this)); + logger->log(" %s, %s", mIdPath.c_str(), mSource.c_str()); +#endif // Avoid destruction of the image mSDLSurface = nullptr; // Avoid possible destruction of its alpha channel @@ -198,6 +202,10 @@ SubImage::~SubImage() #endif if (mParent) { +#ifdef DEBUG_IMAGES + logger->log("decref from subminage: %p, parent: %p", + static_cast(this), static_cast(mParent)); +#endif mParent->decRef(); mParent = nullptr; } -- cgit v1.2.3-60-g2f50