bug hunting through address sanitizer (at least for opengl)

This commit is contained in:
mrq 2025-08-23 15:58:38 -05:00
parent 8ccf468c2a
commit 044839bb81
9 changed files with 28 additions and 16 deletions

4
.gitignore vendored
View File

@ -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/

View File

@ -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<typename T> inline size_t initializeBuffer( const T& data, GLsizeiptr length, GLenum usage, bool alias = false ) { return initializeBuffer( (const void*) &data, length, usage, alias ); }
template<typename T> inline size_t initializeBuffer( const T& data, GLenum usage, bool alias = false ) { return initializeBuffer( (const void*) &data, static_cast<GLsizeiptr>(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 ); }

View File

@ -649,7 +649,7 @@ template<typename T, size_t R, size_t C>
pod::Matrix<T,R,C>& /*UF_API*/ uf::matrix::decode( const ext::json::Value& json, pod::Matrix<T,R,C>& 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<T>(m[i]);
else if ( ext::json::isObject(json) ) {
uint_fast8_t i = 0;
@ -667,7 +667,7 @@ pod::Matrix<T,R,C> /*UF_API*/ uf::matrix::decode( const ext::json::Value& json,
ALIGN16 pod::Matrix<T,R,C> 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<T>(_m[i]);
else if ( ext::json::isObject(json) ) {
uint_fast8_t i = 0;

View File

@ -572,7 +572,7 @@ template<typename T, size_t N>
pod::Vector<T,N>& /*UF_API*/ uf::vector::decode( const ext::json::Value& json, pod::Vector<T,N>& 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<T>(v[i]);
else if ( ext::json::isObject(json) ) {
auto i = 0;
@ -589,7 +589,7 @@ pod::Vector<T,N> /*UF_API*/ uf::vector::decode( const ext::json::Value& json, co
pod::Vector<T,N> 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<T>(_v[i]);
else if ( ext::json::isObject(json) ) {
auto i = 0;

View File

@ -135,11 +135,13 @@ bool uf::pointeredUserdata::is( const pod::PointeredUserdata& userdata ) {
}
template<typename T> 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<T>;
trait.destructor = &uf::userdata::destruct<T>;
return trait;}
//
return trait;
}
// No need to cast data to a pointer AND get the data's size!
template<typename T>
pod::PointeredUserdata& uf::PointeredUserdata::create( const T& data ) {

View File

@ -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;

View File

@ -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
}

View File

@ -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");
}
}

View File

@ -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;
}
}
}