Slightly improved error messages when love.graphics.newShader fails

This commit is contained in:
Alex Szpakowski
2013-03-16 12:49:46 -03:00
parent f9d687cb65
commit e8c6a3f77c
+13 -3
View File
@@ -505,8 +505,6 @@ int w_newShader(lua_State *L)
if (!Shader::isSupported()) if (!Shader::isSupported())
return luaL_error(L, "Sorry, your graphics card does not support shaders."); return luaL_error(L, "Sorry, your graphics card does not support shaders.");
try
{
// clamp stack to 2 elements // clamp stack to 2 elements
lua_settop(L, 2); lua_settop(L, 2);
@@ -535,10 +533,22 @@ int w_newShader(lua_State *L)
sources[Shader::TYPE_FRAGMENT] = fragcode; sources[Shader::TYPE_FRAGMENT] = fragcode;
} }
if (sources.empty())
{
// Original args had source code, but effectCodeToGLSL couldn't translate it
for (int i = 1; i <= 2; i++)
{
if (lua_isstring(L, i))
return luaL_argerror(L, i, "invalid or incomplete shader code");
}
}
try
{
Shader *shader = instance->newShader(sources); Shader *shader = instance->newShader(sources);
luax_newtype(L, "Shader", GRAPHICS_SHADER_T, (void *)shader); luax_newtype(L, "Shader", GRAPHICS_SHADER_T, (void *)shader);
} }
catch(const love::Exception &e) catch (const love::Exception &e)
{ {
// memory is freed in Graphics::newShader // memory is freed in Graphics::newShader
luax_getfunction(L, "graphics", "_transformGLSLErrorMessages"); luax_getfunction(L, "graphics", "_transformGLSLErrorMessages");