Skip to content

Commit

Permalink
Fix crash on Windows if gfx_directx_acknowledge_resize() fails
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Sep 29, 2015
1 parent 2413349 commit a824fcb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
13 changes: 6 additions & 7 deletions src/allegro/src/graphics.c
Expand Up @@ -621,22 +621,21 @@ int acknowledge_resize(void)
TRACE(PREFIX_I "acknowledge_resize init.\n");

if (gfx_driver->acknowledge_resize) {
BITMAP *new_screen;

/* Hide the mouse from current "screen" */
if (_mouse_installed)
if (screen && _mouse_installed)
show_mouse(NULL);

new_screen = gfx_driver->acknowledge_resize();
if (!new_screen) {
/* We've to change the global "screen" variable (even to NULL if
the resize fails) because gfx_driver->acknowledge_resize()
destroys the old screen pointer/video surfaces. */
screen = gfx_driver->acknowledge_resize();
if (!screen) {
TRACE(PREFIX_I "acknowledge_resize failed.\n");
return -1;
}

TRACE(PREFIX_I "acknowledge_resize succeeded.\n");

screen = new_screen;

if (_al_linker_mouse)
_al_linker_mouse->set_mouse_etc();

Expand Down
29 changes: 22 additions & 7 deletions src/allegro/src/win/wddwin.c
Expand Up @@ -779,7 +779,8 @@ static void gfx_directx_win_exit(struct BITMAP *bmp)
static BITMAP *gfx_directx_acknowledge_resize(void)
{
HWND allegro_wnd = win_get_window();
int color_depth = bitmap_color_depth(screen);
int color_depth = (screen ? bitmap_color_depth(screen):
desktop_color_depth());
int w, h;
RECT rc;
BITMAP *new_screen;
Expand All @@ -790,24 +791,38 @@ static BITMAP *gfx_directx_acknowledge_resize(void)
if (w % 4)
w -= (w % 4);

/* Copy current content in screen */
BITMAP* tmp = NULL;
if (screen)
tmp = create_bitmap_ex(color_depth, w, h);

_enter_gfx_critical();

/* Copy current content in screen */
BITMAP* tmp = create_bitmap_ex(color_depth, w, h);
clear_bitmap(tmp);
blit(gfx_directx_forefront_bitmap, tmp, 0, 0, 0, 0, w, h);
if (tmp) {
clear_bitmap(tmp);
blit(gfx_directx_forefront_bitmap, tmp, 0, 0, 0, 0, w, h);
}

/* Destroy old screen */
destroy_bitmap(gfx_directx_forefront_bitmap);
_destroy_directx_forefront_bitmap_extras();

/* Re-create the screen */
new_screen = _create_directx_forefront_bitmap(w, h, color_depth);
if (!new_screen) {
if (tmp)
destroy_bitmap(tmp);

_exit_gfx_critical();
return NULL;
}

/* Restore content in the new screen */
clear_bitmap(new_screen);
blit(tmp, new_screen, 0, 0, 0, 0, w, h);
destroy_bitmap(tmp);
if (tmp) {
blit(tmp, new_screen, 0, 0, 0, 0, w, h);
destroy_bitmap(tmp);
}

_exit_gfx_critical();

Expand Down
5 changes: 3 additions & 2 deletions src/she/alleg4/display_events.cpp
Expand Up @@ -65,9 +65,10 @@ void display_generate_events()

#ifdef ALLEGRO4_WITH_RESIZE_PATCH
if (resized) {
resized = false;
if (acknowledge_resize() < 0)
return;

acknowledge_resize();
resized = false;

Alleg4Display* display = unique_display;
if (display) {
Expand Down

0 comments on commit a824fcb

Please sign in to comment.