Author: cazfi
Date: Wed Nov 11 18:46:01 2015
New Revision: 30547

URL: http://svn.gna.org/viewcvs/freeciv?rev=30547&view=rev
Log:
Fixed science report progress bar crash on sdl-clients when research not set.

See bug #24052

Modified:
    branches/S2_5/client/gui-sdl/repodlgs.c

Modified: branches/S2_5/client/gui-sdl/repodlgs.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-sdl/repodlgs.c?rev=30547&r1=30546&r2=30547&view=diff
==============================================================================
--- branches/S2_5/client/gui-sdl/repodlgs.c     (original)
+++ branches/S2_5/client/gui-sdl/repodlgs.c     Wed Nov 11 18:46:01 2015
@@ -2602,49 +2602,51 @@
     copy_chars_to_string16(pStr, cBuf);
     
     pSurf = create_text_surf_from_str16(pStr);
-    
+
     dest.x = pChangeResearchButton->size.x + pChangeResearchButton->size.w + 
adj_size(10);
-    
+
     alphablit(pSurf, NULL, pWindow->dst->surface, &dest);
 
     dest.y += pSurf->h + adj_size(4);
-    
+
     FREESURFACE(pSurf);
 
     /* progress bar */
-    dest.w = cost * pColb_Surface->w;
-    step = pColb_Surface->w;
-    if (dest.w > (area.w - dest.x - adj_size(16))) {
-      dest.w = (area.w - dest.x - adj_size(16));
-      step = ((area.w - dest.x - adj_size(16)) - pColb_Surface->w) / (cost - 
1);
-
-      if (step == 0) {
-        step = 1;
-      }
-    }
-
-    dest.h = pColb_Surface->h + adj_size(4);
-    SDL_FillRectAlpha(pWindow->dst->surface, &dest, &bg_color);
-  
-    putframe(pWindow->dst->surface,
-             dest.x - 1, dest.y - 1, dest.x + dest.w, dest.y + dest.h,
-             get_theme_color(COLOR_THEME_SCIENCEDLG_FRAME));
-  
-    if (cost > adj_size(286))
-    {
-      cost =
-        adj_size(286) * ((float) 
player_research_get(client.conn.playing)->bulbs_researched / cost);
-    }
-    else
-    {
-      cost =
-        (float)cost * 
((float)player_research_get(client.conn.playing)->bulbs_researched/cost);
-    }
-  
-    dest.y += adj_size(2);
-    for (i = 0; i < cost; i++) {
-      alphablit(pColb_Surface, NULL, pWindow->dst->surface, &dest);
-      dest.x += step;
+    if (cost > 0) {
+      dest.w = cost * pColb_Surface->w;
+      step = pColb_Surface->w;
+      if (dest.w > (area.w - dest.x - adj_size(16))) {
+        int cost_div_safe = cost - 1;
+
+        cost_div_safe = (cost_div_safe != 0 ? cost_div_safe : 1); 
+        dest.w = (area.w - dest.x - adj_size(16));
+        step = ((area.w - dest.x - adj_size(16)) - pColb_Surface->w) / 
cost_div_safe;
+
+        if (step == 0) {
+          step = 1;
+        }
+      }
+
+      dest.h = pColb_Surface->h + adj_size(4);
+      SDL_FillRectAlpha(pWindow->dst->surface, &dest, &bg_color);
+
+      putframe(pWindow->dst->surface,
+               dest.x - 1, dest.y - 1, dest.x + dest.w, dest.y + dest.h,
+               get_theme_color(COLOR_THEME_SCIENCEDLG_FRAME));
+
+      if (cost > adj_size(286)) {
+        cost =
+          adj_size(286) * ((float) 
player_research_get(client.conn.playing)->bulbs_researched / cost);
+      } else {
+        cost =
+          (float)cost * 
((float)player_research_get(client.conn.playing)->bulbs_researched/cost);
+      }
+
+      dest.y += adj_size(2);
+      for (i = 0; i < cost; i++) {
+        alphablit(pColb_Surface, NULL, pWindow->dst->surface, &dest);
+        dest.x += step;
+      }
     }
 
     /* improvement icons */


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to