From 11104a16d2578bfb60e6f68f09fb1e061fd0f136 Mon Sep 17 00:00:00 2001 From: aap Date: Tue, 19 Jan 2021 18:28:49 +0100 Subject: [PATCH] strdup fix --- src/gl/gl3shader.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/gl/gl3shader.cpp b/src/gl/gl3shader.cpp index 11880d3..3ca8c3d 100644 --- a/src/gl/gl3shader.cpp +++ b/src/gl/gl3shader.cpp @@ -21,6 +21,19 @@ namespace gl3 { #include "shaders/header_fs.inc" UniformRegistry uniformRegistry; +static char nameBuffer[(MAX_UNIFORMS + MAX_BLOCKS)*32]; // static because memory system isn't up yet when we register +static uint32 nameBufPtr; + +static char* +shader_strdup(const char *name) +{ + size_t len = strlen(name)+1; + char *s = &nameBuffer[nameBufPtr]; + nameBufPtr += len; + assert(nameBufPtr <= nelem(nameBuffer)); + memcpy(s, name, len); + return s; +} int32 registerUniform(const char *name) @@ -33,7 +46,7 @@ registerUniform(const char *name) assert(0 && "no space for uniform"); return -1; } - uniformRegistry.uniformNames[uniformRegistry.numUniforms] = rwStrdup(name, MEMDUR_EVENT); + uniformRegistry.uniformNames[uniformRegistry.numUniforms] = shader_strdup(name); return uniformRegistry.numUniforms++; } @@ -56,7 +69,7 @@ registerBlock(const char *name) // TODO: print error if(uniformRegistry.numBlocks+1 >= MAX_BLOCKS) return -1; - uniformRegistry.blockNames[uniformRegistry.numBlocks] = rwStrdup(name, MEMDUR_EVENT); + uniformRegistry.blockNames[uniformRegistry.numBlocks] = shader_strdup(name); return uniformRegistry.numBlocks++; }