My use case is that I'm creating a domain-specific language for doing 3d modelling. And in the language, I've got a function for displaying what's currently built -- using g3n. (g3n has a lot built-in that makes my use case easier than using go-gl directly would be. Plus, I'm not that strong on the lower-level GLFW stuff.) Specifically why I'm looking to be able to display a g3n window again after closing one is:
- I'd like to support calling that function multiple times in the same run of the program in my language such that the code can build part of it, display, build more, display again, etc. (Or, perhaps displaying multiple times in a loop, for instance.) Plus it's a pretty artificial limitation to say that can only be called once per run.
- I've built a REPL for my language, and I definitely want to be able to support allowing users to rerun a command that included a call to that display function a second time without requiring the user to exit the REPL and re-enter it.
- I've also built a playground which runs my language's runtime in the browser with Web Assembly (super cool, and my use case doesn't need asset loading or audio, neither of which are supported by g3n yet.) If users type some code with a call to that display function, run it, then exit the in-browser g3n viewer, then edit the code and run it again, I want it to be able to display the viewer a second time without requiring a refresh of the whole page.
When I try to display a second time on Linux, I get the error message ! NotInitialized: The GLFW library is not initialized. I suspect this may be because after the main loop ends, the Destroy() function on the *GlfwWindow calls glfw.Terminate(). Thereafter, it's no longer initialized. Attempting to call window.Init(width, height int, title string) error results in a panic (on purpose, it seems.) I confess I do not know enough about glfw to understand if and if so why it's necessary to prevent that function from running twice.
The way I'm doing things in the playground, I'd like to call the Exit() function on the singleton *Application instance when they hide the viewer, just so that it doesn't eat up performance in the background while it's not actually displaying. Because there's no way to reset the private exit field on the singleton *Application instance, when I try to display a second time in WASM, it displays the first frame (as in, it runs the main loop for one iteration, but no more) before exiting because the exit field is true.
A minimal code example that will reproduce the ! NotInitialized: The GLFW library is not initialized error follows:
package main
import (
"time"
"github.com/g3n/engine/app"
"github.com/g3n/engine/renderer"
)
func main() {
a := app.App()
a.Exit()
a.Run(func(renderer *renderer.Renderer, deltaTime time.Duration) {})
a.Run(func(renderer *renderer.Renderer, deltaTime time.Duration) {})
}
I'm not sure if there's some way to accomplish what I'm hoping that I've overlooked. But I'm hoping what I'm trying to do isn't a lost cause.
My use case is that I'm creating a domain-specific language for doing 3d modelling. And in the language, I've got a function for displaying what's currently built -- using g3n. (g3n has a lot built-in that makes my use case easier than using go-gl directly would be. Plus, I'm not that strong on the lower-level GLFW stuff.) Specifically why I'm looking to be able to display a g3n window again after closing one is:
When I try to display a second time on Linux, I get the error message
! NotInitialized: The GLFW library is not initialized. I suspect this may be because after the main loop ends, theDestroy()function on the*GlfwWindowcallsglfw.Terminate(). Thereafter, it's no longer initialized. Attempting to callwindow.Init(width, height int, title string) errorresults in a panic (on purpose, it seems.) I confess I do not know enough about glfw to understand if and if so why it's necessary to prevent that function from running twice.The way I'm doing things in the playground, I'd like to call the
Exit()function on the singleton*Applicationinstance when they hide the viewer, just so that it doesn't eat up performance in the background while it's not actually displaying. Because there's no way to reset the privateexitfield on the singleton*Applicationinstance, when I try to display a second time in WASM, it displays the first frame (as in, it runs the main loop for one iteration, but no more) before exiting because theexitfield is true.A minimal code example that will reproduce the
! NotInitialized: The GLFW library is not initializederror follows:I'm not sure if there's some way to accomplish what I'm hoping that I've overlooked. But I'm hoping what I'm trying to do isn't a lost cause.