Browse Source

Corrected crash on shader loading

If shader file could not be found on loading it crashed, instead added
fallback to default shader!
pull/421/head
Ray 7 years ago
parent
commit
2388cbc3cd
1 changed files with 30 additions and 19 deletions
  1. +30
    -19
      src/rlgl.c

+ 30
- 19
src/rlgl.c View File

@ -2365,38 +2365,49 @@ Shader LoadShader(char *vsFileName, char *fsFileName)
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
unsigned int vertexShaderId, fragmentShaderId;
unsigned int vertexShaderId = defaultVShaderId;
unsigned int fragmentShaderId = defaultFShaderId;
if (vsFileName == NULL) vertexShaderId = defaultVShaderId;
else
if (vsFileName != NULL)
{
char *vShaderStr = LoadText(vsFileName);
vertexShaderId = CompileShader(vShaderStr, GL_VERTEX_SHADER);
free(vShaderStr);
if (vShaderStr != NULL)
{
vertexShaderId = CompileShader(vShaderStr, GL_VERTEX_SHADER);
free(vShaderStr);
}
}
if (fsFileName == NULL) fragmentShaderId = defaultVShaderId;
else
if (fsFileName != NULL)
{
char* fShaderStr = LoadText(fsFileName);
fragmentShaderId = CompileShader(fShaderStr, GL_FRAGMENT_SHADER);
free(fShaderStr);
if (fShaderStr != NULL)
{
fragmentShaderId = CompileShader(fShaderStr, GL_FRAGMENT_SHADER);
free(fShaderStr);
}
}
shader.id = LoadShaderProgram(vertexShaderId, fragmentShaderId);
if ((vertexShaderId == defaultVShaderId) && (fragmentShaderId == defaultFShaderId)) shader = defaultShader;
else
{
shader.id = LoadShaderProgram(vertexShaderId, fragmentShaderId);
if (vertexShaderId != defaultVShaderId) glDeleteShader(vertexShaderId);
if (fragmentShaderId != defaultFShaderId) glDeleteShader(fragmentShaderId);
if (vertexShaderId != defaultVShaderId) glDeleteShader(vertexShaderId);
if (fragmentShaderId != defaultFShaderId) glDeleteShader(fragmentShaderId);
if (shader.id == 0)
{
TraceLog(LOG_WARNING, "Custom shader could not be loaded");
shader = defaultShader;
if (shader.id == 0)
{
TraceLog(LOG_WARNING, "Custom shader could not be loaded");
shader = defaultShader;
}
// After shader loading, we TRY to set default location names
if (shader.id > 0) SetShaderDefaultLocations(&shader);
}
// After shader loading, we TRY to set default location names
if (shader.id > 0) SetShaderDefaultLocations(&shader);
// Get available shader uniforms
// NOTE: This information is useful for debug...
int uniformCount = -1;

Loading…
Cancel
Save