AGS: Fixed sending non-error messages to debugger

From upstream 3b43353986ca91ecad9c5270e362c8716effaf37
This commit is contained in:
Paul Gilbert 2022-05-04 22:45:21 -07:00
parent 540a92a6c5
commit faa858a55b
3 changed files with 11 additions and 19 deletions

View File

@ -22,13 +22,6 @@
#include "ags/lib/std/memory.h"
#include "ags/lib/std/limits.h"
#include "ags/shared/core/platform.h"
#if AGS_PLATFORM_OS_WINDOWS
#define NOMINMAX
#define BITMAP WINDOWS_BITMAP
//include <windows.h>
#undef BITMAP
#endif
//include <SDL.h>
#include "ags/lib/std/initializer_list.h"
#include "ags/shared/ac/common.h"
#include "ags/shared/ac/game_setup_struct.h"
@ -321,23 +314,24 @@ struct Breakpoint {
};
bool send_message_to_editor(const char *msg, const char *errorMsg) {
String callStack = cc_get_error().CallStack;
// Get either saved callstack from a script error, or current execution point
String callStack = (errorMsg && cc_has_error()) ?
cc_get_error().CallStack : cc_get_callstack();
if (callStack.IsEmpty())
return false;
char messageToSend[STD_BUFFER_SIZE];
sprintf(messageToSend, "<?xml version=\"1.0\" encoding=\"Windows-1252\"?><Debugger Command=\"%s\">", msg);
String message;
message.AppendFmt("<?xml version=\"1.0\" encoding=\"Windows-1252\"?><Debugger Command=\"%s\">", msg);
#if AGS_PLATFORM_OS_WINDOWS
sprintf(&messageToSend[strlen(messageToSend)], " <EngineWindow>%d</EngineWindow> ", (int)sys_win_get_window());
message.AppendFmt(" <EngineWindow>%d</EngineWindow> ", (int)sys_win_get_window());
#endif
sprintf(&messageToSend[strlen(messageToSend)], " <ScriptState><![CDATA[%s]]></ScriptState> ", callStack.GetCStr());
message.AppendFmt(" <ScriptState><![CDATA[%s]]></ScriptState> ", callStack.GetCStr());
if (errorMsg != nullptr) {
sprintf(&messageToSend[strlen(messageToSend)], " <ErrorMessage><![CDATA[%s]]></ErrorMessage> ", errorMsg);
message.AppendFmt(" <ErrorMessage><![CDATA[%s]]></ErrorMessage> ", errorMsg);
}
strcat(messageToSend, "</Debugger>");
_G(editor_debugger)->SendMessageToEditor(messageToSend);
message.Append("</Debugger>");
_G(editor_debugger)->SendMessageToEditor(message.GetCStr());
return true;
}

View File

@ -88,6 +88,7 @@ void can_run_delayed_command();
// Gets current running script position
bool get_script_position(ScriptPosition &script_pos);
AGS::Shared::String cc_get_callstack(int max_lines = INT_MAX);
} // namespace AGS3

View File

@ -42,9 +42,6 @@ int ccGetOption(int optbit) {
return 0;
}
// Returns current running script callstack as a human-readable text
extern String cc_get_callstack(int max_lines = INT_MAX);
void cc_clear_error() {
_GP(ccError) = ScriptError();
}