소스 검색

Make sure to detach data before deleting

Before deleting certain objects, they must be detached from their parents. That's the case for shader objects after linkage to shader program and also for the texture/cubemaps/renderbuffers attached to framebuffers. If objects are deleted before detached, they are kept in memory to avoid accessing deleted data.
pull/1381/head
raysan5 4 년 전
부모
커밋
90befff4b8
1개의 변경된 파일33개의 추가작업 그리고 7개의 파일을 삭제
  1. +33
    -7
      src/rlgl.h

+ 33
- 7
src/rlgl.h 파일 보기

@ -1456,11 +1456,23 @@ void rlDeleteTextures(unsigned int id)
void rlDeleteRenderTextures(RenderTexture2D target)
{
#if (defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)) && defined(SUPPORT_RENDER_TEXTURES_HINT)
if (target.texture.id > 0) glDeleteTextures(1, &target.texture.id);
if (target.texture.id > 0)
{
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); // Detach texture from FBO
glDeleteTextures(1, &target.texture.id);
}
if (target.depth.id > 0)
{
if (target.depthTexture) glDeleteTextures(1, &target.depth.id);
else glDeleteRenderbuffers(1, &target.depth.id);
if (target.depthTexture)
{
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
glDeleteTextures(1, &target.depth.id);
}
else
{
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
glDeleteRenderbuffers(1, &target.depth.id);
}
}
if (target.id > 0) glDeleteFramebuffers(1, &target.id);
@ -1483,8 +1495,12 @@ void rlDeleteVertexArrays(unsigned int id)
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
if (RLGL.ExtSupported.vao)
{
if (id != 0) glDeleteVertexArrays(1, &id);
TRACELOG(LOG_INFO, "VAO: [ID %i] Unloaded vertex data from VRAM (GPU)", id);
if (id != 0)
{
glBindVertexArray(0);
glDeleteVertexArrays(1, &id);
TRACELOG(LOG_INFO, "VAO: [ID %i] Unloaded vertex data from VRAM (GPU)", id);
}
}
#endif
}
@ -3094,8 +3110,18 @@ Shader LoadShaderCode(const char *vsCode, const char *fsCode)
{
shader.id = LoadShaderProgram(vertexShaderId, fragmentShaderId);
if (vertexShaderId != RLGL.State.defaultVShaderId) glDeleteShader(vertexShaderId);
if (fragmentShaderId != RLGL.State.defaultFShaderId) glDeleteShader(fragmentShaderId);
if (vertexShaderId != RLGL.State.defaultVShaderId)
{
// Detach shader before deletion to make sure memory is freed
glDetachShader(shader.id, vertexShaderId);
glDeleteShader(vertexShaderId);
}
if (fragmentShaderId != RLGL.State.defaultFShaderId)
{
// Detach shader before deletion to make sure memory is freed
glDetachShader(shader.id, fragmentShaderId);
glDeleteShader(fragmentShaderId);
}
if (shader.id == 0)
{

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