summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2005-10-14 20:10:12 +0000
committerpeter1138 <peter1138@openttd.org>2005-10-14 20:10:12 +0000
commit5c3625b88fba7d83173851f177c14309e3d54989 (patch)
treec81de7dc93f3edb134f00c849f31546908bac26e
parentf97d1274bc13b976aeec0d346f6dc06f3b4072c6 (diff)
downloadopenttd-5c3625b88fba7d83173851f177c14309e3d54989.tar.xz
(svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
-rw-r--r--newgrf.c29
-rw-r--r--sprite.c10
2 files changed, 16 insertions, 23 deletions
diff --git a/newgrf.c b/newgrf.c
index e0876c8ec..9ee9817ca 100644
--- a/newgrf.c
+++ b/newgrf.c
@@ -1404,14 +1404,10 @@ static void NewSpriteGroup(byte *buf, int len)
if (HASBIT(groupid, 15)) {
dg->ranges[i].group = NewCallBackResultSpriteGroup(groupid);
dg->ranges[i].group->ref_count++;
- } else if (groupid >= _cur_grffile->spritegroups_count) {
- /* This doesn't exist for us. */
- grf_load_word(&buf); // skip range
- i--; dg->num_ranges--;
- continue;
+ } else if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
+ grfmsg(GMS_WARN, "NewSpriteGroup(%02x:0x%x): Groupid %04x does not exist, leaving empty.", setid, numloaded, groupid);
+ dg->ranges[i].group = NULL;
} else {
- /* XXX: If multiple surreal sets attach a surreal
- * set this way, we are in trouble. */
dg->ranges[i].group = _cur_grffile->spritegroups[groupid];
dg->ranges[i].group->ref_count++;
}
@@ -1423,15 +1419,14 @@ static void NewSpriteGroup(byte *buf, int len)
groupid = grf_load_word(&buf);
if (HASBIT(groupid, 15)) {
dg->default_group = NewCallBackResultSpriteGroup(groupid);
- } else if (groupid >= _cur_grffile->spritegroups_count) {
- /* This spritegroup stinks. */
- free(dg->ranges), dg->ranges = NULL;
- grfmsg(GMS_WARN, "NewSpriteGroup(%02x:0x%x): Default groupid %04x is cargo callback or unknown, ignoring spritegroup.", setid, numloaded, groupid);
- return;
+ dg->default_group->ref_count++;
+ } else if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
+ grfmsg(GMS_WARN, "NewSpriteGroup(%02x:0x%x): Groupid %04x does not exist, leaving empty.", setid, numloaded, groupid);
+ dg->default_group = NULL;
} else {
dg->default_group = _cur_grffile->spritegroups[groupid];
- }
dg->default_group->ref_count++;
+ }
if (_cur_grffile->spritegroups[setid] != NULL)
UnloadSpriteGroup(&_cur_grffile->spritegroups[setid]);
@@ -1474,11 +1469,9 @@ static void NewSpriteGroup(byte *buf, int len)
if (HASBIT(groupid, 15)) {
rg->groups[i] = NewCallBackResultSpriteGroup(groupid);
rg->groups[i]->ref_count++;
- } else if (groupid >= _cur_grffile->spritegroups_count) {
- /* This doesn't exist for us. */
- i--;
- rg->num_groups--;
- continue;
+ } else if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
+ grfmsg(GMS_WARN, "NewSpriteGroup(%02x:0x%x): Groupid %04x does not exist, leaving empty.", setid, numloaded, groupid);
+ rg->groups[i] = NULL;
} else {
rg->groups[i] = _cur_grffile->spritegroups[groupid];
rg->groups[i]->ref_count++;
diff --git a/sprite.c b/sprite.c
index 28c430f32..2d76b7527 100644
--- a/sprite.c
+++ b/sprite.c
@@ -127,10 +127,10 @@ void UnloadSpriteGroup(SpriteGroup **group_ptr)
{
RealSpriteGroup *rsg = &group->g.real;
for (i = 0; i < rsg->loading_count; i++) {
- UnloadSpriteGroup(&rsg->loading[i]);
+ if (rsg->loading[i] != NULL) UnloadSpriteGroup(&rsg->loading[i]);
}
for (i = 0; i < rsg->loaded_count; i++) {
- UnloadSpriteGroup(&rsg->loaded[i]);
+ if (rsg->loaded[i] != NULL) UnloadSpriteGroup(&rsg->loaded[i]);
}
free(group);
return;
@@ -140,9 +140,9 @@ void UnloadSpriteGroup(SpriteGroup **group_ptr)
{
DeterministicSpriteGroup *dsg = &group->g.determ;
for (i = 0; i < group->g.determ.num_ranges; i++) {
- UnloadSpriteGroup(&dsg->ranges[i].group);
+ if (dsg->ranges[i].group != NULL) UnloadSpriteGroup(&dsg->ranges[i].group);
}
- UnloadSpriteGroup(&dsg->default_group);
+ if (dsg->default_group != NULL) UnloadSpriteGroup(&dsg->default_group);
free(group->g.determ.ranges);
free(group);
return;
@@ -151,7 +151,7 @@ void UnloadSpriteGroup(SpriteGroup **group_ptr)
case SGT_RANDOMIZED:
{
for (i = 0; i < group->g.random.num_groups; i++) {
- UnloadSpriteGroup(&group->g.random.groups[i]);
+ if (group->g.random.groups[i] != NULL) UnloadSpriteGroup(&group->g.random.groups[i]);
}
free(group->g.random.groups);
free(group);