From cbbb35bf791964bf1d11caf3e25887d3ff5583e9 Mon Sep 17 00:00:00 2001 From: Ted John Date: Fri, 19 Jan 2018 12:46:13 +0000 Subject: [PATCH] Refactor memory handling in ObjectLoadError.cpp --- src/openrct2-ui/windows/ObjectLoadError.cpp | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/openrct2-ui/windows/ObjectLoadError.cpp b/src/openrct2-ui/windows/ObjectLoadError.cpp index ddf24e2a15..415c584fe4 100644 --- a/src/openrct2-ui/windows/ObjectLoadError.cpp +++ b/src/openrct2-ui/windows/ObjectLoadError.cpp @@ -14,13 +14,14 @@ *****************************************************************************/ #pragma endregion -#include - +#include +#include #include -#include #include #include #include +#include +#include enum WINDOW_OBJECT_LOAD_ERROR_WIDGET_IDX { WIDX_BACKGROUND, @@ -96,9 +97,9 @@ static rct_window_event_list window_object_load_error_events = { window_object_load_error_scrollpaint }; -static rct_object_entry * _invalid_entries = nullptr; +static std::vector _invalid_entries; static sint32 highlighted_index = -1; -static utf8 * file_path = nullptr; +static std::string file_path; /** * Returns an rct_string_id that represents an rct_object_entry's type. @@ -187,9 +188,7 @@ static void copy_object_names_to_clipboard(rct_window *w) rct_window * window_object_load_error_open(utf8 * path, size_t numMissingObjects, const rct_object_entry * missingObjects) { - size_t missingObjectsSize = numMissingObjects * sizeof(rct_object_entry); - _invalid_entries = Memory::AllocateArray(numMissingObjects); - memcpy(_invalid_entries, missingObjects, missingObjectsSize); + _invalid_entries = std::vector(missingObjects, missingObjects + numMissingObjects); // Check if window is already open rct_window * window = window_bring_to_front_by_class(WC_OBJECT_LOAD_ERROR); @@ -213,7 +212,7 @@ rct_window * window_object_load_error_open(utf8 * path, size_t numMissingObjects // Refresh list items and path window->no_list_items = (uint16)numMissingObjects; - file_path = strndup(path, strnlen(path, MAX_PATH)); + file_path = path; window_invalidate(window); return window; @@ -221,7 +220,8 @@ rct_window * window_object_load_error_open(utf8 * path, size_t numMissingObjects static void window_object_load_error_close(rct_window *w) { - SafeFree(_invalid_entries); + _invalid_entries.clear(); + _invalid_entries.shrink_to_fit(); } static void window_object_load_error_update(rct_window *w) @@ -303,7 +303,7 @@ static void window_object_load_error_paint(rct_window *w, rct_drawpixelinfo *dpi // Draw file name set_format_arg(0, rct_string_id, STR_OBJECT_ERROR_WINDOW_FILE); - set_format_arg(2, utf8*, file_path); + set_format_arg(2, utf8*, file_path.c_str()); gfx_draw_string_left_clipped(dpi, STR_BLACK_STRING, gCommonFormatArgs, COLOUR_BLACK, w->x + 5, w->y + 43, WW-5); }