Author: cazfi Date: Wed Nov 11 18:45:46 2015 New Revision: 30545 URL: http://svn.gna.org/viewcvs/freeciv?rev=30545&view=rev Log: Fixed science report progress bar crash on sdl-clients when research not set.
See bug #24052 Modified: trunk/client/gui-sdl2/repodlgs.c Modified: trunk/client/gui-sdl2/repodlgs.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/repodlgs.c?rev=30545&r1=30544&r2=30545&view=diff ============================================================================== --- trunk/client/gui-sdl2/repodlgs.c (original) +++ trunk/client/gui-sdl2/repodlgs.c Wed Nov 11 18:45:46 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