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