From ce19599fecc5866d0ad5295514505106ae0f752f Mon Sep 17 00:00:00 2001 From: bjorn Date: Tue, 31 Jul 2018 23:07:28 -0700 Subject: [PATCH] Improve uniform error messages; --- src/api/types/shader.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/api/types/shader.c b/src/api/types/shader.c index bef66c26..d4e753d9 100644 --- a/src/api/types/shader.c +++ b/src/api/types/shader.c @@ -27,17 +27,18 @@ int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* des case UNIFORM_FLOAT: case UNIFORM_MATRIX: capacity = blob->size / sizeof(float); - lovrAssert(capacity >= elements, "Blob can only hold %d float%s, at least %d needed", capacity, s, elements); + lovrAssert(capacity >= elements, "Blob can only hold %d float%s, at least %d needed for uniform '%s'", capacity, s, elements, debug); memcpy(dest, blob->data, elements * sizeof(float)); break; case UNIFORM_INT: capacity = blob->size / sizeof(int); - lovrAssert(capacity >= elements, "Blob can only hold %d int%s, at least %d needed", capacity, s, elements); + lovrAssert(capacity >= elements, "Blob can only hold %d int%s, at least %d needed for uniform '%s'", capacity, s, elements, debug); memcpy(dest, blob->data, elements * sizeof(int)); break; - default: lovrThrow(""); // TODO + case UNIFORM_SAMPLER: + lovrThrow("Texture uniform '%s' can not be updated with a Blob", debug); } return 0; @@ -47,7 +48,7 @@ int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* des bool isTable = lua_istable(L, index); if (isTable) { int length = lua_objlen(L, index); - lovrAssert(length == count, ""); // TODO + length = MIN(length, count); for (int i = 0; i < length; i++) { lua_rawgeti(L, index, i + 1); switch (uniform->type) { @@ -76,7 +77,7 @@ int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* des if (wrappedTable) { int length = lua_objlen(L, index); - lovrAssert(length == count, ""); // TODO + length = MIN(length, count); for (int i = 0; i < length; i++) { lua_rawgeti(L, index, i + 1); @@ -97,8 +98,7 @@ int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* des *((int*) dest + i * components + j) = luaL_checkinteger(L, -1); break; - default: - lovrThrow(""); // TODO + case UNIFORM_SAMPLER: lovrThrow("Unreachable"); } lua_pop(L, 1); } @@ -125,7 +125,7 @@ int luax_checkuniform(lua_State* L, int index, const Uniform* uniform, void* des *((float*) dest + i * components + j) = luaL_checknumber(L, -1); break; - default: lovrThrow(""); // TODO + case UNIFORM_SAMPLER: lovrThrow("Unreachable"); } } }