From 7907bb43ce7f03e11bd67dff2429a1cd936d550f Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 25 Aug 2019 17:32:32 +0900 Subject: [PATCH] shareable: Refactoring: reduce sync.Once --- internal/shareable/shareable.go | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/internal/shareable/shareable.go b/internal/shareable/shareable.go index 05d4e5960..75f021791 100644 --- a/internal/shareable/shareable.go +++ b/internal/shareable/shareable.go @@ -47,26 +47,10 @@ func min(a, b int) int { } func init() { - var once sync.Once hooks.AppendHookOnBeforeUpdate(func() error { backendsM.Lock() defer backendsM.Unlock() - once.Do(func() { - if len(theBackends) != 0 { - panic("shareable: all the images must be not-shared before the game starts") - } - if graphicsDriver.HasHighPrecisionFloat() { - minSize = 1024 - // Use 4096 as a maximum size whatever size the graphics driver accepts. There are - // not enough evidences that bigger textures works correctly. - maxSize = min(4096, graphicsDriver.MaxImageSize()) - } else { - minSize = 512 - maxSize = 512 - } - }) - resolveDeferred() makeImagesShared() return nil @@ -612,6 +596,21 @@ func BeginFrame() error { var err error initOnce.Do(func() { err = restorable.InitializeGraphicsDriverState() + if err != nil { + return + } + if len(theBackends) != 0 { + panic("shareable: all the images must be not-shared before the game starts") + } + if graphicsDriver.HasHighPrecisionFloat() { + minSize = 1024 + // Use 4096 as a maximum size whatever size the graphics driver accepts. There are + // not enough evidences that bigger textures works correctly. + maxSize = min(4096, graphicsDriver.MaxImageSize()) + } else { + minSize = 512 + maxSize = 512 + } }) if err != nil { return err