123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #include "error_macros.h"
- #include "core/io/logger.h"
- #include "os/os.h"
- bool _err_error_exists = false;
- static ErrorHandlerList *error_handler_list = NULL;
- void _err_set_last_error(const char *p_err) {
- OS::get_singleton()->set_last_error(p_err);
- }
- void _err_clear_last_error() {
- OS::get_singleton()->clear_last_error();
- }
- void add_error_handler(ErrorHandlerList *p_handler) {
- _global_lock();
- p_handler->next = error_handler_list;
- error_handler_list = p_handler;
- _global_unlock();
- }
- void remove_error_handler(ErrorHandlerList *p_handler) {
- _global_lock();
- ErrorHandlerList *prev = NULL;
- ErrorHandlerList *l = error_handler_list;
- while (l) {
- if (l == p_handler) {
- if (prev)
- prev->next = l->next;
- else
- error_handler_list = l->next;
- break;
- }
- prev = l;
- l = l->next;
- }
- _global_unlock();
- }
- void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, ErrorHandlerType p_type) {
- OS::get_singleton()->print_error(p_function, p_file, p_line, p_error, _err_error_exists ? OS::get_singleton()->get_last_error() : "", (Logger::ErrorType)p_type);
- _global_lock();
- ErrorHandlerList *l = error_handler_list;
- while (l) {
- l->errfunc(l->userdata, p_function, p_file, p_line, p_error, _err_error_exists ? OS::get_singleton()->get_last_error() : "", p_type);
- l = l->next;
- }
- _global_unlock();
- if (_err_error_exists) {
- OS::get_singleton()->clear_last_error();
- _err_error_exists = false;
- }
- }
- void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, bool fatal) {
- String fstr(fatal ? "FATAL: " : "");
- String err(fstr + "Index " + p_index_str + "=" + itos(p_index) + " out of size (" + p_size_str + "=" + itos(p_size) + ")");
- _err_print_error(p_function, p_file, p_line, err.utf8().get_data());
- }
|