From e4b72c0302dfae2859fa67f27c68047699995d57 Mon Sep 17 00:00:00 2001 From: Allanis Date: Fri, 30 Aug 2013 16:31:59 +0100 Subject: [PATCH] [Fix] Planets with 0 tech won't segfault anymore. :/ --- src/land.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/land.c b/src/land.c index 5b02c8d..c0b403c 100644 --- a/src/land.c +++ b/src/land.c @@ -567,6 +567,13 @@ static void shipyard_open(void) { /* Setup the ships to buy/sell. */ ships = ship_getTech(&nships, land_planet->tech, PLANET_TECH_MAX); + + if(nships <= 0) { + ships = malloc(sizeof(char*)); + ships[0] = strdup("None"); + nships = 1; + } + window_addList(secondary_wid, 20, 40, 200, SHIPYARD_HEIGHT-80, "lstShipyard", ships, nships, 0, shipyard_update); @@ -593,6 +600,23 @@ static void shipyard_update(char* str) { char buf[80], buf2[16], buf3[16]; shipname = toolkit_getList(secondary_wid, "lstShipyard"); + + /* No ships. */ + if(strcmp(shipname, "None")==0) { + window_modifyImage(secondary_wid, "imgTarget", NULL); + window_disableButton(secondary_wid, "btnBuyShip"); + window_disableButton(secondary_wid, "btnInfoShip"); + snprintf(buf, 80, + "None\n" + "NA\n" + "NA\n" + "\n" + "NA\n" + "NA\n"); + window_modifyText(secondary_wid, "txtDDesc", buf); + return; + } + ship = ship_get(shipname); if(player_nships()==0) window_disableButton(secondary_wid, "btnYourShips");