Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2005:
[Freeciv-Dev] Re: (PR#14818) gui-sdl science dialog crash
Home

[Freeciv-Dev] Re: (PR#14818) gui-sdl science dialog crash

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#14818) gui-sdl science dialog crash
From: "Christian Prochaska" <cp.ml.freeciv.dev@xxxxxxxxxxxxxx>
Date: Sat, 10 Dec 2005 23:55:49 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=14818 >

On 12/10/05, Jason Short <jdorje@xxxxxxxxxxxxxxxxxxxxx> wrote:
>
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=14818 >
>
> When I press F6 gui-sdl crashes.
>
> #0  0x08162056 in popup_science_dialog (raise=true) at repodlgs.c:3220
> 3220          pLogo = adj_surf(GET_SURF(get_tech_sprite(tileset,
> get_player_research(game.player_ptr)->researching)));
> (gdb) bt
> #0  0x08162056 in popup_science_dialog (raise=true) at repodlgs.c:3220
> #1  0x08143337 in research_callback (pButton=0x8f88a40) at mapctrl.c:208
> #2  0x0812f70d in widget_pressed_action (pWidget=0x8f88a40) at
> gui_stuff.c:441
> #3  0x0812d3a1 in main_key_down_handler (Key=
>        {scancode = 72 'H', sym = SDLK_F6, mod = KMOD_NONE, unicode = 0},
>      pData=0x0) at gui_main.c:222
> #4  0x0812e3f1 in gui_event_loop (pData=0x0, loop_action=0,
>      key_down_handler=0x812d361 <main_key_down_handler>,
>      key_up_handler=0x812d5e4 <main_key_up_handler>,
>      mouse_button_down_handler=0x812d5ff <main_mouse_button_down_handler>,
>      mouse_button_up_handler=0x812d6b9 <main_mouse_button_up_handler>,
>      mouse_motion_handler=0x812d747 <main_mouse_motion_handler>)
>      at gui_main.c:735
> #5  0x0812eb3f in ui_main (argc=1, argv=0xbf9c0d94) at gui_main.c:1005
> #6  0x080501ce in main (argc=1, argv=0xbf9c0d94) at civclient.c:351
>
>
>

The reason was that the tech icons were not found (because they belong
to the tileset but were stored together with the theme files which are
now accessed separately) and the result of get_tech_sprite() was not
checked. The attached patch fixes this and I removed the tech icons
from the deluxe theme.

diff -urN -X devel/diff_ignore devel_distclean/client/gui-sdl/inteldlg.c 
devel/client/gui-sdl/inteldlg.c
--- devel_distclean/client/gui-sdl/inteldlg.c   2005-11-27 01:35:27.000000000 
+0100
+++ devel/client/gui-sdl/inteldlg.c     2005-12-10 23:33:46.000000000 +0100
@@ -34,6 +34,7 @@
 #include "gui_string.h"
 #include "gui_stuff.h"
 #include "mapview.h"
+#include "repodlgs.h"
 #include "spaceshipdlg.h"
 
 #include "inteldlg.h"
@@ -171,7 +172,7 @@
   h += MAX(pLogo->h + adj_size(20), pInfo->h + adj_size(20));
     
   /* ---------- */
