Browse Source

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.
pull/518/head
Vladimír Vondruš 5 years ago
parent
commit
2f24199ed7
  1. 6
      src/Magnum/GL/AbstractShaderProgram.cpp
  2. 20
      src/Magnum/GL/Test/MeshGLTest.cpp

6
src/Magnum/GL/AbstractShaderProgram.cpp

@ -386,9 +386,9 @@ void AbstractShaderProgram::draw(Containers::ArrayView<const Containers::Referen
use();
#ifndef CORRADE_NO_ASSERT
const Mesh* original = &meshes.begin()->get()._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

20
src/Magnum/GL/Test/MeshGLTest.cpp

@ -25,6 +25,7 @@
#include <sstream>
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/FormatStl.h>
#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<std::uintptr_t>(&a), reinterpret_cast<std::uintptr_t>(&b)));
}
}}}}
CORRADE_TEST_MAIN(Magnum::GL::Test::MeshGLTest)

Loading…
Cancel
Save