[aseprite] 104/250: Fix crash on Windows if gfx_directx_acknowledge_resize() fails

Tobias Hansen thansen at moszumanska.debian.org
Sun Dec 20 15:27:17 UTC 2015


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository aseprite.

commit a824fcb5e14e9302438879841cd188dbb8b701ed
Author: David Capello <davidcapello at gmail.com>
Date:   Tue Sep 29 13:58:12 2015 -0300

    Fix crash on Windows if gfx_directx_acknowledge_resize() fails
---
 src/allegro/src/graphics.c        | 13 ++++++-------
 src/allegro/src/win/wddwin.c      | 29 ++++++++++++++++++++++-------
 src/she/alleg4/display_events.cpp |  5 +++--
 3 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/src/allegro/src/graphics.c b/src/allegro/src/graphics.c
index 7f7cc5a..b20d362 100644
--- a/src/allegro/src/graphics.c
+++ b/src/allegro/src/graphics.c
@@ -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();
 
diff --git a/src/allegro/src/win/wddwin.c b/src/allegro/src/win/wddwin.c
index 3620fa3..50a619e 100644
--- a/src/allegro/src/win/wddwin.c
+++ b/src/allegro/src/win/wddwin.c
@@ -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;
@@ -790,12 +791,17 @@ 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);
@@ -803,11 +809,20 @@ static BITMAP *gfx_directx_acknowledge_resize(void)
 
    /* 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();
 
diff --git a/src/she/alleg4/display_events.cpp b/src/she/alleg4/display_events.cpp
index 8ee5de4..5b8d234 100644
--- a/src/she/alleg4/display_events.cpp
+++ b/src/she/alleg4/display_events.cpp
@@ -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) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git



More information about the Pkg-games-commits mailing list