-  col = w / (GET_SURF(get_tech_sprite(tileset, A_FIRST))->w + adj_size(4));
+  col = w / (get_tech_icon(A_FIRST)->w + adj_size(4));
   n = 0;
   pLast = pBuf;
   for(i = A_FIRST; i<game.control.num_tech_types; i++) {
@@ -179,7 +180,7 @@
       tech_is_available(game.player_ptr, i) &&
       get_invention(game.player_ptr, i) != TECH_KNOWN) {
       
-      pBuf = create_icon2(GET_SURF(get_tech_sprite(tileset, i)), pWindow->dst,
+      pBuf = create_icon2(get_tech_icon(i), pWindow->dst,
        (WF_DRAW_THEME_TRANSPARENT|WF_WIDGET_HAS_INFO_LABEL|WF_FREE_STRING));
       pBuf->action = tech_callback;
       set_wstate(pBuf, FC_WS_NORMAL);
diff -urN -X devel/diff_ignore devel_distclean/client/gui-sdl/repodlgs.c 
devel/client/gui-sdl/repodlgs.c
--- devel_distclean/client/gui-sdl/repodlgs.c   2005-11-27 01:35:27.000000000 
+0100
+++ devel/client/gui-sdl/repodlgs.c     2005-12-11 01:45:36.000000000 +0100
@@ -63,6 +63,7 @@
 #include "repodlgs.h"
 
 
+static SDL_Surface *pNeutral_Tech_Icon;
 static SDL_Surface *pNone_Tech_Icon;
 static SDL_Surface *pFuture_Tech_Icon;
 
@@ -2224,22 +2225,26 @@
 void setup_auxiliary_tech_icons(void)
 {
   SDL_Surface *pSurf;
+  SDL_Color color = {255, 255, 255, 255};
   SDL_String16 *pStr = create_str16_from_char(_("None"), adj_font(10));
   
   pStr->style |= (TTF_STYLE_BOLD | SF_CENTER);
     
   /* create icons */
-  pNone_Tech_Icon = create_surf(adj_size(50), adj_size(50), SDL_SWSURFACE);
-  SDL_FillRect(pNone_Tech_Icon, NULL,
-         SDL_MapRGB(pNone_Tech_Icon->format, 255 , 255 , 255));
-  putframe(pNone_Tech_Icon, 0 , 0,
-         pNone_Tech_Icon->w - 1, pNone_Tech_Icon->h - 1 , 0x0);
-  
-  pFuture_Tech_Icon = SDL_DisplayFormat(pNone_Tech_Icon);
+  pSurf = create_surf(adj_size(50), adj_size(50), SDL_SWSURFACE);
+  SDL_SetAlpha(pSurf, SDL_SRCALPHA, 136);
+    
+  SDL_FillRectAlpha(pSurf, NULL, &color);
+  putframe(pSurf, 0 , 0, pSurf->w - 1, pSurf->h - 1, 0x0);
+
+  pNeutral_Tech_Icon = SDL_DisplayFormatAlpha(pSurf);
+  pNone_Tech_Icon = SDL_DisplayFormatAlpha(pSurf);    
+  pFuture_Tech_Icon = SDL_DisplayFormatAlpha(pSurf);
   
+  FREESURFACE(pSurf);
+    
   /* None */
   pSurf = create_text_surf_from_str16(pStr);
-    
   blit_entire_src(pSurf, pNone_Tech_Icon ,
          (adj_size(50) - pSurf->w) / 2 , (adj_size(50) - pSurf->h) / 2);
   
@@ -2259,6 +2264,7 @@
 
 void free_auxiliary_tech_icons(void)
 {
+  FREESURFACE(pNeutral_Tech_Icon);
   FREESURFACE(pNone_Tech_Icon);
   FREESURFACE(pFuture_Tech_Icon);
 }
@@ -2275,7 +2281,11 @@
     case A_FUTURE:
       return pFuture_Tech_Icon;
     default:
-      return adj_surf(GET_SURF(get_tech_sprite(tileset, tech)));
+      if (get_tech_sprite(tileset, tech)) {
+        return adj_surf(GET_SURF(get_tech_sprite(tileset, tech)));
+      } else {
+        return pNeutral_Tech_Icon;
+      }
   }
   return NULL;
 }
@@ -3214,19 +3224,8 @@
     }
   }
 
-  if (get_player_research(game.player_ptr)->researching != A_UNSET)
-  {
-    if(get_player_research(game.player_ptr)->researching != A_FUTURE) {
-      pLogo = adj_surf(GET_SURF(get_tech_sprite(tileset, 
get_player_research(game.player_ptr)->researching)));
-  } else {
-    /* "Future Tech" icon */
-    pLogo = pFuture_Tech_Icon;
-  }
-  } else {
-    /* "None" icon */
-    pLogo = pNone_Tech_Icon;
-  }
-
+  pLogo = get_tech_icon(get_player_research(game.player_ptr)->researching);
+  
   pBuf = create_icon2(pLogo, pWindow->dst, WF_DRAW_THEME_TRANSPARENT);
 
   pBuf->action = change_research;
@@ -3240,13 +3239,7 @@
   add_to_gui_list(ID_SCIENCE_DLG_CHANGE_REASARCH_BUTTON, pBuf);
 
   /* ------ */
-  if (get_player_research(game.player_ptr)->tech_goal != A_UNSET)
-  {
-    pLogo = adj_surf(GET_SURF(get_tech_sprite(tileset, 
get_player_research(game.player_ptr)->tech_goal)));
-  } else {
-    /* "None" icon */
-    pLogo = pNone_Tech_Icon;
-  }
+  pLogo = get_tech_icon(get_player_research(game.player_ptr)->tech_goal);
   
   pBuf = create_icon2(pLogo, pWindow->dst, WF_DRAW_THEME_TRANSPARENT);
   pBuf->action = change_research_goal;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#14818) gui-sdl science dialog crash, Christian Prochaska <=