mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 01:59:43 +01:00
Fix dereferencing NULL if image fails to load
If LoadImage() returned NULL, the game would dereference it and segfault. So I've added NULL checks to dereferencing the pointers.
This commit is contained in:
parent
8956b04d67
commit
9f11438dcc
1 changed files with 26 additions and 17 deletions
|
@ -306,15 +306,19 @@ void Graphics::updatetitlecolours(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PROCESS_TILESHEET_CHECK_ERROR(tilesheet, tile_square) \
|
#define PROCESS_TILESHEET_CHECK_ERROR(tilesheet, tile_square) \
|
||||||
if (grphx.im_##tilesheet->w % tile_square != 0 \
|
if (grphx.im_##tilesheet == NULL) \
|
||||||
|
{ \
|
||||||
|
/* We have already asserted; just no-op. */ \
|
||||||
|
} \
|
||||||
|
else if (grphx.im_##tilesheet->w % tile_square != 0 \
|
||||||
|| grphx.im_##tilesheet->h % tile_square != 0) \
|
|| grphx.im_##tilesheet->h % tile_square != 0) \
|
||||||
{ \
|
{ \
|
||||||
const char* error = "Error: %s.png dimensions not exact multiples of %i!"; \
|
const char* error = "Error: %s.png dimensions not exact multiples of %i!"; \
|
||||||
char message[128]; \
|
char message[128]; \
|
||||||
SDL_snprintf(message, sizeof(message), error, #tilesheet, tile_square); \
|
|
||||||
\
|
|
||||||
const char* error_title = "Error with %s.png"; \
|
const char* error_title = "Error with %s.png"; \
|
||||||
char message_title[128]; \
|
char message_title[128]; \
|
||||||
|
\
|
||||||
|
SDL_snprintf(message, sizeof(message), error, #tilesheet, tile_square); \
|
||||||
SDL_snprintf(message_title, sizeof(message_title), error_title, #tilesheet); \
|
SDL_snprintf(message_title, sizeof(message_title), error_title, #tilesheet); \
|
||||||
\
|
\
|
||||||
puts(message); \
|
puts(message); \
|
||||||
|
@ -332,9 +336,13 @@ void Graphics::updatetitlecolours(void)
|
||||||
#define PROCESS_TILESHEET_RENAME(tilesheet, vector, tile_square, extra_code) \
|
#define PROCESS_TILESHEET_RENAME(tilesheet, vector, tile_square, extra_code) \
|
||||||
PROCESS_TILESHEET_CHECK_ERROR(tilesheet, tile_square) \
|
PROCESS_TILESHEET_CHECK_ERROR(tilesheet, tile_square) \
|
||||||
\
|
\
|
||||||
for (int j = 0; j < grphx.im_##tilesheet->h / tile_square; j++) \
|
else \
|
||||||
{ \
|
{ \
|
||||||
for (int i = 0; i < grphx.im_##tilesheet->w / tile_square; i++) \
|
int j; \
|
||||||
|
for (j = 0; j < grphx.im_##tilesheet->h / tile_square; ++j) \
|
||||||
|
{ \
|
||||||
|
int i; \
|
||||||
|
for (i = 0; i < grphx.im_##tilesheet->w / tile_square; ++i) \
|
||||||
{ \
|
{ \
|
||||||
SDL_Surface* temp = GetSubSurface( \
|
SDL_Surface* temp = GetSubSurface( \
|
||||||
grphx.im_##tilesheet, \
|
grphx.im_##tilesheet, \
|
||||||
|
@ -348,7 +356,8 @@ void Graphics::updatetitlecolours(void)
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
SDL_FreeSurface(grphx.im_##tilesheet); \
|
SDL_FreeSurface(grphx.im_##tilesheet); \
|
||||||
grphx.im_##tilesheet = NULL;
|
grphx.im_##tilesheet = NULL; \
|
||||||
|
}
|
||||||
|
|
||||||
#define PROCESS_TILESHEET(tilesheet, tile_square, extra_code) \
|
#define PROCESS_TILESHEET(tilesheet, tile_square, extra_code) \
|
||||||
PROCESS_TILESHEET_RENAME(tilesheet, tilesheet, tile_square, extra_code)
|
PROCESS_TILESHEET_RENAME(tilesheet, tilesheet, tile_square, extra_code)
|
||||||
|
|
Loading…
Reference in a new issue