summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/error_macros.cpp7
-rw-r--r--core/error_macros.h41
-rw-r--r--core/global_constants.cpp150
-rw-r--r--core/math/a_star.cpp1
-rw-r--r--core/os/input_event.h4
-rw-r--r--core/typedefs.h4
6 files changed, 109 insertions, 98 deletions
diff --git a/core/error_macros.cpp b/core/error_macros.cpp
index 170a22e8dd..7d85aa9001 100644
--- a/core/error_macros.cpp
+++ b/core/error_macros.cpp
@@ -97,3 +97,10 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co
_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());
+}
diff --git a/core/error_macros.h b/core/error_macros.h
index 1fa7f2c134..8d2f588706 100644
--- a/core/error_macros.h
+++ b/core/error_macros.h
@@ -76,6 +76,7 @@ void add_error_handler(ErrorHandlerList *p_handler);
void remove_error_handler(ErrorHandlerList *p_handler);
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_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 = false);
#ifndef _STR
#define _STR(m_x) #m_x
@@ -129,13 +130,13 @@ extern bool _err_error_exists;
// (*): See https://stackoverflow.com/questions/257418/do-while-0-what-is-it-good-for
-#define ERR_FAIL_INDEX(m_index, m_size) \
- do { \
- if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Index " _STR(m_index) " out of size (" _STR(m_size) ")."); \
- return; \
- } else \
- _err_error_exists = false; \
+#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; \
+ } else \
+ _err_error_exists = false; \
} while (0); // (*)
/** An index has failed if m_index<0 or m_index >=m_size, the function exists.
@@ -143,24 +144,24 @@ extern bool _err_error_exists;
* appropriate error condition from error_macros.h
*/
-#define ERR_FAIL_INDEX_V(m_index, m_size, m_retval) \
- do { \
- if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Index " _STR(m_index) " out of size (" _STR(m_size) ")."); \
- return m_retval; \
- } else \
- _err_error_exists = false; \
+#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; \
+ } else \
+ _err_error_exists = false; \
} while (0); // (*)
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
* We'll return a null reference and try to keep running.
*/
-#define CRASH_BAD_INDEX(m_index, m_size) \
- do { \
- if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
- _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Index " _STR(m_index) " out of size (" _STR(m_size) ")."); \
- GENERATE_TRAP \
- } \
+#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); // (*)
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
diff --git a/core/global_constants.cpp b/core/global_constants.cpp
index 6f58af2ccf..8bddeae69a 100644
--- a/core/global_constants.cpp
+++ b/core/global_constants.cpp
@@ -86,6 +86,8 @@ static Vector<_GlobalConstant> _global_constants;
VARIANT_ENUM_CAST(KeyList);
VARIANT_ENUM_CAST(KeyModifierMask);
+VARIANT_ENUM_CAST(ButtonList);
+VARIANT_ENUM_CAST(JoystickList);
void register_global_constants() {
@@ -367,82 +369,82 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT(KEY_MASK_GROUP_SWITCH);
// mouse
- BIND_GLOBAL_CONSTANT(BUTTON_LEFT);
- BIND_GLOBAL_CONSTANT(BUTTON_RIGHT);
- BIND_GLOBAL_CONSTANT(BUTTON_MIDDLE);
- BIND_GLOBAL_CONSTANT(BUTTON_WHEEL_UP);
- BIND_GLOBAL_CONSTANT(BUTTON_WHEEL_DOWN);
- BIND_GLOBAL_CONSTANT(BUTTON_WHEEL_LEFT);
- BIND_GLOBAL_CONSTANT(BUTTON_WHEEL_RIGHT);
- BIND_GLOBAL_CONSTANT(BUTTON_MASK_LEFT);
- BIND_GLOBAL_CONSTANT(BUTTON_MASK_RIGHT);
- BIND_GLOBAL_CONSTANT(BUTTON_MASK_MIDDLE);
+ BIND_GLOBAL_ENUM_CONSTANT(BUTTON_LEFT);
+ BIND_GLOBAL_ENUM_CONSTANT(BUTTON_RIGHT);
+ BIND_GLOBAL_ENUM_CONSTANT(BUTTON_MIDDLE);
+ BIND_GLOBAL_ENUM_CONSTANT(BUTTON_WHEEL_UP);
+ BIND_GLOBAL_ENUM_CONSTANT(BUTTON_WHEEL_DOWN);
+ BIND_GLOBAL_ENUM_CONSTANT(BUTTON_WHEEL_LEFT);
+ BIND_GLOBAL_ENUM_CONSTANT(BUTTON_WHEEL_RIGHT);
+ BIND_GLOBAL_ENUM_CONSTANT(BUTTON_MASK_LEFT);
+ BIND_GLOBAL_ENUM_CONSTANT(BUTTON_MASK_RIGHT);
+ BIND_GLOBAL_ENUM_CONSTANT(BUTTON_MASK_MIDDLE);
//joypads
- BIND_GLOBAL_CONSTANT(JOY_BUTTON_0);
- BIND_GLOBAL_CONSTANT(JOY_BUTTON_1);
- BIND_GLOBAL_CONSTANT(JOY_BUTTON_2);
- BIND_GLOBAL_CONSTANT(JOY_BUTTON_3);
- BIND_GLOBAL_CONSTANT(JOY_BUTTON_4);
- BIND_GLOBAL_CONSTANT(JOY_BUTTON_5);
- BIND_GLOBAL_CONSTANT(JOY_BUTTON_6);
- BIND_GLOBAL_CONSTANT(JOY_BUTTON_7);
- BIND_GLOBAL_CONSTANT(JOY_BUTTON_8);
- BIND_GLOBAL_CONSTANT(JOY_BUTTON_9);
- BIND_GLOBAL_CONSTANT(JOY_BUTTON_10);
- BIND_GLOBAL_CONSTANT(JOY_BUTTON_11);
- BIND_GLOBAL_CONSTANT(JOY_BUTTON_12);
- BIND_GLOBAL_CONSTANT(JOY_BUTTON_13);
- BIND_GLOBAL_CONSTANT(JOY_BUTTON_14);
- BIND_GLOBAL_CONSTANT(JOY_BUTTON_15);
- BIND_GLOBAL_CONSTANT(JOY_BUTTON_MAX);
-
- BIND_GLOBAL_CONSTANT(JOY_SONY_CIRCLE);
- BIND_GLOBAL_CONSTANT(JOY_SONY_X);
- BIND_GLOBAL_CONSTANT(JOY_SONY_SQUARE);
- BIND_GLOBAL_CONSTANT(JOY_SONY_TRIANGLE);
-
- BIND_GLOBAL_CONSTANT(JOY_XBOX_B);
- BIND_GLOBAL_CONSTANT(JOY_XBOX_A);
- BIND_GLOBAL_CONSTANT(JOY_XBOX_X);
- BIND_GLOBAL_CONSTANT(JOY_XBOX_Y);
-
- BIND_GLOBAL_CONSTANT(JOY_DS_A);
- BIND_GLOBAL_CONSTANT(JOY_DS_B);
- BIND_GLOBAL_CONSTANT(JOY_DS_X);
- BIND_GLOBAL_CONSTANT(JOY_DS_Y);
-
- BIND_GLOBAL_CONSTANT(JOY_SELECT);
- BIND_GLOBAL_CONSTANT(JOY_START);
- BIND_GLOBAL_CONSTANT(JOY_DPAD_UP);
- BIND_GLOBAL_CONSTANT(JOY_DPAD_DOWN);
- BIND_GLOBAL_CONSTANT(JOY_DPAD_LEFT);
- BIND_GLOBAL_CONSTANT(JOY_DPAD_RIGHT);
- BIND_GLOBAL_CONSTANT(JOY_L);
- BIND_GLOBAL_CONSTANT(JOY_L2);
- BIND_GLOBAL_CONSTANT(JOY_L3);
- BIND_GLOBAL_CONSTANT(JOY_R);
- BIND_GLOBAL_CONSTANT(JOY_R2);
- BIND_GLOBAL_CONSTANT(JOY_R3);
-
- BIND_GLOBAL_CONSTANT(JOY_AXIS_0);
- BIND_GLOBAL_CONSTANT(JOY_AXIS_1);
- BIND_GLOBAL_CONSTANT(JOY_AXIS_2);
- BIND_GLOBAL_CONSTANT(JOY_AXIS_3);
- BIND_GLOBAL_CONSTANT(JOY_AXIS_4);
- BIND_GLOBAL_CONSTANT(JOY_AXIS_5);
- BIND_GLOBAL_CONSTANT(JOY_AXIS_6);
- BIND_GLOBAL_CONSTANT(JOY_AXIS_7);
- BIND_GLOBAL_CONSTANT(JOY_AXIS_MAX);
-
- BIND_GLOBAL_CONSTANT(JOY_ANALOG_LX);
- BIND_GLOBAL_CONSTANT(JOY_ANALOG_LY);
-
- BIND_GLOBAL_CONSTANT(JOY_ANALOG_RX);
- BIND_GLOBAL_CONSTANT(JOY_ANALOG_RY);
-
- BIND_GLOBAL_CONSTANT(JOY_ANALOG_L2);
- BIND_GLOBAL_CONSTANT(JOY_ANALOG_R2);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_0);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_1);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_2);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_3);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_4);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_5);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_6);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_7);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_8);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_9);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_10);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_11);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_12);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_13);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_14);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_15);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_MAX);
+
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_CIRCLE);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_X);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_SQUARE);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_TRIANGLE);
+
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_B);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_A);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_X);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_XBOX_Y);
+
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_DS_A);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_DS_B);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_DS_X);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_DS_Y);
+
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_SELECT);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_START);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_DPAD_UP);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_DPAD_DOWN);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_DPAD_LEFT);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_DPAD_RIGHT);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_L);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_L2);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_L3);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_R);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_R2);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_R3);
+
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_0);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_1);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_2);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_3);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_4);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_5);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_6);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_7);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_MAX);
+
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_LX);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_LY);
+
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_RX);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_RY);
+
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_L2);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_R2);
// error list
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index 4f80fb2491..ffe1089965 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -443,4 +443,5 @@ AStar::AStar() {
AStar::~AStar() {
pass = 1;
+ clear();
}
diff --git a/core/os/input_event.h b/core/os/input_event.h
index 5dc0f91d5f..f2c8cc802d 100644
--- a/core/os/input_event.h
+++ b/core/os/input_event.h
@@ -44,7 +44,7 @@
* The events are pretty obvious.
*/
-enum {
+enum ButtonList {
BUTTON_LEFT = 1,
BUTTON_RIGHT = 2,
BUTTON_MIDDLE = 3,
@@ -58,7 +58,7 @@ enum {
};
-enum {
+enum JoystickList {
JOY_BUTTON_0 = 0,
JOY_BUTTON_1 = 1,
diff --git a/core/typedefs.h b/core/typedefs.h
index bf5c8b0f75..c509edf9fe 100644
--- a/core/typedefs.h
+++ b/core/typedefs.h
@@ -98,11 +98,11 @@ T *_nullptr() {
#undef OK
#endif
+#include "int_types.h"
+
#include "error_list.h"
#include "error_macros.h"
-#include "int_types.h"
-
/** Generic ABS function, for math uses please use Math::abs */
#ifndef ABS