diff --git a/engine/static/scripting/include/argus/scripting/types.hpp b/engine/static/scripting/include/argus/scripting/types.hpp index 13caa727..99c6fbd3 100644 --- a/engine/static/scripting/include/argus/scripting/types.hpp +++ b/engine/static/scripting/include/argus/scripting/types.hpp @@ -18,6 +18,8 @@ #pragma once +#include "argus/core/engine.hpp" + #include #include #include @@ -251,7 +253,7 @@ namespace argus { template [[nodiscard]] const T &at(size_t index) const { if (sizeof(T) != m_element_size) { - throw std::invalid_argument("Template parameter size does not match element size"); + crash("Template parameter size does not match element size"); } return *reinterpret_cast(this->operator[](index)); } @@ -341,7 +343,7 @@ namespace argus { template void set(size_t index, const E &val) { if (sizeof(E) != m_element_size) { - throw std::invalid_argument("Template type size does not match element size of VectorWrapper"); + crash("Template type size does not match element size of VectorWrapper"); } set(index, reinterpret_cast(&val)); } diff --git a/engine/static/scripting/include/argus/scripting/wrapper.hpp b/engine/static/scripting/include/argus/scripting/wrapper.hpp index 688aa530..1de324f2 100644 --- a/engine/static/scripting/include/argus/scripting/wrapper.hpp +++ b/engine/static/scripting/include/argus/scripting/wrapper.hpp @@ -252,7 +252,7 @@ namespace argus { VectorWrapper *wrapper = reinterpret_cast(obj); return wrapper->get_underlying_vector(); } else { - throw std::runtime_error("Invalid vector object type magic"); + crash("Invalid vector object type magic"); } } else if constexpr (is_reference_wrapper_v) { assert(param.type.type == IntegralType::Pointer); diff --git a/engine/static/scripting/src/bind.cpp b/engine/static/scripting/src/bind.cpp index 9b3afd1e..4239b57f 100644 --- a/engine/static/scripting/src/bind.cpp +++ b/engine/static/scripting/src/bind.cpp @@ -225,6 +225,10 @@ namespace argus { CopyCtorProxy copy_ctor, MoveCtorProxy move_ctor, DtorProxy dtor) { + if (size == 0) { + crash("Bound types cannot be zero-sized"); + } + BoundTypeDef def { name, size, diff --git a/engine/static/scripting/src/types.cpp b/engine/static/scripting/src/types.cpp index 33cbbfb4..c37db48a 100644 --- a/engine/static/scripting/src/types.cpp +++ b/engine/static/scripting/src/types.cpp @@ -248,7 +248,7 @@ namespace argus { m_count(count), m_element_dtor(element_dtor) { if (element_size == 0) { - throw std::invalid_argument("Element size must be greater than zero"); + crash("Element size must be greater than zero"); } } @@ -274,7 +274,7 @@ namespace argus { void *ArrayBlob::operator[](size_t index) { if (index >= m_count) { - throw std::invalid_argument("Index is out of bounds"); + crash("ArrayBlob index is out of bounds"); } return reinterpret_cast(reinterpret_cast(m_blob) + (m_element_size * index)); @@ -283,7 +283,7 @@ namespace argus { const void *ArrayBlob::operator[](size_t index) const { //return const_cast(const_cast(this)->operator[](index)); if (index >= m_count) { - throw std::invalid_argument("Index is out of bounds"); + crash("ArrayBlob index is out of bounds"); } return reinterpret_cast(reinterpret_cast(m_blob) + (m_element_size * index)); @@ -336,8 +336,8 @@ namespace argus { const void *VectorWrapper::at(size_t index) const { auto size = (*m_get_size_fn)(m_underlying_vec); if (index >= size) { - throw std::out_of_range("Index " + std::to_string(index) - + " is out of range in vector of size " + std::to_string(size)); + crash("Index " + std::to_string(index) + + " is out of range in VectorWrapper of size " + std::to_string(size)); } return reinterpret_cast(reinterpret_cast((*m_get_element_fn)(m_underlying_vec, index))); diff --git a/engine/static/scripting/src/wrapper.cpp b/engine/static/scripting/src/wrapper.cpp index 5de370e9..7b8019e6 100644 --- a/engine/static/scripting/src/wrapper.cpp +++ b/engine/static/scripting/src/wrapper.cpp @@ -183,18 +183,18 @@ namespace argus { ObjectType &el_type = *vec_type.element_type.value(); if (el_type.type == IntegralType::Void) { - throw std::invalid_argument("Vectors of void are not supported"); + crash("Vectors of void are not supported"); } else if (el_type.type == IntegralType::Callback) { - throw std::invalid_argument("Vectors of callbacks are not supported"); + crash("Vectors of callbacks are not supported"); } else if (el_type.type == IntegralType::Type) { - throw std::invalid_argument("Vectors of types are not supported"); + crash("Vectors of types are not supported"); } else if (el_type.type == IntegralType::Vector) { - throw std::invalid_argument("Vectors of vectors are not supported"); + crash("Vectors of vectors are not supported"); } else if (el_type.type == IntegralType::Boolean) { - // C++ is stupid and specializes std::vector as a bitfield, - // which fucks with our assumptions about how we can tinker with - // the vector. Much easier to just not support it. - throw std::invalid_argument("Vectors of booleans are not supported"); + // C++ is stupid and specializes std::vector as a bitfield + // which messes up our assumptions about how we can tinker with the + // vector. Much easier to just not support it. + crash("Vectors of booleans are not supported"); } } diff --git a/engine/static/scripting_lua/src/lua_language_plugin.cpp b/engine/static/scripting_lua/src/lua_language_plugin.cpp index 1741668b..77a86d72 100644 --- a/engine/static/scripting_lua/src/lua_language_plugin.cpp +++ b/engine/static/scripting_lua/src/lua_language_plugin.cpp @@ -607,7 +607,7 @@ namespace argus { case 8: return *reinterpret_cast(wrapper.value); default: - throw std::invalid_argument("Bad floating-point width " + std::to_string(wrapper.type.size) + crash("Bad floating-point width " + std::to_string(wrapper.type.size) + " (must be 4, or 8)"); } }