Skip to content

Commit d75e626

Browse files
committed
lazy initialize go-gl/gl on first texture frame
1 parent 0e810c5 commit d75e626

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

application.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,6 @@ func (a *Application) Run() error {
232232
texturer := newRegistry(a.engine, a.window)
233233
a.engine.GLExternalTextureFrameCallback = texturer.handleExternalTexture
234234

235-
texturer.init()
236-
237235
// Not very nice, but we can only really fix this when there's a pluggable
238236
// renderer.
239237
defaultTextinputPlugin.keyboardLayout = a.config.keyboardLayout

texture-registry.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import (
1010
"github.com/pkg/errors"
1111
)
1212

13+
// once is used for the lazy initialization of go-gl/gl.
14+
// The initialization occur on the first requested texture's frame.
15+
var once sync.Once
16+
1317
// TextureRegistry is a registry entry for a managed Texture.
1418
type TextureRegistry struct {
1519
window *glfw.Window
@@ -90,6 +94,10 @@ func (t *TextureRegistry) setTextureHandler(textureID int64, handler ExternalTex
9094
func (t *TextureRegistry) handleExternalTexture(textureID int64,
9195
width int, height int) *embedder.FlutterOpenGLTexture {
9296

97+
once.Do(func() {
98+
t.init()
99+
})
100+
93101
t.channelsLock.RLock()
94102
registration, registrationExists := t.channels[textureID]
95103
t.channelsLock.RUnlock()

0 commit comments

Comments
 (0)