Protect against Sources being null

This commit is contained in:
Gymnasiast 2018-07-30 22:01:04 +02:00
parent 8ff6831c57
commit edaebd5163
4 changed files with 11 additions and 3 deletions

View File

@ -1090,7 +1090,7 @@ static void window_editor_object_selection_paint(rct_window* w, rct_drawpixelinf
y += 12;
// Draw object source
stringId = object_manager_get_source_game_string(listItem->repositoryItem->Sources[0]);
stringId = object_manager_get_source_game_string(listItem->repositoryItem->GetFirstSourceGame());
gfx_draw_string_right(dpi, stringId, nullptr, COLOUR_WHITE, w->x + w->width - 5, y);
y += 12;

View File

@ -47,7 +47,7 @@ void BannerObject::ReadLegacy(IReadObjectContext* context, IStream* stream)
auto item = objectRepository.FindObject(identifier);
if (item != nullptr)
{
auto sourceGame = item->Sources[0];
auto sourceGame = item->GetFirstSourceGame();
if (sourceGame == OBJECT_SOURCE_WACKY_WORLDS
|| sourceGame == OBJECT_SOURCE_TIME_TWISTER
|| sourceGame == OBJECT_SOURCE_CUSTOM)

View File

@ -51,7 +51,7 @@ void FootpathItemObject::ReadLegacy(IReadObjectContext* context, IStream* stream
auto item = objectRepository.FindObject(identifier);
if (item != nullptr)
{
auto sourceGame = item->Sources[0];
auto sourceGame = item->GetFirstSourceGame();
if (sourceGame == OBJECT_SOURCE_WACKY_WORLDS || sourceGame == OBJECT_SOURCE_TIME_TWISTER
|| sourceGame == OBJECT_SOURCE_CUSTOM)
{

View File

@ -49,6 +49,14 @@ struct ObjectRepositoryItem
{
std::vector<rct_object_entry> Entries;
} SceneryGroupInfo;
OBJECT_SOURCE_GAME GetFirstSourceGame() const
{
if (Sources.empty())
return OBJECT_SOURCE_CUSTOM;
else
return (OBJECT_SOURCE_GAME)Sources[0];
}
};
interface IObjectRepository