Author: cazfi
Date: Wed Nov 11 18:45:53 2015
New Revision: 30546

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

See bug #24052

Modified:
    branches/S2_6/client/gui-sdl/repodlgs.c
    branches/S2_6/client/gui-sdl2/repodlgs.c

Modified: branches/S2_6/client/gui-sdl/repodlgs.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl/repodlgs.c?rev=30546&r1=30545&r2=30546&view=diff
==============================================================================
--- branches/S2_6/client/gui-sdl/repodlgs.c     (original)
+++ branches/S2_6/client/gui-sdl/repodlgs.c     Wed Nov 11 18:45:53 2015
@@ -2617,34 +2617,39 @@
     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) presearch->bulbs_researched / cost);
-    } else {
-      cost = (float) cost * ((float) presearch->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) presearch->bulbs_researched / cost);
+      } else {
+        cost = (float) cost * ((float) presearch->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 */

Modified: branches/S2_6/client/gui-sdl2/repodlgs.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-sdl2/repodlgs.c?rev=30546&r1=30545&r2=30546&view=diff
==============================================================================
--- branches/S2_6/client/gui-sdl2/repodlgs.c    (original)
+++ branches/S2_6/client/gui-sdl2/repodlgs.c    Wed Nov 11 18:45:53 2015
@@ -2669,34 +2669,39 @@
     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);
-    fill_rect_alpha(pWindow->dst->surface, &dest, &bg_color);
-
-    create_frame(pWindow->dst->surface,
-                 dest.x - 1, dest.y - 1, dest.w, dest.h,
-                 get_theme_color(COLOR_THEME_SCIENCEDLG_FRAME));
-
-    if (cost > adj_size(286)) {
-      cost = adj_size(286) * ((float) presearch->bulbs_researched / cost);
-    } else {
-      cost = (float) cost * ((float) presearch->bulbs_researched / cost);
-    }
-
-    dest.y += adj_size(2);
-    for (i = 0; i < cost; i++) {
-      alphablit(pColb_Surface, NULL, pWindow->dst->surface, &dest, 255);
-      dest.x += step;
+    if (cost > 0) {
+      int cost_div_safe = cost - 1;
+
+      cost_div_safe = (cost_div_safe != 0 ? cost_div_safe : 1);
+      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_div_safe;
+
+        if (step == 0) {
+          step = 1;
+        }
+      }
+
+      dest.h = pColb_Surface->h + adj_size(4);
+      fill_rect_alpha(pWindow->dst->surface, &dest, &bg_color);
+
+      create_frame(pWindow->dst->surface,
+                   dest.x - 1, dest.y - 1, dest.w, dest.h,
+                   get_theme_color(COLOR_THEME_SCIENCEDLG_FRAME));
+
+      if (cost > adj_size(286)) {
+        cost = adj_size(286) * ((float) presearch->bulbs_researched / cost);
+      } else {
+        cost = (float) cost * ((float) presearch->bulbs_researched / cost);
+      }
+
+      dest.y += adj_size(2);
+      for (i = 0; i < cost; i++) {
+        alphablit(pColb_Surface, NULL, pWindow->dst->surface, &dest, 255);
+        dest.x += step;
+      }
     }
 
     /* improvement icons */


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

Reply via email to