From 042269953909d96811306c9b576bc686840343ec Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 3 Jul 2017 21:46:07 +0100 Subject: [PATCH] Fix #5381: Game crashes in editor when scenery or pathing is clicked Add more defensive checks for when there are no objects loaded. - Do not open footpath window if there are no footpath objects loaded. - Prevent crash in scenery window if no scenery groups loaded. --- distribution/changelog.txt | 1 + src/openrct2/windows/footpath.c | 39 ++++++++++++++++++++------------- src/openrct2/windows/scenery.c | 8 +++++-- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index c78cbdb008..1d577bdf37 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -115,6 +115,7 @@ - Fix: [#5003] Able to remove entrance/exit of unedittable rides (such as in Volcania). - Fix: [#5096] Failure to open parks with out of bounds sprite coordinates. - Fix: [#5114] Some entertainer costumes never select-able. +- Fix: [#5381] Game crashes in scenario editor when scenery or pathing is clicked on when no objects loaded. 0.0.5 (2016-12-27) ------------------------------------------------------------------------ diff --git a/src/openrct2/windows/footpath.c b/src/openrct2/windows/footpath.c index c9029906f7..f61022b2b8 100644 --- a/src/openrct2/windows/footpath.c +++ b/src/openrct2/windows/footpath.c @@ -204,7 +204,7 @@ static void window_footpath_construct(); static void window_footpath_remove(); static void window_footpath_set_enabled_and_pressed_widgets(); static void footpath_get_next_path_info(sint32 *type, sint32 *x, sint32 *y, sint32 *z, sint32 *slope); -static void footpath_select_default(); +static bool footpath_select_default(); /** * @@ -212,6 +212,20 @@ static void footpath_select_default(); */ void window_footpath_open() { + // If a restricted path was selected when the game is no longer in Sandbox mode, reset it + rct_footpath_entry *pathEntry = get_footpath_entry(gFootpathSelectedId); + if (pathEntry != (rct_footpath_entry*)-1 && (pathEntry->flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR) && !gCheatsSandboxMode) { + pathEntry = (rct_footpath_entry*)-1; + } + + // Select the default path if we don't have one + if (pathEntry == (rct_footpath_entry*)-1) { + if (!footpath_select_default()) { + // No path objects to select from, don't open window + return; + } + } + // Check if window is already open rct_window *window = window_bring_to_front_by_class(WC_FOOTPATH); if (window != NULL) @@ -247,17 +261,6 @@ void window_footpath_open() window_push_others_right(window); show_gridlines(); - // If a restricted path was selected when the game is no longer in Sandbox mode, reset it - rct_footpath_entry *pathEntry = get_footpath_entry(gFootpathSelectedId); - if (pathEntry != (rct_footpath_entry*)-1 && (pathEntry->flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR) && !gCheatsSandboxMode) { - pathEntry = (rct_footpath_entry*)-1; - } - - // Select the default path if we don't have one - if (pathEntry == (rct_footpath_entry*)-1) { - footpath_select_default(); - } - tool_cancel(); gFootpathConstructionMode = PATH_CONSTRUCTION_MODE_LAND; tool_set(window, WIDX_CONSTRUCT_ON_LAND, TOOL_PATH_DOWN); @@ -1145,14 +1148,14 @@ static void footpath_get_next_path_info(sint32 *type, sint32 *x, sint32 *y, sint } } -static void footpath_select_default() +static bool footpath_select_default() { // Select first available footpath - gFootpathSelectedId = 0; + sint32 footpathId = -1; for (sint32 i = 0; i < object_entry_group_counts[OBJECT_TYPE_PATHS]; i++) { rct_footpath_entry *pathEntry = get_footpath_entry(i); if (pathEntry != (rct_footpath_entry*)-1) { - gFootpathSelectedId = i; + footpathId = i; // Prioritise non-restricted path if (!(pathEntry->flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR)) { @@ -1160,4 +1163,10 @@ static void footpath_select_default() } } } + if (footpathId == -1) { + return false; + } else { + gFootpathSelectedId = footpathId; + return true; + } } diff --git a/src/openrct2/windows/scenery.c b/src/openrct2/windows/scenery.c index babef050bd..6bdb3be63d 100644 --- a/src/openrct2/windows/scenery.c +++ b/src/openrct2/windows/scenery.c @@ -907,8 +907,12 @@ void window_scenery_invalidate(rct_window *w) { uint16 tabIndex = gWindowSceneryActiveTabIndex; uint32 titleStringId = STR_MISCELLANEOUS; - if (tabIndex < 19) - titleStringId = get_scenery_group_entry(tabIndex)->name; + if (tabIndex < 19) { + rct_scenery_set_entry * sgEntry = get_scenery_group_entry(tabIndex); + if (sgEntry != NULL && sgEntry != (rct_scenery_set_entry *)-1) { + titleStringId = sgEntry->name; + } + } window_scenery_widgets[WIDX_SCENERY_TITLE].text = titleStringId;