From 2f24199ed7008b2930972b9f3bf48cdef5b8b836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 24 Apr 2021 20:07:18 +0200 Subject: [PATCH] GL: improve message for the common mesh assert in multi-draw. In my case I was using a dangling MeshView reference there, and it was hard to debug without these. --- src/Magnum/GL/AbstractShaderProgram.cpp | 6 +++--- src/Magnum/GL/Test/MeshGLTest.cpp | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Magnum/GL/AbstractShaderProgram.cpp b/src/Magnum/GL/AbstractShaderProgram.cpp index 5f228b827..05685f68e 100644 --- a/src/Magnum/GL/AbstractShaderProgram.cpp +++ b/src/Magnum/GL/AbstractShaderProgram.cpp @@ -386,9 +386,9 @@ void AbstractShaderProgram::draw(Containers::ArrayViewget()._original.get(); - for(MeshView& mesh: meshes) - CORRADE_ASSERT(&mesh._original.get() == original, "GL::AbstractShaderProgram::draw(): all meshes must be views of the same original mesh", ); + const Mesh* original = &*meshes.front()->_original; + for(std::size_t i = 0; i != meshes.size(); ++i) + CORRADE_ASSERT(&*meshes[i]->_original == original, "GL::AbstractShaderProgram::draw(): all meshes must be views of the same original mesh, expected" << original << "but got" << &*meshes[i]->_original << "at index" << i, ); #endif #ifndef MAGNUM_TARGET_GLES diff --git a/src/Magnum/GL/Test/MeshGLTest.cpp b/src/Magnum/GL/Test/MeshGLTest.cpp index df17de288..f58b3a598 100644 --- a/src/Magnum/GL/Test/MeshGLTest.cpp +++ b/src/Magnum/GL/Test/MeshGLTest.cpp @@ -25,6 +25,7 @@ #include #include +#include #include "Magnum/Image.h" #include "Magnum/Mesh.h" @@ -189,6 +190,7 @@ struct MeshGLTest: OpenGLTester { #ifdef MAGNUM_TARGET_GLES void multiDrawBaseVertexNoExtensionAvailable(); #endif + void multiDrawDifferentMeshes(); }; MeshGLTest::MeshGLTest() { @@ -335,9 +337,9 @@ MeshGLTest::MeshGLTest() { &MeshGLTest::multiDrawBaseVertex, #endif #ifdef MAGNUM_TARGET_GLES - &MeshGLTest::multiDrawBaseVertexNoExtensionAvailable + &MeshGLTest::multiDrawBaseVertexNoExtensionAvailable, #endif - }); + &MeshGLTest::multiDrawDifferentMeshes}); } using namespace Math::Literals; @@ -3456,6 +3458,20 @@ void MeshGLTest::multiDrawBaseVertexNoExtensionAvailable() { } #endif +void MeshGLTest::multiDrawDifferentMeshes() { + #ifdef CORRADE_NO_ASSERT + CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); + #endif + + Mesh a, b; + MeshView viewA{a}, viewB{b}; + + std::ostringstream out; + Error redirectError{&out}; + MultipleShader{}.draw({viewA, viewB}); + CORRADE_COMPARE(out.str(), Utility::formatString("GL::AbstractShaderProgram::draw(): all meshes must be views of the same original mesh, expected 0x{:x} but got 0x{:x} at index 1\n", reinterpret_cast(&a), reinterpret_cast(&b))); +} + }}}} CORRADE_TEST_MAIN(Magnum::GL::Test::MeshGLTest)