24 #ifdef DEBUG_SDL_SURFACES
34 PRAGMA48(GCC diagnostic ignored
"-Wshadow")
35 #include <SDL_image.h>
41 #define DEBUG_SURFACE_ALLOCATION 1
43 std::map<void*, SDLMemoryObject*> mSurfaces;
45 static SDL_Surface *addSurface(
const char *
restrict const name,
50 #ifdef DEBUG_SURFACE_ALLOCATION
51 logger->
log(
"add surface: %s %s:%u %p", name,
52 file, line,
static_cast<void*
>(surface));
55 std::map<void*, SDLMemoryObject*>::iterator
56 it = mSurfaces.find(surface);
57 if (it != mSurfaces.end())
59 SDLMemoryObject *
const obj = (*it).second;
62 #ifdef DEBUG_SURFACE_ALLOCATION
63 logger->
log(
"adding existing surface: %p, count:%d\n"
64 "was add %s\nwas deleted %s", surface, obj->mCnt,
65 obj->mAddFile.c_str(), obj->mRemoveFile.c_str());
73 mSurfaces[surface] =
new SDLMemoryObject(name, file, line);
83 #ifdef DEBUG_SURFACE_ALLOCATION
84 logger->
log(
"delete surface: %s %s:%u %p", name, file, line, surface);
87 std::map<void*, SDLMemoryObject*>::iterator
88 it = mSurfaces.find(surface);
89 if (it == mSurfaces.end())
91 logger->
log(
"bad surface delete: %p at %s:%d",
92 static_cast<void*
>(surface), file, line);
96 SDLMemoryObject *
const obj = (*it).second;
99 const int cnt = obj->mCnt;
100 #ifdef DEBUG_SURFACE_ALLOCATION
101 logger->
log(
"debug deleting surface: %p, count:%d\n"
102 "was add %s\nwas deleted %s", surface, cnt,
103 obj->mAddFile.c_str(), obj->mRemoveFile.c_str());
108 logger->
log(
"deleting already deleted surface: %p at %s:%d\n"
109 "was add %s\nwas deleted %s",
static_cast<void*
>(surface),
110 file, line, obj->mAddFile.c_str(),
111 obj->mRemoveFile.c_str());
115 mSurfaces.erase(surface);
121 obj->mRemoveFile =
strprintf(
"%s:%u", file, line);
127 SDL_Surface *FakeIMG_LoadPNG_RW(SDL_RWops *
const src,
const char *
const file,
130 return addSurface(
"IMG_LoadPNG_RW", IMG_LoadPNG_RW(src), file, line);
133 SDL_Surface *FakeIMG_LoadJPG_RW(SDL_RWops *
const src,
const char *
const file,
136 return addSurface(
"IMG_LoadJPG_RW", IMG_LoadJPG_RW(src), file, line);
139 SDL_Surface *FakeIMG_Load(
const char *name,
const char *
const file,
142 return addSurface(
"IMG_Load", IMG_Load(name), file, line);
145 void FakeSDL_FreeSurface(SDL_Surface *
const surface,
const char *
const file,
148 deleteSurface(
"SDL_FreeSurface", surface, file, line);
149 SDL_FreeSurface(surface);
152 SDL_Surface *FakeSDL_CreateRGBSurface(
const uint32_t flags,
153 const int width,
const int height,
155 const uint32_t rMask,
156 const uint32_t gMask,
157 const uint32_t bMask,
158 const uint32_t aMask,
159 const char *
const file,
162 return addSurface(
"SDL_CreateRGBSurface", SDL_CreateRGBSurface(flags,
163 width, height, depth, rMask, gMask, bMask, aMask), file, line);
166 SDL_Surface *FakeSDL_ConvertSurface(SDL_Surface *
const src,
167 SDL_PixelFormat *
const fmt,
168 const uint32_t flags,
169 const char *
const file,
172 return addSurface(
"SDL_ConvertSurface", SDL_ConvertSurface(
173 src, fmt, flags), file, line);
176 SDL_Surface *FakeTTF_RenderUTF8_Blended(_TTF_Font *
const font,
182 return addSurface(
"TTF_RenderUTF8_Blended", TTF_RenderUTF8_Blended(
183 font, text, fg), file, line);
186 SDL_Surface *FakeSDL_DisplayFormat(SDL_Surface *
const surface,
187 const char *
const file,
190 return addSurface(
"SDL_DisplayFormat",
191 SDL_DisplayFormat(surface), file, line);
194 SDL_Surface *FakeSDL_DisplayFormatAlpha(SDL_Surface *
const surface,
195 const char *
const file,
198 return addSurface(
"SDL_DisplayFormatAlpha",
199 SDL_DisplayFormatAlpha(surface), file, line);
void log(const char *const log_text,...)
std::string strprintf(const char *const format,...)