diff options
author | peter1138 <peter1138@openttd.org> | 2005-10-14 20:10:12 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2005-10-14 20:10:12 +0000 |
commit | e4f668fb4377f37eb7302e6e810c0fae3a44356a (patch) | |
tree | c81de7dc93f3edb134f00c849f31546908bac26e | |
parent | 8d4ed0840b751a5e13c0d68e8883423745e8bb85 (diff) | |
download | openttd-e4f668fb4377f37eb7302e6e810c0fae3a44356a.tar.xz |
(svn r3044) -NewGRF, Codechange: Improve handling of non-existent sprite sets.
-rw-r--r-- | newgrf.c | 29 | ||||
-rw-r--r-- | sprite.c | 10 |
2 files changed, 16 insertions, 23 deletions
@@ -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++; @@ -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); |