From 4090522901d319e7b0581ffc19e3db894507dc36 Mon Sep 17 00:00:00 2001 From: Ted John Date: Thu, 12 Jan 2017 22:11:31 +0000 Subject: [PATCH] Fix #4944: Game crashes upon selecting objects in scenario editor When the filter caused no results to be shown in the list, it would try to realloc for 0 bytes which returns NULL. The error shown in the console was a minor bug, the more serious issue was the the original memory was freed but the list pointer not updated. Instead just check for 0 items, dispose the list and return. --- src/openrct2/windows/editor_object_selection.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/openrct2/windows/editor_object_selection.c b/src/openrct2/windows/editor_object_selection.c index 99cdc57adc..80b7d521e2 100644 --- a/src/openrct2/windows/editor_object_selection.c +++ b/src/openrct2/windows/editor_object_selection.c @@ -390,6 +390,13 @@ static void visible_list_refresh(rct_window *w) } } + if (_numListItems == 0) + { + visible_list_dispose(); + window_invalidate(w); + return; + } + void *new_memory = realloc(_listItems, _numListItems * sizeof(list_item)); if (new_memory == NULL) { log_error("Unable to reallocate list items");