summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRay <[email protected]>2022-11-29 10:45:10 +0100
committerRay <[email protected]>2022-11-29 10:45:10 +0100
commit2edf5a958484f8dc8fb6d3be14606852b696e379 (patch)
tree0ea806fc369d817a81099475e937a2b6e7956bb9
parent50a716c0d91f90e73f1fe2b910b3f7426a0d1360 (diff)
downloadraylib-2edf5a958484f8dc8fb6d3be14606852b696e379.tar.gz
raylib-2edf5a958484f8dc8fb6d3be14606852b696e379.zip
REVIEWED: Issue with shader linkage
-rw-r--r--src/rcore.c11
-rw-r--r--src/rlgl.h6
2 files changed, 11 insertions, 6 deletions
diff --git a/src/rcore.c b/src/rcore.c
index 8f5b63b1..118a5736 100644
--- a/src/rcore.c
+++ b/src/rcore.c
@@ -2446,10 +2446,6 @@ Shader LoadShader(const char *vsFileName, const char *fsFileName)
Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode)
{
Shader shader = { 0 };
- shader.locs = (int *)RL_CALLOC(RL_MAX_SHADER_LOCATIONS, sizeof(int));
-
- // NOTE: All locations must be reseted to -1 (no location)
- for (int i = 0; i < RL_MAX_SHADER_LOCATIONS; i++) shader.locs[i] = -1;
shader.id = rlLoadShaderCode(vsCode, fsCode);
@@ -2465,6 +2461,11 @@ Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode)
// vertex texcoord2 location = 5
// NOTE: If any location is not found, loc point becomes -1
+
+ shader.locs = (int *)RL_CALLOC(RL_MAX_SHADER_LOCATIONS, sizeof(int));
+
+ // All locations reseted to -1 (no location)
+ for (int i = 0; i < RL_MAX_SHADER_LOCATIONS; i++) shader.locs[i] = -1;
// Get handles to GLSL input attibute locations
shader.locs[SHADER_LOC_VERTEX_POSITION] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION);
@@ -2497,6 +2498,8 @@ void UnloadShader(Shader shader)
if (shader.id != rlGetShaderIdDefault())
{
rlUnloadShaderProgram(shader.id);
+
+ // NOTE: If shader loading failed, it should be 0
RL_FREE(shader.locs);
}
}
diff --git a/src/rlgl.h b/src/rlgl.h
index 04fcf8f9..e4f65d69 100644
--- a/src/rlgl.h
+++ b/src/rlgl.h
@@ -3643,12 +3643,14 @@ unsigned int rlLoadShaderCode(const char *vsCode, const char *fsCode)
// NOTE: We detach shader before deletion to make sure memory is freed
if (vertexShaderId != RLGL.State.defaultVShaderId)
{
- glDetachShader(id, vertexShaderId);
+ // WARNING: Shader program linkage could fail and returned id is 0
+ if (id > 0) glDetachShader(id, vertexShaderId);
glDeleteShader(vertexShaderId);
}
if (fragmentShaderId != RLGL.State.defaultFShaderId)
{
- glDetachShader(id, fragmentShaderId);
+ // WARNING: Shader program linkage could fail and returned id is 0
+ if (id > 0) glDetachShader(id, fragmentShaderId);
glDeleteShader(fragmentShaderId);
}