From 48c224f27a3f19f0b544955f367e714beb213481 Mon Sep 17 00:00:00 2001 From: yexo Date: Fri, 8 Jan 2010 19:14:33 +0000 Subject: [PATCH] (svn r18759) -Fix [NewGRF]: don't segfault when a newgrf contains an action2 and action3 but no action0 --- src/newgrf.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/newgrf.cpp b/src/newgrf.cpp index fd2e52e58f..04df38e333 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -3183,7 +3183,7 @@ static void StationMapSpriteGroup(byte *buf, uint8 idcount) if (ctype == CT_INVALID) continue; for (uint i = 0; i < idcount; i++) { - StationSpec *statspec = _cur_grffile->stations[stations[i]]; + StationSpec *statspec = _cur_grffile->stations == NULL ? NULL : _cur_grffile->stations[stations[i]]; if (statspec == NULL) { grfmsg(1, "StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stations[i]); @@ -3198,7 +3198,7 @@ static void StationMapSpriteGroup(byte *buf, uint8 idcount) if (!IsValidGroupID(groupid, "StationMapSpriteGroup")) return; for (uint i = 0; i < idcount; i++) { - StationSpec *statspec = _cur_grffile->stations[stations[i]]; + StationSpec *statspec = _cur_grffile->stations == NULL ? NULL : _cur_grffile->stations[stations[i]]; if (statspec == NULL) { grfmsg(1, "StationMapSpriteGroup: Station with ID 0x%02X does not exist, skipping", stations[i]); @@ -3227,6 +3227,11 @@ static void TownHouseMapSpriteGroup(byte *buf, uint8 idcount) uint16 groupid = grf_load_word(&buf); if (!IsValidGroupID(groupid, "TownHouseMapSpriteGroup")) return; + if (_cur_grffile->housespec == NULL) { + grfmsg(1, "TownHouseMapSpriteGroup: No houses defined, skipping"); + return; + } + for (uint i = 0; i < idcount; i++) { HouseSpec *hs = _cur_grffile->housespec[houses[i]]; @@ -3253,6 +3258,11 @@ static void IndustryMapSpriteGroup(byte *buf, uint8 idcount) uint16 groupid = grf_load_word(&buf); if (!IsValidGroupID(groupid, "IndustryMapSpriteGroup")) return; + if (_cur_grffile->industryspec == NULL) { + grfmsg(1, "IndustryMapSpriteGroup: No industries defined, skipping"); + return; + } + for (uint i = 0; i < idcount; i++) { IndustrySpec *indsp = _cur_grffile->industryspec[industries[i]]; @@ -3279,6 +3289,11 @@ static void IndustrytileMapSpriteGroup(byte *buf, uint8 idcount) uint16 groupid = grf_load_word(&buf); if (!IsValidGroupID(groupid, "IndustrytileMapSpriteGroup")) return; + if (_cur_grffile->indtspec == NULL) { + grfmsg(1, "IndustrytileMapSpriteGroup: No industry tiles defined, skipping"); + return; + } + for (uint i = 0; i < idcount; i++) { IndustryTileSpec *indtsp = _cur_grffile->indtspec[indtiles[i]];