File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import org.lwjgl.opengl.GL
1717import org.lwjgl.opengl.GL43C
1818import org.lwjgl.opengl.GLUtil
1919import org.lwjgl.system.Callback
20+ import org.lwjgl.system.MemoryStack
2021import org.lwjgl.system.MemoryUtil.*
2122import org.lwjgl.vulkan.VkInstance
2223import uno.kotlin.first
@@ -433,15 +434,23 @@ open class GlfwWindow(var handle: GlfwWindowHandle) {
433434
434435 var autoSwap = true
435436
436- inline fun loop (block : () -> Unit ) = loop({ isOpen }, block)
437+ inline fun loop (block : (MemoryStack ) -> Unit ) = loop({ isOpen }, block)
437438
438- inline fun loop (condition : () -> Boolean , block : () -> Unit ) {
439+ /* *
440+ * The `stack` passed to `block` will be automatically a stack frame in place
441+ * (i.e. it has been pushed exactly once, without popping).
442+ * So you can do any allocation on that frame without pushing/popping further
443+ * It's the user choice to pass it down the stacktrace to avoid TLS
444+ */
445+ inline fun loop (condition : () -> Boolean , block : (MemoryStack ) -> Unit ) {
439446 while (condition()) {
440447 glfwPollEvents()
441- block()
448+ val stack = MemoryStack .stackGet()
449+ block(stack.push())
442450 if (autoSwap)
443451 glfwSwapBuffers(handle)
444- appBuffer.reset()
452+ stack.pop()
453+ appBuffer.reset() // TODO delete
445454 }
446455 }
447456
You can’t perform that action at this time.
0 commit comments