summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/bind/core_bind.cpp4
-rw-r--r--core/class_db.cpp2
-rw-r--r--core/core_builders.py2
-rw-r--r--core/error_macros.h868
-rw-r--r--core/image.cpp2
-rw-r--r--core/io/config_file.cpp2
-rw-r--r--core/io/image_loader.cpp4
-rw-r--r--core/io/ip.cpp2
-rw-r--r--core/io/multiplayer_api.cpp16
-rw-r--r--core/io/packet_peer_udp.cpp2
-rw-r--r--core/io/resource_format_binary.cpp4
-rw-r--r--core/io/resource_importer.cpp4
-rw-r--r--core/io/resource_loader.cpp4
-rw-r--r--core/math/bsp_tree.cpp2
-rw-r--r--core/math/rect2.h13
-rw-r--r--core/message_queue.cpp2
-rw-r--r--core/object.cpp4
-rw-r--r--core/os/dir_access.cpp4
-rw-r--r--core/os/os.cpp2
-rw-r--r--core/project_settings.cpp6
-rw-r--r--core/translation.cpp2
-rw-r--r--core/type_info.h2
-rw-r--r--core/undo_redo.cpp2
-rw-r--r--core/ustring.cpp2
24 files changed, 534 insertions, 423 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index efd7e3dbf5..e61e392a79 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -110,7 +110,7 @@ PoolStringArray _ResourceLoader::get_dependencies(const String &p_path) {
#ifndef DISABLE_DEPRECATED
bool _ResourceLoader::has(const String &p_path) {
- WARN_PRINTS("ResourceLoader.has() is deprecated, please replace it with the equivalent has_cached() or the new exists().");
+ WARN_PRINT("ResourceLoader.has() is deprecated, please replace it with the equivalent has_cached() or the new exists().");
return has_cached(p_path);
}
#endif // DISABLE_DEPRECATED
@@ -3217,7 +3217,7 @@ Ref<JSONParseResult> _JSON::parse(const String &p_json) {
result->error = JSON::parse(p_json, result->result, result->error_string, result->error_line);
if (result->error != OK) {
- ERR_PRINTS(vformat("Error parsing JSON at line %s: %s", result->error_line, result->error_string));
+ ERR_PRINT(vformat("Error parsing JSON at line %s: %s", result->error_line, result->error_string));
}
return result;
}
diff --git a/core/class_db.cpp b/core/class_db.cpp
index 65f0c6008c..8800f51778 100644
--- a/core/class_db.cpp
+++ b/core/class_db.cpp
@@ -541,7 +541,7 @@ Object *ClassDB::instance(const StringName &p_class) {
}
#ifdef TOOLS_ENABLED
if (ti->api == API_EDITOR && !Engine::get_singleton()->is_editor_hint()) {
- ERR_PRINTS("Class '" + String(p_class) + "' can only be instantiated by editor.");
+ ERR_PRINT("Class '" + String(p_class) + "' can only be instantiated by editor.");
return NULL;
}
#endif
diff --git a/core/core_builders.py b/core/core_builders.py
index f3a9e3b221..7720183595 100644
--- a/core/core_builders.py
+++ b/core/core_builders.py
@@ -1,8 +1,8 @@
"""Functions used to generate source files during build time
All such functions are invoked in a subprocess on Windows to prevent build flakiness.
-
"""
+
from platform_methods import subprocess_main
from compat import iteritems, itervalues, open_utf8, escape_string, byte_to_str
diff --git a/core/error_macros.h b/core/error_macros.h
index 8ba6618942..4a3ea28957 100644
--- a/core/error_macros.h
+++ b/core/error_macros.h
@@ -32,21 +32,8 @@
#define ERROR_MACROS_H
#include "core/typedefs.h"
-/**
- * Error macros. Unlike exceptions and asserts, these macros try to maintain consistency and stability
- * inside the code. It is recommended to always return processable data, so in case of an error,
- * the engine can keep working well.
- * In most cases, bugs and/or invalid data are not fatal and should never allow a perfectly running application
- * to fail or crash.
- */
-
-/**
- * Pointer to the error macro printing function. Reassign to any function to have errors printed
- */
-
-/** Function used by the error macros */
-// function, file, line, error, explanation
+class String;
enum ErrorHandlerType {
ERR_HANDLER_ERROR,
@@ -55,7 +42,8 @@ enum ErrorHandlerType {
ERR_HANDLER_SHADER,
};
-class String;
+// Pointer to the error handler printing function. Reassign to any function to have errors printed.
+// Parameters: userdata, function, file, line, error, explanation, type.
typedef void (*ErrorHandlerFunc)(void *, const char *, const char *, int p_line, const char *, const char *, ErrorHandlerType p_type);
struct ErrorHandlerList {
@@ -75,6 +63,7 @@ struct ErrorHandlerList {
void add_error_handler(ErrorHandlerList *p_handler);
void remove_error_handler(ErrorHandlerList *p_handler);
+// Functions used by the error macros.
void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const char *p_message, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
@@ -84,15 +73,6 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co
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, const char *p_message = "", bool fatal = 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, const String &p_message, bool fatal = false);
-#ifndef _STR
-#define _STR(m_x) #m_x
-#define _MKSTR(m_x) _STR(m_x)
-#endif
-
-#define _FNL __FILE__ ":"
-
-/** An index has failed if m_index<0 or m_index >=m_size, the function exits */
-
#ifdef __GNUC__
//#define FUNCTION_STR __PRETTY_FUNCTION__ - too annoying
#define FUNCTION_STR __FUNCTION__
@@ -100,15 +80,16 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li
#define FUNCTION_STR __FUNCTION__
#endif
-// Don't use this directly; instead, use any of the CRASH_* macros
#ifdef _MSC_VER
-#define GENERATE_TRAP \
- __debugbreak(); \
- /* Avoid warning about control paths */ \
- for (;;) { \
- }
+/**
+ * Don't use GENERATE_TRAP() directly, should only be used be the macros below.
+ */
+#define GENERATE_TRAP() __debugbreak()
#else
-#define GENERATE_TRAP __builtin_trap();
+/**
+ * Don't use GENERATE_TRAP() directly, should only be used be the macros below.
+ */
+#define GENERATE_TRAP() __builtin_trap()
#endif
// Used to strip debug messages in release mode
@@ -118,411 +99,528 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li
#define DEBUG_STR(m_msg) ""
#endif
-// (*): See https://stackoverflow.com/questions/257418/do-while-0-what-is-it-good-for
-
-/**
- * If `m_index` is less than 0 or greater than or equal to `m_size`, prints a generic
- * error message and returns from the function. This macro should be preferred to
- * `ERR_FAIL_COND` for bounds checking.
- */
-#define ERR_FAIL_INDEX(m_index, m_size) \
- do { \
- if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
- _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
- return; \
- } \
- } while (0); // (*)
-
-/**
- * If `m_index` is less than 0 or greater than or equal to `m_size`, prints a custom
- * error message and returns from the function. This macro should be preferred to
- * `ERR_FAIL_COND_MSG` for bounds checking.
- */
-#define ERR_FAIL_INDEX_MSG(m_index, m_size, m_msg) \
- do { \
- if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
- _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), DEBUG_STR(m_msg)); \
- return; \
- } \
- } while (0); // (*)
-
-/**
- * If `m_index` is less than 0 or greater than or equal to `m_size`,
- * prints a generic error message and returns the value specified in `m_retval`.
- * This macro should be preferred to `ERR_FAIL_COND_V` for bounds checking.
- */
-#define ERR_FAIL_INDEX_V(m_index, m_size, m_retval) \
- do { \
- if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
- _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
- return m_retval; \
- } \
- } while (0); // (*)
-
-/**
- * If `m_index` is less than 0 or greater than or equal to `m_size`,
- * prints a custom error message and returns the value specified in `m_retval`.
- * This macro should be preferred to `ERR_FAIL_COND_V_MSG` for bounds checking.
- */
-#define ERR_FAIL_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
- do { \
- if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
- _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), DEBUG_STR(m_msg)); \
- return m_retval; \
- } \
- } while (0); // (*)
-
-/**
- * If `m_index` is greater than or equal to `m_size`,
- * prints a generic error message and returns the value specified in `m_retval`.
- * This macro should be preferred to `ERR_FAIL_COND_V` for unsigned bounds checking.
- */
-#define ERR_FAIL_UNSIGNED_INDEX_V(m_index, m_size, m_retval) \
- do { \
- if (unlikely((m_index) >= (m_size))) { \
- _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
- return m_retval; \
- } \
- } while (0); // (*)
-
-/**
- * If `m_index` is greater than or equal to `m_size`,
- * prints a custom error message and returns the value specified in `m_retval`.
- * This macro should be preferred to `ERR_FAIL_COND_V_MSG` for unsigned bounds checking.
- */
-#define ERR_FAIL_UNSIGNED_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
- do { \
- if (unlikely((m_index) >= (m_size))) { \
- _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), DEBUG_STR(m_msg)); \
- return m_retval; \
- } \
- } while (0); // (*)
-
-/**
- * If `m_index` is less than 0 or greater than or equal to `m_size`,
- * crashes the engine immediately with a generic error message.
- * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
- * This macro should be preferred to `CRASH_COND` for bounds checking.
- */
-#define CRASH_BAD_INDEX(m_index, m_size) \
- do { \
- if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
- _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", true); \
- GENERATE_TRAP \
- } \
- } while (0); // (*)
-
-/**
- * If `m_index` is less than 0 or greater than or equal to `m_size`,
- * crashes the engine immediately with a custom error message.
- * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
- * This macro should be preferred to `CRASH_COND` for bounds checking.
- */
-#define CRASH_BAD_INDEX_MSG(m_index, m_size, m_msg) \
- do { \
- if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
- _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, true); \
- GENERATE_TRAP \
- } \
- } while (0); // (*)
-
-/**
- * If `m_param` is `null`, prints a generic error message and returns from the function.
- */
-#define ERR_FAIL_NULL(m_param) \
- { \
- if (unlikely(!m_param)) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null."); \
- return; \
- } \
- }
-
/**
- * If `m_param` is `null`, prints a custom error message and returns from the function.
+ * Error macros.
+ * WARNING: These macros work in the opposite way to assert().
+ *
+ * Unlike exceptions and asserts, these macros try to maintain consistency and stability.
+ * In most cases, bugs and/or invalid data are not fatal. They should never allow a perfectly
+ * running application to fail or crash.
+ * Always try to return processable data, so the engine can keep running well.
+ * Use the _MSG versions to print a meaningful message to help with debugging.
*/
-#define ERR_FAIL_NULL_MSG(m_param, m_msg) \
- { \
- if (unlikely(!m_param)) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null.", DEBUG_STR(m_msg)); \
- return; \
- } \
- }
-/**
- * If `m_param` is `null`, prints a generic error message and returns the value specified in `m_retval`.
- */
-#define ERR_FAIL_NULL_V(m_param, m_retval) \
- { \
- if (unlikely(!m_param)) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null."); \
- return m_retval; \
- } \
- }
+// Index out of bounds error macros.
+// These macros should be used instead of `ERR_FAIL_COND` for bounds checking.
-/**
- * If `m_param` is `null`, prints a custom error message and returns the value specified in `m_retval`.
- */
-#define ERR_FAIL_NULL_V_MSG(m_param, m_retval, m_msg) \
- { \
- if (unlikely(!m_param)) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null.", DEBUG_STR(m_msg)); \
- return m_retval; \
- } \
- }
+// Integer index out of bounds error macros.
/**
- * If `m_cond` evaluates to `true`, prints a generic error message and returns from the function.
+ * Try using `ERR_FAIL_INDEX_MSG`.
+ * Only use this macro if there is no sensible error message.
+ *
+ * Ensures an integer index `m_index` is less than `m_size` and greater than or equal to 0.
+ * If not, the current function returns.
*/
-#define ERR_FAIL_COND(m_cond) \
- { \
- if (unlikely(m_cond)) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true."); \
- return; \
- } \
- }
+#define ERR_FAIL_INDEX(m_index, m_size) \
+ if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
+ return; \
+ } else \
+ ((void)0)
/**
- * If `m_cond` evaluates to `true`, prints a custom error message and returns from the function.
+ * Ensures an integer index `m_index` is less than `m_size` and greater than or equal to 0.
+ * If not, prints `m_msg` and the current function returns.
*/
-#define ERR_FAIL_COND_MSG(m_cond, m_msg) \
- { \
- if (unlikely(m_cond)) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true.", DEBUG_STR(m_msg)); \
- return; \
- } \
- }
+#define ERR_FAIL_INDEX_MSG(m_index, m_size, m_msg) \
+ if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), DEBUG_STR(m_msg)); \
+ return; \
+ } else \
+ ((void)0)
/**
- * If `m_cond` evaluates to `true`, crashes the engine immediately with a generic error message.
- * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
+ * Try using `ERR_FAIL_INDEX_V_MSG`.
+ * Only use this macro if there is no sensible error message.
+ *
+ * Ensures an integer index `m_index` is less than `m_size` and greater than or equal to 0.
+ * If not, the current function returns `m_retval`.
*/
-#define CRASH_COND(m_cond) \
- { \
- if (unlikely(m_cond)) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Condition \"" _STR(m_cond) "\" is true."); \
- GENERATE_TRAP \
- } \
- }
+#define ERR_FAIL_INDEX_V(m_index, m_size, m_retval) \
+ if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
+ return m_retval; \
+ } else \
+ ((void)0)
/**
- * If `m_cond` evaluates to `true`, crashes the engine immediately with a custom error message.
- * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
- */
-#define CRASH_COND_MSG(m_cond, m_msg) \
- { \
- if (unlikely(m_cond)) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Condition \"" _STR(m_cond) "\" is true.", DEBUG_STR(m_msg)); \
- GENERATE_TRAP \
- } \
- }
+ * Ensures an integer index `m_index` is less than `m_size` and greater than or equal to 0.
+ * If not, prints `m_msg` and the current function returns `m_retval`.
+ */
+#define ERR_FAIL_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
+ if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), DEBUG_STR(m_msg)); \
+ return m_retval; \
+ } else \
+ ((void)0)
-/**
- * If `m_cond` evaluates to `true`, prints a generic error message and returns the value specified in `m_retval`.
- */
-#define ERR_FAIL_COND_V(m_cond, m_retval) \
- { \
- if (unlikely(m_cond)) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Returned: " _STR(m_retval)); \
- return m_retval; \
- } \
- }
+/**
+ * Try using `ERR_FAIL_INDEX_MSG` or `ERR_FAIL_INDEX_V_MSG`.
+ * Only use this macro if there is no sensible fallback i.e. the error is unrecoverable, and
+ * there is no sensible error message.
+ *
+ * Ensures an integer index `m_index` is less than `m_size` and greater than or equal to 0.
+ * If not, the application crashes.
+ */
+#define CRASH_BAD_INDEX(m_index, m_size) \
+ if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", true); \
+ GENERATE_TRAP(); \
+ } else \
+ ((void)0)
/**
- * If `m_cond` evaluates to `true`, prints a custom error message and returns the value specified in `m_retval`.
- */
-#define ERR_FAIL_COND_V_MSG(m_cond, m_retval, m_msg) \
- { \
- if (unlikely(m_cond)) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Returned: " _STR(m_retval), DEBUG_STR(m_msg)); \
- return m_retval; \
- } \
- }
+ * Try using `ERR_FAIL_INDEX_MSG` or `ERR_FAIL_INDEX_V_MSG`.
+ * Only use this macro if there is no sensible fallback i.e. the error is unrecoverable.
+ *
+ * Ensures an integer index `m_index` is less than `m_size` and greater than or equal to 0.
+ * If not, prints `m_msg` and the application crashes.
+ */
+#define CRASH_BAD_INDEX_MSG(m_index, m_size, m_msg) \
+ if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), DEBUG_STR(m_msg), true); \
+ GENERATE_TRAP(); \
+ } else \
+ ((void)0)
+
+// Unsigned integer index out of bounds error macros.
/**
- * If `m_cond` evaluates to `true`, prints a custom error message and continues the loop the macro is located in.
- */
-#define ERR_CONTINUE(m_cond) \
- { \
- if (unlikely(m_cond)) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Continuing."); \
- continue; \
- } \
- }
+ * Try using `ERR_FAIL_UNSIGNED_INDEX_MSG`.
+ * Only use this macro if there is no sensible error message.
+ *
+ * Ensures an unsigned integer index `m_index` is less than `m_size`.
+ * If not, the current function returns.
+ */
+#define ERR_FAIL_UNSIGNED_INDEX(m_index, m_size) \
+ if (unlikely((m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
+ return; \
+ } else \
+ ((void)0)
+
+/**
+ * Ensures an unsigned integer index `m_index` is less than `m_size`.
+ * If not, prints `m_msg` and the current function returns.
+ */
+#define ERR_FAIL_UNSIGNED_INDEX_MSG(m_index, m_size, m_msg) \
+ if (unlikely((m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), DEBUG_STR(m_msg)); \
+ return; \
+ } else \
+ ((void)0)
+
+/**
+ * Try using `ERR_FAIL_UNSIGNED_INDEX_V_MSG`.
+ * Only use this macro if there is no sensible error message.
+ *
+ * Ensures an unsigned integer index `m_index` is less than `m_size`.
+ * If not, the current function returns `m_retval`.
+ */
+#define ERR_FAIL_UNSIGNED_INDEX_V(m_index, m_size, m_retval) \
+ if (unlikely((m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
+ return m_retval; \
+ } else \
+ ((void)0)
+
+/**
+ * Ensures an unsigned integer index `m_index` is less than `m_size`.
+ * If not, prints `m_msg` and the current function returns `m_retval`.
+ */
+#define ERR_FAIL_UNSIGNED_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
+ if (unlikely((m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), DEBUG_STR(m_msg)); \
+ return m_retval; \
+ } else \
+ ((void)0)
+
+/**
+ * Try using `ERR_FAIL_UNSIGNED_INDEX_MSG` or `ERR_FAIL_UNSIGNED_INDEX_V_MSG`.
+ * Only use this macro if there is no sensible fallback i.e. the error is unrecoverable, and
+ * there is no sensible error message.
+ *
+ * Ensures an unsigned integer index `m_index` is less than `m_size`.
+ * If not, the application crashes.
+ */
+#define CRASH_BAD_UNSIGNED_INDEX(m_index, m_size) \
+ if (unlikely((m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", true); \
+ GENERATE_TRAP(); \
+ } else \
+ ((void)0)
+
+/**
+ * Try using `ERR_FAIL_UNSIGNED_INDEX_MSG` or `ERR_FAIL_UNSIGNED_INDEX_V_MSG`.
+ * Only use this macro if there is no sensible fallback i.e. the error is unrecoverable.
+ *
+ * Ensures an unsigned integer index `m_index` is less than `m_size`.
+ * If not, prints `m_msg` and the application crashes.
+ */
+#define CRASH_BAD_UNSIGNED_INDEX_MSG(m_index, m_size, m_msg) \
+ if (unlikely((m_index) >= (m_size))) { \
+ _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), DEBUG_STR(m_msg), true); \
+ GENERATE_TRAP(); \
+ } else \
+ ((void)0)
+
+// Null reference error macros.
+
+/**
+ * Try using `ERR_FAIL_NULL_MSG`.
+ * Only use this macro if there is no sensible error message.
+ *
+ * Ensures a pointer `m_param` is not null.
+ * If it is null, the current function returns.
+ */
+#define ERR_FAIL_NULL(m_param) \
+ if (unlikely(!m_param)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null."); \
+ return; \
+ } else \
+ ((void)0)
+
+/**
+ * Ensures a pointer `m_param` is not null.
+ * If it is null, prints `m_msg` and the current function returns.
+ */
+#define ERR_FAIL_NULL_MSG(m_param, m_msg) \
+ if (unlikely(!m_param)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null.", DEBUG_STR(m_msg)); \
+ return; \
+ } else \
+ ((void)0)
+
+/**
+ * Try using `ERR_FAIL_NULL_V_MSG`.
+ * Only use this macro if there is no sensible error message.
+ *
+ * Ensures a pointer `m_param` is not null.
+ * If it is null, the current function returns `m_retval`.
+ */
+#define ERR_FAIL_NULL_V(m_param, m_retval) \
+ if (unlikely(!m_param)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null."); \
+ return m_retval; \
+ } else \
+ ((void)0)
+
+/**
+ * Ensures a pointer `m_param` is not null.
+ * If it is null, prints `m_msg` and the current function returns `m_retval`.
+ */
+#define ERR_FAIL_NULL_V_MSG(m_param, m_retval, m_msg) \
+ if (unlikely(!m_param)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null.", DEBUG_STR(m_msg)); \
+ return m_retval; \
+ } else \
+ ((void)0)
+
+/**
+ * Try using `ERR_FAIL_COND_MSG`.
+ * Only use this macro if there is no sensible error message.
+ * If checking for null use ERR_FAIL_NULL_MSG instead.
+ * If checking index bounds use ERR_FAIL_INDEX_MSG instead.
+ *
+ * Ensures `m_cond` is false.
+ * If `m_cond` is true, the current function returns.
+ */
+#define ERR_FAIL_COND(m_cond) \
+ if (unlikely(m_cond)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true."); \
+ return; \
+ } else \
+ ((void)0)
+
+/**
+ * Ensures `m_cond` is false.
+ * If `m_cond` is true, prints `m_msg` and the current function returns.
+ *
+ * If checking for null use ERR_FAIL_NULL_MSG instead.
+ * If checking index bounds use ERR_FAIL_INDEX_MSG instead.
+ */
+#define ERR_FAIL_COND_MSG(m_cond, m_msg) \
+ if (unlikely(m_cond)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true.", DEBUG_STR(m_msg)); \
+ return; \
+ } else \
+ ((void)0)
+
+/**
+ * Try using `ERR_FAIL_COND_V_MSG`.
+ * Only use this macro if there is no sensible error message.
+ * If checking for null use ERR_FAIL_NULL_V_MSG instead.
+ * If checking index bounds use ERR_FAIL_INDEX_V_MSG instead.
+ *
+ * Ensures `m_cond` is false.
+ * If `m_cond` is true, the current function returns `m_retval`.
+ */
+#define ERR_FAIL_COND_V(m_cond, m_retval) \
+ if (unlikely(m_cond)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. returned: " _STR(m_retval)); \
+ return m_retval; \
+ } else \
+ ((void)0)
+
+/**
+ * Ensures `m_cond` is false.
+ * If `m_cond` is true, prints `m_msg` and the current function returns `m_retval`.
+ *
+ * If checking for null use ERR_FAIL_NULL_V_MSG instead.
+ * If checking index bounds use ERR_FAIL_INDEX_V_MSG instead.
+ */
+#define ERR_FAIL_COND_V_MSG(m_cond, m_retval, m_msg) \
+ if (unlikely(m_cond)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. returned: " _STR(m_retval), DEBUG_STR(m_msg)); \
+ return m_retval; \
+ } else \
+ ((void)0)
+
+/**
+ * Try using `ERR_CONTINUE_MSG`.
+ * Only use this macro if there is no sensible error message.
+ *
+ * Ensures `m_cond` is false.
+ * If `m_cond` is true, the current loop continues.
+ */
+#define ERR_CONTINUE(m_cond) \
+ if (unlikely(m_cond)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Continuing."); \
+ continue; \
+ } else \
+ ((void)0)
+
+/**
+ * Ensures `m_cond` is false.
+ * If `m_cond` is true, prints `m_msg` and the current loop continues.
+ */
+#define ERR_CONTINUE_MSG(m_cond, m_msg) \
+ if (unlikely(m_cond)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Continuing.", DEBUG_STR(m_msg)); \
+ continue; \
+ } else \
+ ((void)0)
+
+/**
+ * Try using `ERR_BREAK_MSG`.
+ * Only use this macro if there is no sensible error message.
+ *
+ * Ensures `m_cond` is false.
+ * If `m_cond` is true, the current loop breaks.
+ */
+#define ERR_BREAK(m_cond) \
+ if (unlikely(m_cond)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Breaking."); \
+ break; \
+ } else \
+ ((void)0)
+
+/**
+ * Ensures `m_cond` is false.
+ * If `m_cond` is true, prints `m_msg` and the current loop breaks.
+ */
+#define ERR_BREAK_MSG(m_cond, m_msg) \
+ if (unlikely(m_cond)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Breaking.", DEBUG_STR(m_msg)); \
+ break; \
+ } else \
+ ((void)0)
+
+/**
+ * Try using `ERR_FAIL_COND_MSG` or `ERR_FAIL_COND_V_MSG`.
+ * Only use this macro if there is no sensible fallback i.e. the error is unrecoverable, and
+ * there is no sensible error message.
+ *
+ * Ensures `m_cond` is false.
+ * If `m_cond` is true, the application crashes.
+ */
+#define CRASH_COND(m_cond) \
+ if (unlikely(m_cond)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Condition \"" _STR(m_cond) "\" is true."); \
+ GENERATE_TRAP(); \
+ } else \
+ ((void)0)
+
+/**
+ * Try using `ERR_FAIL_COND_MSG` or `ERR_FAIL_COND_V_MSG`.
+ * Only use this macro if there is no sensible fallback i.e. the error is unrecoverable.
+ *
+ * Ensures `m_cond` is false.
+ * If `m_cond` is true, prints `m_msg` and the application crashes.
+ */
+#define CRASH_COND_MSG(m_cond, m_msg) \
+ if (unlikely(m_cond)) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Condition \"" _STR(m_cond) "\" is true.", DEBUG_STR(m_msg)); \
+ GENERATE_TRAP(); \
+ } else \
+ ((void)0)
+
+// Generic error macros.
+
+/**
+ * Try using `ERR_FAIL_COND_MSG` or `ERR_FAIL_MSG`.
+ * Only use this macro if more complex error detection or recovery is required, and
+ * there is no sensible error message.
+ *
+ * The current function returns.
+ */
+#define ERR_FAIL() \
+ if (1) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed."); \
+ return; \
+ } else \
+ ((void)0)
/**
- * If `m_cond` evaluates to `true`, prints a custom error message and continues the loop the macro is located in.
+ * Try using `ERR_FAIL_COND_MSG`.
+ * Only use this macro if more complex error detection or recovery is required.
+ *
+ * Prints `m_msg`, and the current function returns.
*/
-#define ERR_CONTINUE_MSG(m_cond, m_msg) \
- { \
- if (unlikely(m_cond)) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Continuing.", DEBUG_STR(m_msg)); \
- continue; \
- } \
- }
+#define ERR_FAIL_MSG(m_msg) \
+ if (1) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed.", DEBUG_STR(m_msg)); \
+ return; \
+ } else \
+ ((void)0)
/**
- * If `m_cond` evaluates to `true`, prints a generic error message and breaks from the loop the macro is located in.
+ * Try using `ERR_FAIL_COND_V_MSG` or `ERR_FAIL_V_MSG`.
+ * Only use this macro if more complex error detection or recovery is required, and
+ * there is no sensible error message.
+ *
+ * The current function returns `m_retval`.
*/
-#define ERR_BREAK(m_cond) \
- { \
- if (unlikely(m_cond)) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Breaking."); \
- break; \
- } \
- }
+#define ERR_FAIL_V(m_retval) \
+ if (1) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " __STR(m_value)); \
+ return m_retval; \
+ } else \
+ ((void)0)
/**
- * If `m_cond` evaluates to `true`, prints a custom error message and breaks from the loop the macro is located in.
+ * Try using `ERR_FAIL_COND_V_MSG`.
+ * Only use this macro if more complex error detection or recovery is required.
+ *
+ * Prints `m_msg`, and the current function returns `m_retval`.
*/
-#define ERR_BREAK_MSG(m_cond, m_msg) \
- { \
- if (unlikely(m_cond)) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Breaking.", DEBUG_STR(m_msg)); \
- break; \
- } \
- }
-
-/**
- * Prints a generic error message and returns from the function.
- */
-#define ERR_FAIL() \
- { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method failed."); \
- return; \
- }
-
-/**
- * Prints a custom error message and returns from the function.
- */
-#define ERR_FAIL_MSG(m_msg) \
- { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method failed.", DEBUG_STR(m_msg)); \
- return; \
- }
-
-/**
- * Prints a generic error message and returns the value specified in `m_retval`.
- */
-#define ERR_FAIL_V(m_retval) \
- { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method failed. Returning: " __STR(m_retval)); \
- return m_retval; \
- }
-
-/**
- * Prints a custom error message and returns the value specified in `m_retval`.
- */
-#define ERR_FAIL_V_MSG(m_retval, m_msg) \
- { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method failed. Returning: " __STR(m_retval), DEBUG_STR(m_msg)); \
- return m_retval; \
- }
-
-/**
- * Crashes the engine immediately with a generic error message.
- * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
- */
-#define CRASH_NOW() \
- { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Method failed."); \
- GENERATE_TRAP \
- }
-
-/**
- * Crashes the engine immediately with a custom error message.
- * Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
- */
-#define CRASH_NOW_MSG(m_msg) \
- { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Method failed.", DEBUG_STR(m_msg)); \
- GENERATE_TRAP \
- }
+#define ERR_FAIL_V_MSG(m_retval, m_msg) \
+ if (1) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " __STR(m_value), DEBUG_STR(m_msg)); \
+ return m_retval; \
+ } else \
+ ((void)0)
/**
- * Prints an error message without returning.
+ * Try using `ERR_FAIL_COND_MSG`, `ERR_FAIL_COND_V_MSG`, `ERR_CONTINUE_MSG` or ERR_BREAK_MSG.
+ * Only use this macro at the start of a function that has not been implemented yet, or
+ * if more complex error detection or recovery is required.
+ *
+ * Prints `m_msg`.
*/
-#define ERR_PRINT(m_string) \
- { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string); \
- }
+#define ERR_PRINT(m_msg) \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, DEBUG_STR(m_msg))
/**
- * Prints an error message without returning.
- * FIXME: Remove this macro and replace all uses with `ERR_PRINT` as it's identical.
+ * Prints `m_msg` once during the application lifetime.
*/
-#define ERR_PRINTS(m_string) \
- { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string); \
- }
+#define ERR_PRINT_ONCE(m_msg) \
+ if (1) { \
+ static bool first_print = true; \
+ if (first_print) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, DEBUG_STR(m_msg)); \
+ first_print = false; \
+ } \
+ } else \
+ ((void)0)
-/**
- * Prints an error message without returning, but only do so once in the application lifecycle.
- * This can be used to avoid spamming the console with error messages.
- */
-#define ERR_PRINT_ONCE(m_string) \
- { \
- static bool first_print = true; \
- if (first_print) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string); \
- first_print = false; \
- } \
- }
+// Print warning message macros.
/**
- * Prints a warning message without returning. To warn about deprecated usage,
- * use `WARN_DEPRECATED` or `WARN_DEPRECATED_MSG` instead.
+ * Prints `m_msg`.
+ *
+ * If warning about deprecated usage, use `WARN_DEPRECATED` or `WARN_DEPRECATED_MSG` instead.
*/
-#define WARN_PRINT(m_string) \
- { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING); \
- }
+#define WARN_PRINT(m_msg) \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, DEBUG_STR(m_msg), ERR_HANDLER_WARNING)
/**
- * Prints a warning message without returning.
- * FIXME: Remove this macro and replace all uses with `WARN_PRINT` as it's identical.
+ * Prints `m_msg` once during the application lifetime.
+ *
+ * If warning about deprecated usage, use `WARN_DEPRECATED` or `WARN_DEPRECATED_MSG` instead.
*/
-#define WARN_PRINTS(m_string) \
- { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING); \
- }
+#define WARN_PRINT_ONCE(m_msg) \
+ if (1) { \
+ static bool first_print = true; \
+ if (first_print) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, DEBUG_STR(m_msg), ERR_HANDLER_WARNING); \
+ first_print = false; \
+ } \
+ } else \
+ ((void)0)
-/**
- * Prints a warning message without returning, but only do so once in the application lifecycle.
- * This can be used to avoid spamming the console with warning messages.
- */
-#define WARN_PRINT_ONCE(m_string) \
- { \
- static bool first_print = true; \
- if (first_print) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING); \
- first_print = false; \
- } \
- }
+// Print deprecated warning message macros.
/**
- * Prints a generic deprecation warning message without returning.
- * This should be preferred to `WARN_PRINT` for deprecation warnings.
+ * Warns that the current function is deprecated.
*/
#define WARN_DEPRECATED \
- { \
+ if (1) { \
static volatile bool warning_shown = false; \
if (!warning_shown) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "This method has been deprecated and will be removed in the future.", ERR_HANDLER_WARNING); \
warning_shown = true; \
} \
- }
-
-/**
- * Prints a custom deprecation warning message without returning.
- * This should be preferred to `WARN_PRINT` for deprecation warnings.
- */
-#define WARN_DEPRECATED_MSG(m_msg) \
- { \
- static volatile bool warning_shown = false; \
- if (!warning_shown) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "This method has been deprecated and will be removed in the future.", m_msg, ERR_HANDLER_WARNING); \
- warning_shown = true; \
- } \
- }
+ } else \
+ ((void)0)
+
+/**
+ * Warns that the current function is deprecated and prints `m_msg`.
+ */
+#define WARN_DEPRECATED_MSG(m_msg) \
+ if (1) { \
+ static volatile bool warning_shown = false; \
+ if (!warning_shown) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "This method has been deprecated and will be removed in the future.", DEBUG_STR(m_msg), ERR_HANDLER_WARNING); \
+ warning_shown = true; \
+ } \
+ } else \
+ ((void)0)
+
+/**
+ * Do not use.
+ * If the application should never reach this point use CRASH_NOW_MSG(m_msg) to explain why.
+ *
+ * The application crashes.
+ */
+#define CRASH_NOW() \
+ if (1) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Method/Function Failed."); \
+ GENERATE_TRAP(); \
+ } else \
+ ((void)0)
+
+/**
+ * Only use if the application should never reach this point.
+ *
+ * Prints `m_msg`, and then the application crashes.
+ */
+#define CRASH_NOW_MSG(m_msg) \
+ if (1) { \
+ _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Method/Function Failed.", DEBUG_STR(m_msg)); \
+ GENERATE_TRAP(); \
+ } else \
+ ((void)0)
#endif
diff --git a/core/image.cpp b/core/image.cpp
index f43c26ab19..09b07bba13 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -1879,7 +1879,7 @@ Image::AlphaMode Image::detect_alpha() const {
Error Image::load(const String &p_path) {
#ifdef DEBUG_ENABLED
if (p_path.begins_with("res://") && ResourceLoader::exists(p_path)) {
- WARN_PRINTS("Loaded resource as image file, this will not work on export: '" + p_path + "'. Instead, import the image file as an Image resource and load it normally as a resource.");
+ WARN_PRINT("Loaded resource as image file, this will not work on export: '" + p_path + "'. Instead, import the image file as an Image resource and load it normally as a resource.");
}
#endif
return ImageLoader::load_image(p_path, this);
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp
index 5c25cad770..99da512247 100644
--- a/core/io/config_file.cpp
+++ b/core/io/config_file.cpp
@@ -275,7 +275,7 @@ Error ConfigFile::_internal_load(const String &p_path, FileAccess *f) {
memdelete(f);
return OK;
} else if (err != OK) {
- ERR_PRINTS("ConfgFile::load - " + p_path + ":" + itos(lines) + " error: " + error_text + ".");
+ ERR_PRINT("ConfgFile::load - " + p_path + ":" + itos(lines) + " error: " + error_text + ".");
memdelete(f);
return err;
}
diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp
index 05929ee8ed..720f25f91b 100644
--- a/core/io/image_loader.cpp
+++ b/core/io/image_loader.cpp
@@ -53,7 +53,7 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c
Error err;
f = FileAccess::open(p_file, FileAccess::READ, &err);
if (!f) {
- ERR_PRINTS("Error opening file '" + p_file + "'.");
+ ERR_PRINT("Error opening file '" + p_file + "'.");
return err;
}
}
@@ -66,7 +66,7 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c
continue;
Error err = loader[i]->load_image(p_image, f, p_force_linear, p_scale);
if (err != OK) {
- ERR_PRINTS("Error loading image: " + p_file);
+ ERR_PRINT("Error loading image: " + p_file);
}
if (err != ERR_FILE_UNRECOGNIZED) {
diff --git a/core/io/ip.cpp b/core/io/ip.cpp
index ea791fb327..23f6ca25d0 100644
--- a/core/io/ip.cpp
+++ b/core/io/ip.cpp
@@ -184,7 +184,7 @@ IP_Address IP::get_resolve_item_address(ResolverID p_id) const {
resolver->mutex->lock();
if (resolver->queue[p_id].status != IP::RESOLVER_STATUS_DONE) {
- ERR_PRINTS("Resolve of '" + resolver->queue[p_id].hostname + "'' didn't complete yet.");
+ ERR_PRINT("Resolve of '" + resolver->queue[p_id].hostname + "'' didn't complete yet.");
resolver->mutex->unlock();
return IP_Address();
}
diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp
index 381ac4c0bb..fbed460a4e 100644
--- a/core/io/multiplayer_api.cpp
+++ b/core/io/multiplayer_api.cpp
@@ -253,7 +253,7 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int
node = root_node->get_node(np);
if (!node)
- ERR_PRINTS("Failed to get path from RPC: " + String(np) + ".");
+ ERR_PRINT("Failed to get path from RPC: " + String(np) + ".");
} else {
// Use cached path.
int id = target;
@@ -269,7 +269,7 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int
node = root_node->get_node(ni->path);
if (!node)
- ERR_PRINTS("Failed to get cached path from RPC: " + String(ni->path) + ".");
+ ERR_PRINT("Failed to get cached path from RPC: " + String(ni->path) + ".");
}
return node;
}
@@ -324,7 +324,7 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_
if (ce.error != Variant::CallError::CALL_OK) {
String error = Variant::get_call_error_text(p_node, p_name, (const Variant **)argp.ptr(), argc, ce);
error = "RPC - " + error;
- ERR_PRINTS(error);
+ ERR_PRINT(error);
}
}
@@ -362,7 +362,7 @@ void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p
p_node->set(p_name, value, &valid);
if (!valid) {
String error = "Error setting remote property '" + String(p_name) + "', not found in object of type " + p_node->get_class() + ".";
- ERR_PRINTS(error);
+ ERR_PRINT(error);
}
}
@@ -683,7 +683,7 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const
if (ce.error != Variant::CallError::CALL_OK) {
String error = Variant::get_call_error_text(p_node, p_method, p_arg, p_argcount, ce);
error = "rpc() aborted in local call: - " + error + ".";
- ERR_PRINTS(error);
+ ERR_PRINT(error);
return;
}
}
@@ -698,7 +698,7 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const
if (ce.error != Variant::CallError::CALL_OK) {
String error = Variant::get_call_error_text(p_node, p_method, p_arg, p_argcount, ce);
error = "rpc() aborted in script local call: - " + error + ".";
- ERR_PRINTS(error);
+ ERR_PRINT(error);
return;
}
}
@@ -735,7 +735,7 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const
if (!valid) {
String error = "rset() aborted in local set, property not found: - " + String(p_property) + ".";
- ERR_PRINTS(error);
+ ERR_PRINT(error);
return;
}
} else if (p_node->get_script_instance()) {
@@ -753,7 +753,7 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const
if (!valid) {
String error = "rset() aborted in local script set, property not found: - " + String(p_property) + ".";
- ERR_PRINTS(error);
+ ERR_PRINT(error);
return;
}
}
diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp
index 5c98c4fcab..a8cfd741bb 100644
--- a/core/io/packet_peer_udp.cpp
+++ b/core/io/packet_peer_udp.cpp
@@ -222,7 +222,7 @@ Error PacketPeerUDP::_poll() {
if (rb.space_left() < read + 24) {
#ifdef TOOLS_ENABLED
- WARN_PRINTS("Buffer full, dropping packets!");
+ WARN_PRINT("Buffer full, dropping packets!");
#endif
continue;
}
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 272d5c1116..97dca98185 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -1113,7 +1113,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
memdelete(da);
//use the old approach
- WARN_PRINTS("This file is old, so it can't refactor dependencies, opening and resaving '" + p_path + "'.");
+ WARN_PRINT("This file is old, so it can't refactor dependencies, opening and resaving '" + p_path + "'.");
Error err;
f = FileAccess::open(p_path, FileAccess::READ, &err);
@@ -1635,7 +1635,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
if (!p_main && (!bundle_resources) && res->get_path().length() && res->get_path().find("::") == -1) {
if (res->get_path() == path) {
- ERR_PRINTS("Circular reference to resource being saved found: '" + local_path + "' will be null next time it's loaded.");
+ ERR_PRINT("Circular reference to resource being saved found: '" + local_path + "' will be null next time it's loaded.");
return;
}
int idx = external_resources.size();
diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp
index c2d90ed204..f147170ff7 100644
--- a/core/io/resource_importer.cpp
+++ b/core/io/resource_importer.cpp
@@ -74,7 +74,7 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy
memdelete(f);
return OK;
} else if (err != OK) {
- ERR_PRINTS("ResourceFormatImporter::load - " + p_path + ".import:" + itos(lines) + " error: " + error_text);
+ ERR_PRINT("ResourceFormatImporter::load - " + p_path + ".import:" + itos(lines) + " error: " + error_text);
memdelete(f);
return err;
}
@@ -279,7 +279,7 @@ void ResourceFormatImporter::get_internal_resource_path_list(const String &p_pat
memdelete(f);
return;
} else if (err != OK) {
- ERR_PRINTS("ResourceFormatImporter::get_internal_resource_path_list - " + p_path + ".import:" + itos(lines) + " error: " + error_text);
+ ERR_PRINT("ResourceFormatImporter::get_internal_resource_path_list - " + p_path + ".import:" + itos(lines) + " error: " + error_text);
memdelete(f);
return;
}
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 7471ab4241..0e1ada9475 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -815,7 +815,7 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem
if (err == ERR_FILE_EOF) {
break;
} else if (err != OK) {
- ERR_PRINTS("Parse error: " + p_path + ".remap:" + itos(lines) + " error: " + error_text + ".");
+ ERR_PRINT("Parse error: " + p_path + ".remap:" + itos(lines) + " error: " + error_text + ".");
break;
}
@@ -1013,7 +1013,7 @@ void ResourceLoader::finalize() {
#ifndef NO_THREADS
const LoadingMapKey *K = NULL;
while ((K = loading_map.next(K))) {
- ERR_PRINTS("Exited while resource is being loaded: " + K->path);
+ ERR_PRINT("Exited while resource is being loaded: " + K->path);
}
loading_map.clear();
memdelete(loading_map_mutex);
diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp
index f155d626d7..7ad907db97 100644
--- a/core/math/bsp_tree.cpp
+++ b/core/math/bsp_tree.cpp
@@ -341,7 +341,7 @@ static int _bsp_create_node(const Face3 *p_faces, const Vector<int> &p_indices,
ERR_FAIL_COND_V(p_nodes.size() == BSP_Tree::MAX_NODES, -1);
// should not reach here
- ERR_FAIL_COND_V(p_indices.size() == 0, -1)
+ ERR_FAIL_COND_V(p_indices.size() == 0, -1);
int ic = p_indices.size();
const int *indices = p_indices.ptr();
diff --git a/core/math/rect2.h b/core/math/rect2.h
index 9017377770..0d2e7eb6e5 100644
--- a/core/math/rect2.h
+++ b/core/math/rect2.h
@@ -60,6 +60,19 @@ struct Rect2 {
return true;
}
+ inline bool intersects_touch(const Rect2 &p_rect) const {
+ if (position.x > (p_rect.position.x + p_rect.size.width))
+ return false;
+ if ((position.x + size.width) < p_rect.position.x)
+ return false;
+ if (position.y > (p_rect.position.y + p_rect.size.height))
+ return false;
+ if ((position.y + size.height) < p_rect.position.y)
+ return false;
+
+ return true;
+ }
+
inline real_t distance_to(const Vector2 &p_point) const {
real_t dist = 0.0;
diff --git a/core/message_queue.cpp b/core/message_queue.cpp
index 64ceec5ee4..42390935d4 100644
--- a/core/message_queue.cpp
+++ b/core/message_queue.cpp
@@ -250,7 +250,7 @@ void MessageQueue::_call_function(Object *p_target, const StringName &p_func, co
p_target->call(p_func, argptrs, p_argcount, ce);
if (p_show_error && ce.error != Variant::CallError::CALL_OK) {
- ERR_PRINTS("Error calling deferred method: " + Variant::get_call_error_text(p_target, p_func, argptrs, p_argcount, ce) + ".");
+ ERR_PRINT("Error calling deferred method: " + Variant::get_call_error_text(p_target, p_func, argptrs, p_argcount, ce) + ".");
}
}
diff --git a/core/object.cpp b/core/object.cpp
index 21a3b2cc6c..937b1ae8d4 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -1225,7 +1225,7 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int
if (ce.error == Variant::CallError::CALL_ERROR_INVALID_METHOD && !ClassDB::class_exists(target->get_class_name())) {
//most likely object is not initialized yet, do not throw error.
} else {
- ERR_PRINTS("Error calling method from signal '" + String(p_name) + "': " + Variant::get_call_error_text(target, c.method, args, argc, ce) + ".");
+ ERR_PRINT("Error calling method from signal '" + String(p_name) + "': " + Variant::get_call_error_text(target, c.method, args, argc, ce) + ".");
err = ERR_METHOD_NOT_FOUND;
}
}
@@ -1945,7 +1945,7 @@ Object::~Object() {
if (_emitting) {
//@todo this may need to actually reach the debugger prioritarily somehow because it may crash before
- ERR_PRINTS("Object " + to_string() + " was freed or unreferenced while a signal is being emitted from it. Try connecting to the signal using 'CONNECT_DEFERRED' flag, or use queue_free() to free the object (if this object is a Node) to avoid this error and potential crashes.");
+ ERR_PRINT("Object " + to_string() + " was freed or unreferenced while a signal is being emitted from it. Try connecting to the signal using 'CONNECT_DEFERRED' flag, or use queue_free() to free the object (if this object is a Node) to avoid this error and potential crashes.");
}
while ((S = signal_map.next(NULL))) {
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp
index 0477db82be..f65fc00077 100644
--- a/core/os/dir_access.cpp
+++ b/core/os/dir_access.cpp
@@ -285,7 +285,7 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
FileAccess *fsrc = FileAccess::open(p_from, FileAccess::READ, &err);
if (err) {
- ERR_PRINTS("Failed to open " + p_from);
+ ERR_PRINT("Failed to open " + p_from);
return err;
}
@@ -294,7 +294,7 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
fsrc->close();
memdelete(fsrc);
- ERR_PRINTS("Failed to open " + p_to);
+ ERR_PRINT("Failed to open " + p_to);
return err;
}
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 1ed9484208..7e5c9d6ef8 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -188,7 +188,7 @@ int OS::get_process_id() const {
void OS::vibrate_handheld(int p_duration_ms) {
- WARN_PRINTS("vibrate_handheld() only works with Android and iOS");
+ WARN_PRINT("vibrate_handheld() only works with Android and iOS");
}
bool OS::is_stdout_verbose() const {
diff --git a/core/project_settings.cpp b/core/project_settings.cpp
index a01a8a35c6..59d7e82850 100644
--- a/core/project_settings.cpp
+++ b/core/project_settings.cpp
@@ -206,7 +206,7 @@ bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const {
name = feature_overrides[name];
}
if (!props.has(name)) {
- WARN_PRINTS("Property not found: " + String(name));
+ WARN_PRINT("Property not found: " + String(name));
return false;
}
r_ret = props[name].variant;
@@ -579,7 +579,7 @@ Error ProjectSettings::_load_settings_text(const String &p_path) {
_convert_to_last_version(config_version);
return OK;
} else if (err != OK) {
- ERR_PRINTS("Error parsing " + p_path + " at line " + itos(lines) + ": " + error_text + " File might be corrupted.");
+ ERR_PRINT("Error parsing " + p_path + " at line " + itos(lines) + ": " + error_text + " File might be corrupted.");
memdelete(f);
return err;
}
@@ -612,7 +612,7 @@ Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path,
return OK;
} else if (err_text != ERR_FILE_NOT_FOUND) {
// If the text-based file exists but can't be loaded, we want to know it
- ERR_PRINTS("Couldn't load file '" + p_text_path + "', error code " + itos(err_text) + ".");
+ ERR_PRINT("Couldn't load file '" + p_text_path + "', error code " + itos(err_text) + ".");
return err_text;
}
diff --git a/core/translation.cpp b/core/translation.cpp
index 02297cffc8..cf76de1c9e 100644
--- a/core/translation.cpp
+++ b/core/translation.cpp
@@ -966,7 +966,7 @@ void TranslationServer::set_locale(const String &p_locale) {
print_verbose(vformat("Unsupported locale '%s', falling back to '%s'.", p_locale, trimmed_locale));
if (!is_locale_valid(trimmed_locale)) {
- ERR_PRINTS(vformat("Unsupported locale '%s', falling back to 'en'.", trimmed_locale));
+ ERR_PRINT(vformat("Unsupported locale '%s', falling back to 'en'.", trimmed_locale));
locale = "en";
} else {
locale = trimmed_locale;
diff --git a/core/type_info.h b/core/type_info.h
index c9b2055241..68bc1cc554 100644
--- a/core/type_info.h
+++ b/core/type_info.h
@@ -277,7 +277,7 @@ struct GetTypeInfo<const T *, typename EnableIf<TypeInherits<Object, T>::value>:
template <typename T>
inline StringName __constant_get_enum_name(T param, const String &p_constant) {
if (GetTypeInfo<T>::VARIANT_TYPE == Variant::NIL)
- ERR_PRINTS("Missing VARIANT_ENUM_CAST for constant's enum: " + p_constant);
+ ERR_PRINT("Missing VARIANT_ENUM_CAST for constant's enum: " + p_constant);
return GetTypeInfo<T>::get_class_info().class_name;
}
diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp
index 5d1144e1f5..577879d448 100644
--- a/core/undo_redo.cpp
+++ b/core/undo_redo.cpp
@@ -293,7 +293,7 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
Variant::CallError ce;
obj->call(op.name, (const Variant **)argptrs.ptr(), argc, ce);
if (ce.error != Variant::CallError::CALL_OK) {
- ERR_PRINTS("Error calling method from signal '" + String(op.name) + "': " + Variant::get_call_error_text(obj, op.name, (const Variant **)argptrs.ptr(), argc, ce));
+ ERR_PRINT("Error calling method from signal '" + String(op.name) + "': " + Variant::get_call_error_text(obj, op.name, (const Variant **)argptrs.ptr(), argc, ce));
}
#ifdef TOOLS_ENABLED
Resource *res = Object::cast_to<Resource>(obj);
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 8a1fbfd383..08418463a0 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -3324,7 +3324,7 @@ String String::humanize_size(uint64_t p_size) {
int prefix_idx = 0;
- while (prefix_idx < prefixes.size() && p_size > (_div * 1024)) {
+ while (prefix_idx < prefixes.size() - 1 && p_size > (_div * 1024)) {
_div *= 1024;
prefix_idx++;
}