From 83e376e7317a44af4585fa99747c58a9894a1437 Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Fri, 29 Nov 2019 15:06:42 +0100 Subject: [PATCH] Format remote printerr properly in script debugger output Fixes #33324 --- editor/script_editor_debugger.cpp | 25 +++++++++++++++++++++-- scene/debugger/script_debugger_remote.cpp | 17 ++++++++++++--- scene/debugger/script_debugger_remote.h | 12 ++++++++++- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp index 12219408941..73f18cbdf55 100644 --- a/editor/script_editor_debugger.cpp +++ b/editor/script_editor_debugger.cpp @@ -33,6 +33,7 @@ #include "core/io/marshalls.h" #include "core/project_settings.h" #include "core/ustring.h" +#include "editor/editor_log.h" #include "editor/plugins/canvas_item_editor_plugin.h" #include "editor/plugins/spatial_editor_plugin.h" #include "editor_log.h" @@ -43,6 +44,7 @@ #include "editor_settings.h" #include "main/performance.h" #include "property_editor.h" +#include "scene/debugger/script_debugger_remote.h" #include "scene/gui/dialogs.h" #include "scene/gui/label.h" #include "scene/gui/line_edit.h" @@ -822,8 +824,26 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da //OUT for (int i = 0; i < p_data.size(); i++) { + Array output = p_data[i]; + ERR_FAIL_COND_MSG(output.size() < 2, "Malformed output message from script debugger."); + + String str = output[0]; + ScriptDebuggerRemote::MessageType type = (ScriptDebuggerRemote::MessageType)(int)(output[1]); + + EditorLog::MessageType msg_type; + switch (type) { + case ScriptDebuggerRemote::MESSAGE_TYPE_LOG: { + msg_type = EditorLog::MSG_TYPE_STD; + } break; + case ScriptDebuggerRemote::MESSAGE_TYPE_ERROR: { + msg_type = EditorLog::MSG_TYPE_ERROR; + } break; + default: { + WARN_PRINTS("Unhandled script debugger message type: " + itos(type)); + msg_type = EditorLog::MSG_TYPE_STD; + } break; + } - String t = p_data[i]; //LOG if (!EditorNode::get_log()->is_visible()) { @@ -833,7 +853,8 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da } } } - EditorNode::get_log()->add_message(t); + + EditorNode::get_log()->add_message(str, msg_type); } } else if (p_msg == "performance") { diff --git a/scene/debugger/script_debugger_remote.cpp b/scene/debugger/script_debugger_remote.cpp index 628a30af1d5..fbe5e84f4b1 100644 --- a/scene/debugger/script_debugger_remote.cpp +++ b/scene/debugger/script_debugger_remote.cpp @@ -382,8 +382,14 @@ void ScriptDebuggerRemote::_get_output() { packet_peer_stream->put_var(output_strings.size()); while (output_strings.size()) { + const OutputString &output_string = output_strings.front()->get(); + + Array msg_data; + msg_data.push_back(output_string.message); + msg_data.push_back(output_string.type); + + packet_peer_stream->put_var(msg_data); - packet_peer_stream->put_var(output_strings.front()->get()); output_strings.pop_front(); } locking = false; @@ -1157,10 +1163,15 @@ void ScriptDebuggerRemote::_print_handler(void *p_this, const String &p_string, if (overflowed) s += "[...]"; - sdr->output_strings.push_back(s); + OutputString output_string; + output_string.message = s; + output_string.type = p_error ? MESSAGE_TYPE_ERROR : MESSAGE_TYPE_LOG; + sdr->output_strings.push_back(output_string); if (overflowed) { - sdr->output_strings.push_back("[output overflow, print less text!]"); + output_string.message = "[output overflow, print less text!]"; + output_string.type = MESSAGE_TYPE_ERROR; + sdr->output_strings.push_back(output_string); } } sdr->mutex->unlock(); diff --git a/scene/debugger/script_debugger_remote.h b/scene/debugger/script_debugger_remote.h index 2c0dccdaf79..c56166502e9 100644 --- a/scene/debugger/script_debugger_remote.h +++ b/scene/debugger/script_debugger_remote.h @@ -92,7 +92,12 @@ class ScriptDebuggerRemote : public ScriptDebugger { Array callstack; }; - List output_strings; + struct OutputString { + String message; + int type; + }; + + List output_strings; List messages; int max_messages_per_frame; int n_messages_dropped; @@ -151,6 +156,11 @@ class ScriptDebuggerRemote : public ScriptDebugger { bool skip_breakpoints; public: + enum MessageType { + MESSAGE_TYPE_LOG, + MESSAGE_TYPE_ERROR, + }; + struct ResourceUsage { String path;