소스 검색

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 년 전
부모
커밋
2388cbc3cd
1개의 변경된 파일30개의 추가작업 그리고 19개의 파일을 삭제
  1. +30
    -19
      src/rlgl.c

+ 30
- 19
src/rlgl.c 파일 보기

@ -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;

불러오는 중...
취소
저장