diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-08-28 16:30:50 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-08-29 00:18:56 +0300 |
commit | 57726c7324f165c70671fc5b05d6c0964f56b870 (patch) | |
tree | 8a9f37914c18f9c6ec6d64da08834af245afe0f3 | |
parent | ee1a05faf157c8c9f0f43cf5b906d84f39ded497 (diff) | |
download | manaverse-57726c7324f165c70671fc5b05d6c0964f56b870.tar.gz manaverse-57726c7324f165c70671fc5b05d6c0964f56b870.tar.bz2 manaverse-57726c7324f165c70671fc5b05d6c0964f56b870.tar.xz manaverse-57726c7324f165c70671fc5b05d6c0964f56b870.zip |
improve debug checkers.
add missing surface functions for debugging.
-rw-r--r-- | src/debug.h | 6 | ||||
-rw-r--r-- | src/resources/image.cpp | 10 | ||||
-rw-r--r-- | src/resources/resource.cpp | 14 | ||||
-rw-r--r-- | src/resources/sdlimagehelper.cpp | 8 | ||||
-rw-r--r-- | src/resources/subimage.cpp | 8 | ||||
-rw-r--r-- | src/utils/sdlcheckutils.cpp | 16 | ||||
-rw-r--r-- | src/utils/sdlcheckutils.h | 8 |
7 files changed, 61 insertions, 9 deletions
diff --git a/src/debug.h b/src/debug.h index a250aef68..079cebeac 100644 --- a/src/debug.h +++ b/src/debug.h @@ -52,6 +52,10 @@ #define MTTF_RenderUTF8_Blended(font, text, fg) \ FakeTTF_RenderUTF8_Blended(font, text, fg, __FILE__, __LINE__) #define MIMG_Load(file) FakeIMG_Load(file, __FILE__, __LINE__) +#define MSDL_DisplayFormatAlpha(surface) \ + FakeSDL_DisplayFormatAlpha(surface, __FILE__, __LINE__) +#define MSDL_DisplayFormat(surface) \ + FakeSDL_DisplayFormat(surface, __FILE__, __LINE__) #else @@ -64,5 +68,7 @@ #define MTTF_RenderUTF8_Blended(font, text, fg) \ TTF_RenderUTF8_Blended(font, text, fg) #define MIMG_Load(file) IMG_Load(file) +#define MSDL_DisplayFormatAlpha(surface) SDL_DisplayFormatAlpha(surface) +#define MSDL_DisplayFormat(surface) SDL_DisplayFormat(surface) #endif // ENABLE_SDL_DEBUG 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<void*>(this)); + logger->log("created image: %p", static_cast<void*>(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<void*>(this)); + logger->log("created image: %p", static_cast<void*>(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<void*>(this), - mIdPath.c_str(), mSource.c_str()); + logger->log("delete image: %p", static_cast<void*>(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<void*>(this)); mRefCount++; + logger->log("after incRef: %p, %d", static_cast<void*>(this), mRefCount); +#else + mRefCount++; +#endif } void Resource::decRef() { +#ifdef DEBUG_IMAGES + logger->log("before decRef for: %p", static_cast<void*>(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<void*>(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<void*>(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<void*>(this), static_cast<void*>(mParent)); +#endif mParent->decRef(); mParent = nullptr; } diff --git a/src/utils/sdlcheckutils.cpp b/src/utils/sdlcheckutils.cpp index 755f9553a..ee2f41b77 100644 --- a/src/utils/sdlcheckutils.cpp +++ b/src/utils/sdlcheckutils.cpp @@ -184,4 +184,20 @@ SDL_Surface *FakeTTF_RenderUTF8_Blended(_TTF_Font *const font, font, text, fg), file, line); } +SDL_Surface *FakeSDL_DisplayFormat(SDL_Surface *const surface, + const char *const file, + const unsigned line) +{ + return addSurface("SDL_DisplayFormat", + SDL_DisplayFormat(surface), file, line); +} + +SDL_Surface *FakeSDL_DisplayFormatAlpha(SDL_Surface *const surface, + const char *const file, + const unsigned line) +{ + return addSurface("SDL_DisplayFormatAlpha", + SDL_DisplayFormatAlpha(surface), file, line); +} + #endif // DEBUG_SDL_SURFACES diff --git a/src/utils/sdlcheckutils.h b/src/utils/sdlcheckutils.h index 5a29ab1ba..5bfdad3ed 100644 --- a/src/utils/sdlcheckutils.h +++ b/src/utils/sdlcheckutils.h @@ -63,5 +63,13 @@ SDL_Surface *FakeTTF_RenderUTF8_Blended(_TTF_Font *const font, SDL_Surface *FakeIMG_Load(const char *name, const char *const file, const unsigned line); +SDL_Surface *FakeSDL_DisplayFormat(SDL_Surface *const surface, + const char *const file, + const unsigned line); + +SDL_Surface *FakeSDL_DisplayFormatAlpha(SDL_Surface *const surface, + const char *const file, + const unsigned line); + #endif // DEBUG_SDL_SURFACES #endif // UTILS_SDLCHECKUTILS_H |