Check shaderblock offset exists before reading. Prevents a segfault

This commit is contained in:
mcc 2020-06-04 12:10:56 -04:00
parent ada79dbf5d
commit 0dcf86bc3d
1 changed files with 3 additions and 2 deletions

View File

@ -19,8 +19,9 @@ static int l_lovrShaderBlockGetSize(lua_State* L) {
static int l_lovrShaderBlockGetOffset(lua_State* L) {
ShaderBlock* block = luax_checktype(L, 1, ShaderBlock);
const char* field = luaL_checkstring(L, 2);
const Uniform* uniform = lovrShaderBlockGetUniform(block, field);
const char* name = luaL_checkstring(L, 2);
const Uniform* uniform = lovrShaderBlockGetUniform(block, name);
lovrAssert(uniform, "Unknown uniform for ShaderBlock '%s'", name);
lua_pushinteger(L, uniform->offset);
return 1;
}