gdi: Fix crashing

This commit is contained in:
driver1998 2020-09-07 10:55:25 +08:00
parent 693162f080
commit fb00bf8602
2 changed files with 27 additions and 23 deletions

View File

@ -301,7 +301,7 @@ static bool gdi_gfx_frame(void *data, const void *frame,
unsigned frame_width, unsigned frame_height, uint64_t frame_count,
unsigned pitch, const char *msg, video_frame_info_t *video_info)
{
BITMAPINFO info;
BITMAPINFO* info = NULL;
unsigned mode_width = 0;
unsigned mode_height = 0;
const void *frame_to_copy = frame;
@ -410,22 +410,25 @@ static bool gdi_gfx_frame(void *data, const void *frame,
gdi->screen_width = mode_width;
gdi->screen_height = mode_height;
info.bmiColors[0].rgbBlue = 0;
info.bmiColors[0].rgbGreen = 0;
info.bmiColors[0].rgbRed = 0;
info.bmiColors[0].rgbReserved = 0;
info = malloc(sizeof(BITMAPINFO) + 3 * sizeof(DWORD));
if (!info) return false;
info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info.bmiHeader.biWidth = pitch / (bits / 8);
info.bmiHeader.biHeight = -height;
info.bmiHeader.biPlanes = 1;
info.bmiHeader.biBitCount = bits;
info.bmiHeader.biCompression = 0;
info.bmiHeader.biSizeImage = 0;
info.bmiHeader.biXPelsPerMeter= 0;
info.bmiHeader.biYPelsPerMeter= 0;
info.bmiHeader.biClrUsed = 0;
info.bmiHeader.biClrImportant = 0;
info->bmiColors[0].rgbBlue = 0;
info->bmiColors[0].rgbGreen = 0;
info->bmiColors[0].rgbRed = 0;
info->bmiColors[0].rgbReserved = 0;
info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info->bmiHeader.biWidth = pitch / (bits / 8);
info->bmiHeader.biHeight = -height;
info->bmiHeader.biPlanes = 1;
info->bmiHeader.biBitCount = bits;
info->bmiHeader.biCompression = 0;
info->bmiHeader.biSizeImage = 0;
info->bmiHeader.biXPelsPerMeter= 0;
info->bmiHeader.biYPelsPerMeter= 0;
info->bmiHeader.biClrUsed = 0;
info->bmiHeader.biClrImportant = 0;
if (bits == 16)
{
@ -445,13 +448,13 @@ static bool gdi_gfx_frame(void *data, const void *frame,
}
frame_to_copy = gdi->temp_buf;
info.bmiHeader.biCompression = BI_RGB;
info->bmiHeader.biCompression = BI_RGB;
}
else
{
unsigned *masks = (unsigned*)info.bmiColors;
DWORD* masks = (DWORD*)info->bmiColors;
info.bmiHeader.biCompression = BI_BITFIELDS;
info->bmiHeader.biCompression = BI_BITFIELDS;
/* default 16-bit format on Windows is XRGB1555 */
if (frame_to_copy == gdi->menu_frame)
@ -471,12 +474,13 @@ static bool gdi_gfx_frame(void *data, const void *frame,
}
}
else
info.bmiHeader.biCompression = BI_RGB;
info->bmiHeader.biCompression = BI_RGB;
if (draw)
StretchDIBits(gdi->memDC, 0, 0, width, height, 0, 0, width, height,
frame_to_copy, &info, DIB_RGB_COLORS, SRCCOPY);
frame_to_copy, info, DIB_RGB_COLORS, SRCCOPY);
free(info);
SelectObject(gdi->memDC, gdi->bmp_old);
if (msg)

View File

@ -2004,14 +2004,14 @@ bool gfx_animation_line_ticker_smooth(gfx_animation_ctx_line_ticker_smooth_t *li
glyph_width = font_driver_get_message_width(
line_ticker->font, "a", 1, line_ticker->font_scale);
if (glyph_width < 0)
if (glyph_width <= 0)
goto end;
/* > Height */
glyph_height = font_driver_get_line_height(
line_ticker->font, line_ticker->font_scale);
if (glyph_height < 0)
if (glyph_height <= 0)
goto end;
/* Determine line wrap parameters */