Skip to content

Commit

Permalink
fix: reduce double delete message log level to trace, add double dele…
Browse files Browse the repository at this point in the history
…te protection to FBO
  • Loading branch information
silenium-dev committed Oct 6, 2024
1 parent a54c2a6 commit 755c624
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/main/java/dev/silenium/compose/gl/fbo/FBO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import dev.silenium.compose.gl.objects.Renderbuffer
import dev.silenium.compose.gl.objects.Texture
import dev.silenium.compose.gl.util.checkGLError
import org.lwjgl.opengl.GL30.*
import org.slf4j.LoggerFactory
import java.util.concurrent.atomic.AtomicBoolean

data class FBO(
val id: Int,
Expand All @@ -23,13 +25,20 @@ data class FBO(
checkGLError("glBindFramebuffer")
}

private val destroyed = AtomicBoolean(false)
fun destroy() {
colorAttachment.destroy()
depthStencilAttachment.destroy()
glDeleteFramebuffers(id)
if (destroyed.compareAndExchange(false, true)) {
glDeleteFramebuffers(id)
colorAttachment.destroy()
depthStencilAttachment.destroy()
} else {
logger.trace("FBO $id is already destroyed", Exception())
}
}

companion object {
private val logger = LoggerFactory.getLogger(FBO::class.java)

fun create(
colorAttachment: Texture,
depthStencilAttachment: Renderbuffer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ data class Renderbuffer(
if (destroyed.compareAndExchange(false, true)) {
glDeleteRenderbuffers(id)
} else {
logger.warn("Texture $id is already destroyed")
logger.trace("Texture $id is already destroyed")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/silenium/compose/gl/objects/Texture.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data class Texture(
if (destroyed.compareAndExchange(false, true)) {
glDeleteTextures(id)
} else {
logger.warn("Texture $id is already destroyed")
logger.trace("Texture $id is already destroyed")
}
}

Expand Down

0 comments on commit 755c624

Please sign in to comment.