summaryrefslogtreecommitdiffstats
path: root/core/error/error_macros.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/error/error_macros.cpp')
-rw-r--r--core/error/error_macros.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/core/error/error_macros.cpp b/core/error/error_macros.cpp
index 8376c0aaf8..813ee7684f 100644
--- a/core/error/error_macros.cpp
+++ b/core/error/error_macros.cpp
@@ -34,6 +34,12 @@
#include "core/os/os.h"
#include "core/string/ustring.h"
+// Optional physics interpolation warnings try to include the path to the relevant node.
+#if defined(DEBUG_ENABLED) && defined(TOOLS_ENABLED)
+#include "core/config/project_settings.h"
+#include "scene/main/node.h"
+#endif
+
static ErrorHandlerList *error_handler_list = nullptr;
void add_error_handler(ErrorHandlerList *p_handler) {
@@ -128,3 +134,48 @@ void _err_print_index_error(const char *p_function, const char *p_file, int p_li
void _err_flush_stdout() {
fflush(stdout);
}
+
+// Prevent error spam by limiting the warnings to a certain frequency.
+void _physics_interpolation_warning(const char *p_function, const char *p_file, int p_line, ObjectID p_id, const char *p_warn_string) {
+#if defined(DEBUG_ENABLED) && defined(TOOLS_ENABLED)
+ const uint32_t warn_max = 2048;
+ const uint32_t warn_timeout_seconds = 15;
+
+ static uint32_t warn_count = warn_max;
+ static uint32_t warn_timeout = warn_timeout_seconds;
+
+ uint32_t time_now = UINT32_MAX;
+
+ if (warn_count) {
+ warn_count--;
+ }
+
+ if (!warn_count) {
+ time_now = OS::get_singleton()->get_ticks_msec() / 1000;
+ }
+
+ if ((warn_count == 0) && (time_now >= warn_timeout)) {
+ warn_count = warn_max;
+ warn_timeout = time_now + warn_timeout_seconds;
+
+ if (GLOBAL_GET("debug/settings/physics_interpolation/enable_warnings")) {
+ // UINT64_MAX means unused.
+ if (p_id.operator uint64_t() == UINT64_MAX) {
+ _err_print_error(p_function, p_file, p_line, "[Physics interpolation] " + String(p_warn_string) + " (possibly benign).", false, ERR_HANDLER_WARNING);
+ } else {
+ String node_name;
+ if (p_id.is_valid()) {
+ Node *node = Object::cast_to<Node>(ObjectDB::get_instance(p_id));
+ if (node && node->is_inside_tree()) {
+ node_name = "\"" + String(node->get_path()) + "\"";
+ } else {
+ node_name = "\"unknown\"";
+ }
+ }
+
+ _err_print_error(p_function, p_file, p_line, "[Physics interpolation] " + String(p_warn_string) + ": " + node_name + " (possibly benign).", false, ERR_HANDLER_WARNING);
+ }
+ }
+ }
+#endif
+}