From dca6acf1ca0fd30e14c40f13dfaf0120af41aff3 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Fri, 18 Sep 2020 05:13:12 +0200 Subject: [PATCH] [MIRROR] Fix runtime with ntos apps and improves code involved in the runtime (#854) * Fix runtime with NTOS apps and improve code involved (#53779) There exists a specific state where ui.open() can be called yet the result would be a null window and such behaviour would be intentional. The following CRASH in ui.send_asset() would thus be misleading, because send_asset() was called after open(). This PR adds more information to the CRASH about when the failure state can occur, makes open() return a value based on whether it actually opened a new pooled window or not, and makes sure modular computer apps don't send_assets unless a new pooled window was created. * Fix runtime with ntos apps and improves code involved in the runtime Co-authored-by: Timberpoes --- .../computers/item/computer_ui.dm | 4 ++-- .../modular_computers/file_system/program.dm | 4 ++-- code/modules/tgui/tgui.dm | 14 +++++++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/code/modules/modular_computers/computers/item/computer_ui.dm b/code/modules/modular_computers/computers/item/computer_ui.dm index f891ef4099a..f97c18a1414 100644 --- a/code/modules/modular_computers/computers/item/computer_ui.dm +++ b/code/modules/modular_computers/computers/item/computer_ui.dm @@ -37,8 +37,8 @@ if (!ui) ui = new(user, src, "NtosMain") ui.set_autoupdate(TRUE) - ui.open() - ui.send_asset(get_asset_datum(/datum/asset/simple/headers)) + if(ui.open()) + ui.send_asset(get_asset_datum(/datum/asset/simple/headers)) /obj/item/modular_computer/ui_data(mob/user) diff --git a/code/modules/modular_computers/file_system/program.dm b/code/modules/modular_computers/file_system/program.dm index afdd9a3db47..14898bcb6af 100644 --- a/code/modules/modular_computers/file_system/program.dm +++ b/code/modules/modular_computers/file_system/program.dm @@ -179,8 +179,8 @@ ui = SStgui.try_update_ui(user, src, ui) if(!ui && tgui_id) ui = new(user, src, tgui_id, filedesc) - ui.open() - ui.send_asset(get_asset_datum(/datum/asset/simple/headers)) + if(ui.open()) + ui.send_asset(get_asset_datum(/datum/asset/simple/headers)) // CONVENTIONS, READ THIS WHEN CREATING NEW PROGRAM AND OVERRIDING THIS PROC: // Topic calls are automagically forwarded from NanoModule this program contains. diff --git a/code/modules/tgui/tgui.dm b/code/modules/tgui/tgui.dm index cd425f6f5e4..7322c4179bb 100644 --- a/code/modules/tgui/tgui.dm +++ b/code/modules/tgui/tgui.dm @@ -67,18 +67,20 @@ * public * * Open this UI (and initialize it with data). + * + * return bool - TRUE if a new pooled window is opened, FALSE in all other situations including if a new pooled window didn't open because one already exists. */ /datum/tgui/proc/open() if(!user.client) - return null + return FALSE if(window) - return null + return FALSE process_status() if(status < UI_UPDATE) - return null + return FALSE window = SStgui.request_pooled_window(user) if(!window) - return null + return FALSE opened_at = world.time window.acquire_lock(src) if(!window.is_ready()) @@ -101,6 +103,8 @@ with_static_data = TRUE)) SStgui.on_open(src) + return TRUE + /** * public * @@ -156,7 +160,7 @@ */ /datum/tgui/proc/send_asset(datum/asset/asset) if(!window) - CRASH("send_asset() can only be called after open().") + CRASH("send_asset() was called either without calling open() first or when open() did not return TRUE.") return window.send_asset(asset) /**