From 044839bb816f69c1deec7cceee401e4e7a30ff95 Mon Sep 17 00:00:00 2001 From: mrq Date: Sat, 23 Aug 2025 15:58:38 -0500 Subject: [PATCH] bug hunting through address sanitizer (at least for opengl) --- .gitignore | 4 ++++ engine/inc/uf/ext/opengl/buffer.h | 2 ++ engine/inc/uf/utils/math/matrix/pod.inl | 4 ++-- engine/inc/uf/utils/math/vector/pod.inl | 4 ++-- engine/inc/uf/utils/userdata/pointered.inl | 8 +++++--- engine/src/ext/opengl/buffer.cpp | 2 +- engine/src/ext/opengl/shader.cpp | 2 +- engine/src/spec/context/linux.cpp | 8 ++++---- engine/src/utils/audio/emitter.cpp | 10 +++++++--- 9 files changed, 28 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 58aeefb8..df6f77ab 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,9 @@ *.cdi *.gdi +# Other stuff that's a pain when doing cross-arch stuff +default/ + # Assets *.gz *.png @@ -55,6 +58,7 @@ *.ttf *.otf *.bin + models/ llm/ tmp/ \ No newline at end of file diff --git a/engine/inc/uf/ext/opengl/buffer.h b/engine/inc/uf/ext/opengl/buffer.h index c6dc531d..00bf944e 100644 --- a/engine/inc/uf/ext/opengl/buffer.h +++ b/engine/inc/uf/ext/opengl/buffer.h @@ -81,11 +81,13 @@ namespace ext { size_t initializeBuffer( const void*, GLsizeiptr, GLenum, bool = false ); bool updateBuffer( const void*, GLsizeiptr, const Buffer&, bool = false ) const; + /* inline size_t initializeBuffer( void* data, GLsizeiptr length, GLenum usage, bool alias = false ) { return initializeBuffer( (const void*) data, length, usage, alias ); } template inline size_t initializeBuffer( const T& data, GLsizeiptr length, GLenum usage, bool alias = false ) { return initializeBuffer( (const void*) &data, length, usage, alias ); } template inline size_t initializeBuffer( const T& data, GLenum usage, bool alias = false ) { return initializeBuffer( (const void*) &data, static_cast(sizeof(T)), usage, alias ); } inline bool updateBuffer( const void* data, GLsizeiptr length, size_t index = 0, bool alias = false ) const { return updateBuffer( data, length, buffers.at(index), alias ); } + */ /* inline bool updateBuffer( const void* data, GLsizeiptr length, size_t index = 0, bool alias = false ) const { return updateBuffer( data, length, buffers.at(index), alias ); } inline bool updateBuffer( void* data, GLsizeiptr length, size_t index = 0, bool alias = false ) const { return updateBuffer( (const void*) data, length, index, alias ); } diff --git a/engine/inc/uf/utils/math/matrix/pod.inl b/engine/inc/uf/utils/math/matrix/pod.inl index dd1dad3a..5ee98827 100644 --- a/engine/inc/uf/utils/math/matrix/pod.inl +++ b/engine/inc/uf/utils/math/matrix/pod.inl @@ -649,7 +649,7 @@ template pod::Matrix& /*UF_API*/ uf::matrix::decode( const ext::json::Value& json, pod::Matrix& m ) { if ( ext::json::isArray(json) ) #pragma unroll // GCC unroll T::size - for ( uint_fast8_t i = 0; i < R*C; ++i ) + for ( uint_fast8_t i = 0; i < R*C && i < json.size(); ++i ) m[i] = json[i].as(m[i]); else if ( ext::json::isObject(json) ) { uint_fast8_t i = 0; @@ -667,7 +667,7 @@ pod::Matrix /*UF_API*/ uf::matrix::decode( const ext::json::Value& json, ALIGN16 pod::Matrix m = _m; if ( ext::json::isArray(json) ) #pragma unroll // GCC unroll T::size - for ( uint_fast8_t i = 0; i < R*C; ++i ) + for ( uint_fast8_t i = 0; i < R*C && i < json.size(); ++i ) m[i] = json[i].as(_m[i]); else if ( ext::json::isObject(json) ) { uint_fast8_t i = 0; diff --git a/engine/inc/uf/utils/math/vector/pod.inl b/engine/inc/uf/utils/math/vector/pod.inl index 4bd4ca9e..f1bc1af5 100644 --- a/engine/inc/uf/utils/math/vector/pod.inl +++ b/engine/inc/uf/utils/math/vector/pod.inl @@ -572,7 +572,7 @@ template pod::Vector& /*UF_API*/ uf::vector::decode( const ext::json::Value& json, pod::Vector& v ) { if ( ext::json::isArray(json) ) #pragma unroll // GCC unroll T::size - for ( auto i = 0; i < N; ++i ) + for ( auto i = 0; i < N && i < json.size(); ++i ) v[i] = json[i].as(v[i]); else if ( ext::json::isObject(json) ) { auto i = 0; @@ -589,7 +589,7 @@ pod::Vector /*UF_API*/ uf::vector::decode( const ext::json::Value& json, co pod::Vector v = _v; if ( ext::json::isArray(json) ) #pragma unroll // GCC unroll T::size - for ( auto i = 0; i < N; ++i ) + for ( auto i = 0; i < N && i < json.size(); ++i ) v[i] = json[i].as(_v[i]); else if ( ext::json::isObject(json) ) { auto i = 0; diff --git a/engine/inc/uf/utils/userdata/pointered.inl b/engine/inc/uf/utils/userdata/pointered.inl index eff3c9ca..19f05404 100644 --- a/engine/inc/uf/utils/userdata/pointered.inl +++ b/engine/inc/uf/utils/userdata/pointered.inl @@ -135,11 +135,13 @@ bool uf::pointeredUserdata::is( const pod::PointeredUserdata& userdata ) { } template const pod::UserdataTraits& uf::pointeredUserdata::registerTrait() { auto& trait = uf::userdata::traits[UF_USERDATA_CTTI(T)]; - trait.name = TYPE_NAME(T); +#if UF_DEBUG + trait.name = TYPE_NAME(T); // this sometimes causes a crash but this is only needed for debugging anywys +#endif trait.constructor = &uf::userdata::construct; trait.destructor = &uf::userdata::destruct; - return trait;} -// + return trait; +} // No need to cast data to a pointer AND get the data's size! template pod::PointeredUserdata& uf::PointeredUserdata::create( const T& data ) { diff --git a/engine/src/ext/opengl/buffer.cpp b/engine/src/ext/opengl/buffer.cpp index 51ce4bb6..4eb4e8a4 100644 --- a/engine/src/ext/opengl/buffer.cpp +++ b/engine/src/ext/opengl/buffer.cpp @@ -103,7 +103,7 @@ void ext::opengl::Buffer::allocate( const CreateInfo& bufferCreateInfo ) { this->destroy(); if ( !device ) device = &ext::opengl::device; - this->buffer = device->createBuffer( bufferCreateInfo.usage, bufferCreateInfo.size, nullptr, bufferCreateInfo.aliased ); + this->buffer = device->createBuffer( bufferCreateInfo.usage, bufferCreateInfo.size, NULL, bufferCreateInfo.aliased ); this->usage = bufferCreateInfo.usage; this->size = bufferCreateInfo.size; diff --git a/engine/src/ext/opengl/shader.cpp b/engine/src/ext/opengl/shader.cpp index 13f759b5..e556a5fb 100644 --- a/engine/src/ext/opengl/shader.cpp +++ b/engine/src/ext/opengl/shader.cpp @@ -82,7 +82,7 @@ void ext::opengl::Shader::initialize( ext::opengl::Device& device, const uf::stl } } if ( metadata.autoInitializeUniformBuffers ) { - initializeBuffer( nullptr, sizeof(pod::Uniform), uf::renderer::enums::Buffer::UNIFORM ); + initializeBuffer( NULL, sizeof(pod::Uniform), uf::renderer::enums::Buffer::UNIFORM ); } #endif } diff --git a/engine/src/spec/context/linux.cpp b/engine/src/spec/context/linux.cpp index 35564d8f..62c84e6e 100644 --- a/engine/src/spec/context/linux.cpp +++ b/engine/src/spec/context/linux.cpp @@ -19,7 +19,7 @@ spec::x11::Context::Context( uni::Context* shared, const Context::Settings& sett { m_display = XOpenDisplay(NULL); if (!m_display) { - std::cerr << "Failed to open X display\n"; + UF_MSG_ERROR("Failed to open X display"); return; } @@ -29,7 +29,7 @@ spec::x11::Context::Context( uni::Context* shared, const Context::Settings& sett XSetWindowAttributes swa; swa.event_mask = StructureNotifyMask; m_window = XCreateSimpleWindow(m_display, RootWindow(m_display, scr), 0, 0, 1, 1, 0, 0, 0); - + //XMapWindow(m_display, m_window); this->create(shared); @@ -66,7 +66,7 @@ void spec::x11::Context::create( uni::Context* shared ) { int scr = DefaultScreen(m_display); XVisualInfo* vi = glXChooseVisual(m_display, scr, attribs); if (!vi) { - std::cerr << "Failed to choose visual\n"; + UF_MSG_ERROR("Failed to choose visual"); return; } @@ -74,7 +74,7 @@ void spec::x11::Context::create( uni::Context* shared ) { m_context = glXCreateContext(m_display, vi, sharedCtx, True); if (!m_context) { - std::cerr << "glXCreateContext failed\n"; + UF_MSG_ERROR("glXCreateContext failed"); } } diff --git a/engine/src/utils/audio/emitter.cpp b/engine/src/utils/audio/emitter.cpp index aa2a861b..7666d2f3 100644 --- a/engine/src/utils/audio/emitter.cpp +++ b/engine/src/utils/audio/emitter.cpp @@ -105,11 +105,15 @@ void uf::MappedAudioEmitter::update() { } } void uf::MappedAudioEmitter::cleanup( bool purge ) { - for ( auto& pair : this->m_container ) { - if ( purge || !pair.second.playing() ) { + for ( auto it = this->m_container.begin(); it != this->m_container.end(); ) { + auto& pair = *it; + if (purge || !pair.second.playing()) { pair.second.stop(); pair.second.destroy(); - this->m_container.erase(pair.first); + // because cleanup might only happen on nonplaying audio (for some reason) we're erasing here instead of just clearing the container + it = this->m_container.erase(it); + } else { + ++it; } } } \ No newline at end of file