2023-02-14 02:51:14 +01:00
|
|
|
#region counter
|
|
|
|
globalvar DEBUG_COUNTER;
|
|
|
|
DEBUG_COUNTER = ds_map_create();
|
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
function __debug_counter(key) {
|
2023-02-14 02:51:14 +01:00
|
|
|
if(ds_map_exists(DEBUG_COUNTER, key))
|
|
|
|
DEBUG_COUNTER[? key]++;
|
|
|
|
else
|
|
|
|
DEBUG_COUNTER[? key] = 1;
|
|
|
|
print(key + ": " + string(DEBUG_COUNTER[? key]));
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
2022-01-25 04:05:30 +01:00
|
|
|
function _log_template() {
|
|
|
|
return string(current_year) + "/" + string(current_month) + "/" + string(current_day)
|
2022-01-13 05:24:03 +01:00
|
|
|
+ " " + string(current_hour) + ":" + string(current_minute) + ":" + string(current_second)
|
|
|
|
+ " > ";
|
2022-01-25 04:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function __log(title, str, fname = "log.txt") {
|
|
|
|
var path = DIRECTORY + fname;
|
|
|
|
var f = file_text_open_append(path);
|
|
|
|
var t = _log_template();
|
2022-01-13 05:24:03 +01:00
|
|
|
file_text_write_string(f, string(title) + t + string(str) + "\n");
|
|
|
|
file_text_close(f);
|
|
|
|
}
|
|
|
|
|
2023-04-10 20:02:59 +02:00
|
|
|
function log_message(title, str, icon = noone, flash = false, write = true) {
|
|
|
|
if(write) __log("[MESSAGE] ", string(title) + ": " + string(str));
|
2022-11-14 03:16:15 +01:00
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
return noti_status(string(title) + ": " + string(str), icon, flash);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
function log_warning(title, str, ref = noone) {
|
2022-11-14 03:16:15 +01:00
|
|
|
__log("[WARNING] ", string(title) + ": " + string(str));
|
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
return noti_warning(string(title) + ": " + string(str),, ref);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function log_crash(str) {
|
|
|
|
__log("[ERROR] ", string(str));
|
2022-11-14 03:16:15 +01:00
|
|
|
|
2022-12-22 03:09:55 +01:00
|
|
|
return noti_error(string(str));
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function log_newline() {
|
|
|
|
var path = DIRECTORY + "log.txt";
|
2023-04-21 19:08:10 +02:00
|
|
|
var f = file_text_open_write(path);
|
2022-01-13 05:24:03 +01:00
|
|
|
file_text_writeln(f);
|
|
|
|
file_text_close(f);
|
|
|
|
}
|
|
|
|
|
2022-01-25 04:05:30 +01:00
|
|
|
function log_clear() {
|
|
|
|
var path = DIRECTORY + "log.txt";
|
|
|
|
if(file_exists(path))
|
|
|
|
file_delete(path);
|
|
|
|
}
|
2022-12-22 03:09:55 +01:00
|
|
|
|
|
|
|
function exception_print(e) {
|
2023-05-03 21:42:17 +02:00
|
|
|
if(!is_struct(e) || !struct_has(e, "longMessage")) return string(e);
|
|
|
|
|
2023-01-01 02:06:02 +01:00
|
|
|
var str = "\n\n========== Crash log ==========\n\n" + e.longMessage;
|
|
|
|
str += "\n\n========== Stack trace ==========\n\n";
|
2022-12-22 03:09:55 +01:00
|
|
|
|
2023-02-14 02:51:14 +01:00
|
|
|
for( var i = 0; i < array_length(e.stacktrace); i++ )
|
2022-12-22 03:09:55 +01:00
|
|
|
str += e.stacktrace[i] + "\n"
|
|
|
|
|
2023-01-01 02:06:02 +01:00
|
|
|
str += "\n\n========= Crash log end =========\n";
|
|
|
|
|
2022-12-22 03:09:55 +01:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2023-02-19 02:13:19 +01:00
|
|
|
function setException() {
|
|
|
|
exception_unhandled_handler(function(ex) {
|
|
|
|
var path = string(DIRECTORY) + "prev_crash.pxc";
|
2023-03-11 01:40:17 +01:00
|
|
|
if(!SAVING) SAVE_AT(path);
|
2023-02-14 02:51:14 +01:00
|
|
|
|
2023-02-19 02:13:19 +01:00
|
|
|
var tt = "\n-------------------------- OH NO --------------------------\n\n";
|
|
|
|
tt += "\n" + ex.longMessage;
|
|
|
|
tt += "\n" + ex.script;
|
|
|
|
tt += "\n-------------------------- STACK TRACE --------------------------\n\n";
|
|
|
|
for( var i = 0; i < array_length(ex.stacktrace); i++ ) {
|
|
|
|
tt += ex.stacktrace[i] + "\n";
|
|
|
|
}
|
|
|
|
tt += "\n---------------------------- :( ----------------------------\n";
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-19 02:13:19 +01:00
|
|
|
var path = string(DIRECTORY) + "crash_log.txt";
|
|
|
|
file_text_write_all(path, tt);
|
|
|
|
clipboard_set_text(tt);
|
|
|
|
show_debug_message(tt);
|
2023-02-14 02:51:14 +01:00
|
|
|
|
2023-02-19 02:13:19 +01:00
|
|
|
var tt = "\n-------------------------- OH NO --------------------------\n\n";
|
|
|
|
tt += ex.longMessage;
|
|
|
|
tt += "\n---------------------------- :( ----------------------------\n";
|
|
|
|
|
|
|
|
tt += "\n\nCrash log stored in clipboard and saved at " + path;
|
|
|
|
tt += "\n\nRelaunch the program?";
|
2023-02-14 02:51:14 +01:00
|
|
|
|
2023-02-19 02:13:19 +01:00
|
|
|
widget_set_caption("Pixel Composer crashed");
|
|
|
|
widget_set_icon(DIRECTORY + "icon.png");
|
2023-02-14 02:51:14 +01:00
|
|
|
|
2023-02-19 02:13:19 +01:00
|
|
|
if(show_question(tt)) {
|
|
|
|
var path = executable_get_pathname();
|
|
|
|
execute_shell(path, "--crashed");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
}
|
2023-03-11 01:40:17 +01:00
|
|
|
//setException();
|
2023-02-19 02:13:19 +01:00
|
|
|
|
|
|
|
function resetException() {
|
|
|
|
exception_unhandled_handler(undefined);
|
|
|
|
}
|