From f72d62ce8795f16ee4a73b35e956378a93982cce Mon Sep 17 00:00:00 2001 From: CodingJellyfish Date: Thu, 19 Dec 2024 18:26:47 +0800 Subject: [PATCH] Fix invalid memory access --- src/graphics/sp/sp_base.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/graphics/sp/sp_base.cpp b/src/graphics/sp/sp_base.cpp index cc9265b33ee..f05fd30cec0 100644 --- a/src/graphics/sp/sp_base.cpp +++ b/src/graphics/sp/sp_base.cpp @@ -123,7 +123,7 @@ unsigned g_skinning_offset = 0; // ---------------------------------------------------------------------------- std::vector g_skinning_mesh; // ---------------------------------------------------------------------------- -int g_skinning_tbo_limit = 0; +bool g_skinning_use_tbo = false; // ---------------------------------------------------------------------------- int sp_cur_shadow_cascade = 0; // ---------------------------------------------------------------------------- @@ -319,12 +319,13 @@ void initSkinning() else { #ifndef USE_GLES2 - glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &g_skinning_tbo_limit); - if (stk_config->m_max_skinning_bones << 6 > (unsigned)g_skinning_tbo_limit) + int skinning_tbo_limit; + glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &skinning_tbo_limit); + if (stk_config->m_max_skinning_bones << 6 > (unsigned)skinning_tbo_limit) { Log::warn("SharedGPUObjects", "Too many bones for skinning, max: %d", - g_skinning_tbo_limit >> 6); - stk_config->m_max_skinning_bones = g_skinning_tbo_limit >> 6; + skinning_tbo_limit >> 6); + stk_config->m_max_skinning_bones = skinning_tbo_limit >> 6; } Log::info("SharedGPUObjects", "Hardware Skinning enabled, method: TBO, " "max bones: %u", stk_config->m_max_skinning_bones); @@ -444,7 +445,14 @@ void init() if (CVS->isARBTextureBufferObjectUsable()) { - glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE_ARB, &g_skinning_tbo_limit); + int skinning_tbo_limit; + glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE_ARB, &skinning_tbo_limit); + + g_skinning_use_tbo = skinning_tbo_limit >= stk_config->m_max_skinning_bones << 6; + } + else + { + g_skinning_use_tbo = false; } initSkinning(); @@ -655,8 +663,7 @@ SPShader* getNormalVisualizer() // ---------------------------------------------------------------------------- bool skinningUseTBO() { - return CVS->isARBTextureBufferObjectUsable() - && g_skinning_tbo_limit >= 64 * stk_config->m_max_skinning_bones; + return g_skinning_use_tbo; }