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.
This commit is contained in:
Ted John 2017-07-03 21:46:07 +01:00
parent 1442b43898
commit 0422699539
3 changed files with 31 additions and 17 deletions

View File

@ -115,6 +115,7 @@
- Fix: [#5003] Able to remove entrance/exit of unedittable rides (such as in Volcania). - 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: [#5096] Failure to open parks with out of bounds sprite coordinates.
- Fix: [#5114] Some entertainer costumes never select-able. - 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) 0.0.5 (2016-12-27)
------------------------------------------------------------------------ ------------------------------------------------------------------------

View File

@ -204,7 +204,7 @@ static void window_footpath_construct();
static void window_footpath_remove(); static void window_footpath_remove();
static void window_footpath_set_enabled_and_pressed_widgets(); 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_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() 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 // Check if window is already open
rct_window *window = window_bring_to_front_by_class(WC_FOOTPATH); rct_window *window = window_bring_to_front_by_class(WC_FOOTPATH);
if (window != NULL) if (window != NULL)
@ -247,17 +261,6 @@ void window_footpath_open()
window_push_others_right(window); window_push_others_right(window);
show_gridlines(); 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(); tool_cancel();
gFootpathConstructionMode = PATH_CONSTRUCTION_MODE_LAND; gFootpathConstructionMode = PATH_CONSTRUCTION_MODE_LAND;
tool_set(window, WIDX_CONSTRUCT_ON_LAND, TOOL_PATH_DOWN); 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 // Select first available footpath
gFootpathSelectedId = 0; sint32 footpathId = -1;
for (sint32 i = 0; i < object_entry_group_counts[OBJECT_TYPE_PATHS]; i++) { for (sint32 i = 0; i < object_entry_group_counts[OBJECT_TYPE_PATHS]; i++) {
rct_footpath_entry *pathEntry = get_footpath_entry(i); rct_footpath_entry *pathEntry = get_footpath_entry(i);
if (pathEntry != (rct_footpath_entry*)-1) { if (pathEntry != (rct_footpath_entry*)-1) {
gFootpathSelectedId = i; footpathId = i;
// Prioritise non-restricted path // Prioritise non-restricted path
if (!(pathEntry->flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR)) { 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;
}
} }

View File

@ -907,8 +907,12 @@ void window_scenery_invalidate(rct_window *w)
{ {
uint16 tabIndex = gWindowSceneryActiveTabIndex; uint16 tabIndex = gWindowSceneryActiveTabIndex;
uint32 titleStringId = STR_MISCELLANEOUS; uint32 titleStringId = STR_MISCELLANEOUS;
if (tabIndex < 19) if (tabIndex < 19) {
titleStringId = get_scenery_group_entry(tabIndex)->name; 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; window_scenery_widgets[WIDX_SCENERY_TITLE].text = titleStringId;