From 612c4ad1dcee45a83bfbad78b7a583099024a22a Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 8 Jan 2022 19:55:14 +0100 Subject: [PATCH] Reviewed possible issue with shaders detaching --- src/rlgl.h | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/rlgl.h b/src/rlgl.h index fc5857b8..3ae8575f 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -3550,19 +3550,22 @@ unsigned int rlLoadShaderCode(const char *vsCode, const char *fsCode) if ((vertexShaderId == RLGL.State.defaultVShaderId) && (fragmentShaderId == RLGL.State.defaultFShaderId)) id = RLGL.State.defaultShaderId; else { - id = rlLoadShaderProgram(vertexShaderId, fragmentShaderId); + if ((vertexShaderId != 0) && (fragmentShaderId != 0)) + { + id = rlLoadShaderProgram(vertexShaderId, fragmentShaderId); - if (vertexShaderId != RLGL.State.defaultVShaderId) - { - // Detach shader before deletion to make sure memory is freed - glDetachShader(id, vertexShaderId); - glDeleteShader(vertexShaderId); - } - if (fragmentShaderId != RLGL.State.defaultFShaderId) - { - // Detach shader before deletion to make sure memory is freed - glDetachShader(id, fragmentShaderId); - glDeleteShader(fragmentShaderId); + if (vertexShaderId != RLGL.State.defaultVShaderId) + { + // Detach shader before deletion to make sure memory is freed + glDetachShader(id, vertexShaderId); + glDeleteShader(vertexShaderId); + } + if (fragmentShaderId != RLGL.State.defaultFShaderId) + { + // Detach shader before deletion to make sure memory is freed + glDetachShader(id, fragmentShaderId); + glDeleteShader(fragmentShaderId); + } } if (id == 0)