From 88522fe600f8d07488a85b76ade555dcca64439f Mon Sep 17 00:00:00 2001 From: maj00r Date: Sun, 15 Nov 2026 23:09:49 +0100 Subject: [PATCH] fix(renderer): the legacy renderer clears the arrays the scene left before it draws the ui The legacy renderer drew the ui with the client arrays of the last scene draw still enabled: the texture coordinates of the normal map unit and the normals, pointing into the vertex buffer of whatever was drawn last, 48 bytes a vertex. The ImGui backend sets up the vertex, colour and texture coordinates of the active unit only, so the driver read the stale arrays with the indices of the ui. Once the ui had more vertices than that buffer, the NVIDIA driver read past its end and the game crashed; a crash dump of the editor (an area selected, a track being laid) shows the read of vertex 15113 at a 48-byte stride in ImGui_ImplOpenGL2_RenderDrawData. The arrays are now disabled on every texture unit the geometry uses, with the normal and colour arrays, inside the glPushClientAttrib already there, so the scene gets its state back after the ui. The default and the experimental renderers don't go through this code. --- rendering/openglrenderer.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rendering/openglrenderer.cpp b/rendering/openglrenderer.cpp index 71bd7d0ef..d27f56099 100644 --- a/rendering/openglrenderer.cpp +++ b/rendering/openglrenderer.cpp @@ -419,6 +419,15 @@ opengl_renderer::Render() { // add user interface setup_units( true, false, false ); ::glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); + // the arrays the scene left enabled point into the buffer of whatever was drawn last; the ui sets up + // the vertex, colour and texture coordinates of the active unit only, so the driver would go on reading + // the rest with the indices of the ui, past the end of that buffer once the ui has more vertices than it + for( auto const unit : m_geometry.units().texture ) { + ::glClientActiveTexture( GL_TEXTURE0 + unit ); + ::glDisableClientState( GL_TEXTURE_COORD_ARRAY ); + } + ::glDisableClientState( GL_NORMAL_ARRAY ); + ::glDisableClientState( GL_COLOR_ARRAY ); ::glClientActiveTexture( GL_TEXTURE0 + m_diffusetextureunit ); // clear state for ui