Skip texture binding when texture setup has failed

RenderStateTextureBindings::setupTextures() ignores the return value of
Texture::setupTexture(). When setup fails, the texture is deleted and left
without a valid OpenGL id, but applyOpenGL() still calls Texture::bind(),
where CVF_ASSERT on the id aborts the application.

Skip bindings without a valid texture id and log a render error instead.
This commit is contained in:
Magne Sjaastad
2026-08-19 07:26:27 +02:00
parent 43a925c3f0
commit 71090bdc18
@@ -237,6 +237,14 @@ void RenderStateTextureBindings::applyOpenGL(OpenGLContext* oglContext) const
const Sampler* sampler = m_bindings[i].sampler.p();
CVF_ASSERT(texture && sampler);
// Texture setup in setupTextures() can fail at run-time, leaving the texture without a valid OpenGL id.
// Skip the binding in that case, as Texture::bind() asserts on an invalid id.
if (texture->textureOglId() == 0)
{
CVF_LOG_RENDER_ERROR(oglContext, "Skipping texture binding, texture has not been set up.");
continue;
}
cvfGL->glActiveTexture(static_cast<GLenum>(GL_TEXTURE0 + i));
texture->bind(oglContext);