From 28f5d5a07c189cde32aab5d24269785d6fc5f95e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jul 2025 19:57:42 +0200 Subject: [PATCH] GL: assume object is created if it's already bound somewhere. The assertions triggered by the tests added in previous commit no longer fire. --- src/Magnum/GL/AbstractFramebuffer.cpp | 12 +++++++++++- src/Magnum/GL/AbstractTexture.cpp | 12 +++++++++++- src/Magnum/GL/Buffer.cpp | 12 +++++++++++- src/Magnum/GL/Mesh.cpp | 12 +++++++++++- src/Magnum/GL/Renderbuffer.cpp | 12 +++++++++++- src/Magnum/GL/TransformFeedback.cpp | 12 +++++++++++- 6 files changed, 66 insertions(+), 6 deletions(-) diff --git a/src/Magnum/GL/AbstractFramebuffer.cpp b/src/Magnum/GL/AbstractFramebuffer.cpp index f6d0a0b72..3238fee2e 100644 --- a/src/Magnum/GL/AbstractFramebuffer.cpp +++ b/src/Magnum/GL/AbstractFramebuffer.cpp @@ -112,7 +112,17 @@ void AbstractFramebuffer::createIfNotAlready() { require the object to be created. Binding the framebuffer finally creates it. Also all EXT DSA functions implicitly create it. */ bindInternal(); - CORRADE_INTERNAL_ASSERT(_flags & ObjectFlag::Created); + + /* In some cases, such as when this function is called on a object created + using wrap(), ObjectFlag::Created might not be set but bindInternal() + above was a no-op as the object was already bound somewhere. In that + case assume that, since it's bound, it's already created, and we just + didn't know. See the wrapCreateIfNotAlready() test for a repro case. + + Note that the branch is done this way instead of an unconditional |= to + make code coverage report that this codepath is indeed tested. */ + if(!(_flags >= ObjectFlag::Created)) + _flags |= ObjectFlag::Created; } #endif diff --git a/src/Magnum/GL/AbstractTexture.cpp b/src/Magnum/GL/AbstractTexture.cpp index 2dd69f534..4c4b633d6 100644 --- a/src/Magnum/GL/AbstractTexture.cpp +++ b/src/Magnum/GL/AbstractTexture.cpp @@ -261,7 +261,17 @@ void AbstractTexture::createIfNotAlready() { directly and they require the object to be created. Binding the texture to desired target finally creates it. */ bindInternal(); - CORRADE_INTERNAL_ASSERT(_flags & ObjectFlag::Created); + + /* In some cases, such as when this function is called on a object created + using wrap(), ObjectFlag::Created might not be set but bindInternal() + above was a no-op as the object was already bound somewhere. In that + case assume that, since it's bound, it's already created, and we just + didn't know. See the wrapCreateIfNotAlready() test for a repro case. + + Note that the branch is done this way instead of an unconditional |= to + make code coverage report that this codepath is indeed tested. */ + if(!(_flags >= ObjectFlag::Created)) + _flags |= ObjectFlag::Created; } #endif diff --git a/src/Magnum/GL/Buffer.cpp b/src/Magnum/GL/Buffer.cpp index 03021a0b4..e38bf9568 100644 --- a/src/Magnum/GL/Buffer.cpp +++ b/src/Magnum/GL/Buffer.cpp @@ -240,7 +240,17 @@ void Buffer::createIfNotAlready() { buffer finally creates it. Also all EXT DSA functions implicitly create it. */ bindSomewhereInternal(_targetHint); - CORRADE_INTERNAL_ASSERT(_flags & ObjectFlag::Created); + + /* In some cases, such as when this function is called on a object created + using wrap(), ObjectFlag::Created might not be set but bindInternal() + above was a no-op as the object was already bound somewhere. In that + case assume that, since it's bound, it's already created, and we just + didn't know. See the wrapCreateIfNotAlready() test for a repro case. + + Note that the branch is done this way instead of an unconditional |= to + make code coverage report that this codepath is indeed tested. */ + if(!(_flags >= ObjectFlag::Created)) + _flags |= ObjectFlag::Created; } #endif diff --git a/src/Magnum/GL/Mesh.cpp b/src/Magnum/GL/Mesh.cpp index 958ef59d4..7c7e4473c 100644 --- a/src/Magnum/GL/Mesh.cpp +++ b/src/Magnum/GL/Mesh.cpp @@ -401,7 +401,17 @@ inline void Mesh::createIfNotAlready() { require the object to be created. Binding the VAO finally creates it. Also all EXT DSA functions implicitly create it. */ bindVAO(); - CORRADE_INTERNAL_ASSERT(_flags & ObjectFlag::Created); + + /* In some cases, such as when this function is called on a object created + using wrap(), ObjectFlag::Created might not be set but bindVAO() above + was a no-op as the object was already bound somewhere. In that case + assume that, since it's bound, it's already created, and we just didn't + know. See the wrapCreateIfNotAlready() test for a repro case. + + Note that the branch is done this way instead of an unconditional |= to + make code coverage report that this codepath is indeed tested. */ + if(!(_flags >= ObjectFlag::Created)) + _flags |= ObjectFlag::Created; } #endif diff --git a/src/Magnum/GL/Renderbuffer.cpp b/src/Magnum/GL/Renderbuffer.cpp index 07ece4ec9..fab4281ee 100644 --- a/src/Magnum/GL/Renderbuffer.cpp +++ b/src/Magnum/GL/Renderbuffer.cpp @@ -108,7 +108,17 @@ inline void Renderbuffer::createIfNotAlready() { require the object to be created. Binding the renderbuffer finally creates it. Also all EXT DSA functions implicitly create it. */ bind(); - CORRADE_INTERNAL_ASSERT(_flags & ObjectFlag::Created); + + /* In some cases, such as when this function is called on a object created + using wrap(), ObjectFlag::Created might not be set but bind() above was + a no-op as the object was already bound somewhere. In that case assume + that, since it's bound, it's already created, and we just didn't know. + See the wrapCreateIfNotAlready() test for a repro case. + + Note that the branch is done this way instead of an unconditional |= to + make code coverage report that this codepath is indeed tested. */ + if(!(_flags >= ObjectFlag::Created)) + _flags |= ObjectFlag::Created; } #endif diff --git a/src/Magnum/GL/TransformFeedback.cpp b/src/Magnum/GL/TransformFeedback.cpp index 86d73ec0c..17f5b2bae 100644 --- a/src/Magnum/GL/TransformFeedback.cpp +++ b/src/Magnum/GL/TransformFeedback.cpp @@ -162,7 +162,17 @@ inline void TransformFeedback::createIfNotAlready() { require the object to be created. Binding the transform feedback finally creates it. Also all EXT DSA functions implicitly create it. */ bindInternal(); - CORRADE_INTERNAL_ASSERT(_flags & ObjectFlag::Created); + + /* In some cases, such as when this function is called on a object created + using wrap(), ObjectFlag::Created might not be set but bindInternal() + above was a no-op as the object was already bound somewhere. In that + case assume that, since it's bound, it's already created, and we just + didn't know. See the wrapCreateIfNotAlready() test for a repro case. + + Note that the branch is done this way instead of an unconditional |= to + make code coverage report that this codepath is indeed tested. */ + if(!(_flags >= ObjectFlag::Created)) + _flags |= ObjectFlag::Created; } #endif