From 1fa80e7478a118b5d537e823dab75cd3157edb6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 2 Mar 2016 08:40:05 -0800 Subject: [PATCH] GL: Prevent memory stomp when shader has more samplers than allowed. Issue #704. --- src/renderer_gl.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index bb9b2bf2..7fc65a3d 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -3706,9 +3706,19 @@ namespace bgfx { namespace gl case GL_IMAGE_CUBE: case GL_INT_IMAGE_CUBE: case GL_UNSIGNED_INT_IMAGE_CUBE: - BX_TRACE("Sampler #%d at location %d.", m_numSamplers, loc); - m_sampler[m_numSamplers] = loc; - m_numSamplers++; + if (m_numSamplers < BX_COUNTOF(m_sampler) ) + { + BX_TRACE("Sampler #%d at location %d.", m_numSamplers, loc); + m_sampler[m_numSamplers] = loc; + m_numSamplers++; + } + else + { + BX_TRACE("Too many samplers (max: %d)! Sampler at location %d." + , BX_COUNTOF(m_sampler) + , loc + ); + } break; default: