forbid GFX2_Surfaces with 0 pixels
This commit is contained in:
parent
01c6a9cd09
commit
32f6cbfb5c
@ -28,22 +28,18 @@ T_GFX2_Surface * New_GFX2_Surface(word width, word height)
|
||||
T_GFX2_Surface * surface;
|
||||
size_t size;
|
||||
|
||||
size = width * height;
|
||||
if (size == 0) // surfaces with no pixels not allowed
|
||||
return NULL;
|
||||
|
||||
surface = malloc(sizeof(T_GFX2_Surface));
|
||||
if (surface == NULL)
|
||||
return NULL;
|
||||
size = width * height;
|
||||
if (size > 0)
|
||||
surface->pixels = malloc(size);
|
||||
if(surface->pixels == NULL)
|
||||
{
|
||||
surface->pixels = malloc(size);
|
||||
if(surface->pixels == NULL)
|
||||
{
|
||||
free(surface);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
surface->pixels = NULL;
|
||||
free(surface);
|
||||
return NULL;
|
||||
}
|
||||
memset(surface->palette, 0, sizeof(surface->palette));
|
||||
surface->w = width;
|
||||
|
||||
@ -722,6 +722,13 @@ byte *Render_text_SFont(const char *str, int font_number, int *width, int *heigh
|
||||
*width = SFont_TextWidth(font, str);
|
||||
|
||||
text_surface = New_GFX2_Surface(*width, *height);
|
||||
if (text_surface == NULL)
|
||||
{
|
||||
Warning("Failed to allocate text surface");
|
||||
SFont_FreeFont(font);
|
||||
Free_GFX2_Surface(font_surface);
|
||||
return NULL;
|
||||
}
|
||||
// Fill with transparent color
|
||||
memset(text_surface->pixels, font->Transparent, *width * *height);
|
||||
// Rendu du texte
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user