internal/restorable: bug fix: concurrent map write

This commit is contained in:
Hajime Hoshi 2022-12-24 03:14:04 +09:00
parent 71492554a7
commit e4576a3de5

View File

@ -57,12 +57,13 @@ var (
func init() { func init() {
var wg errgroup.Group var wg errgroup.Group
var nearestIR, linearIR *shaderir.Program
wg.Go(func() error { wg.Go(func() error {
ir, err := graphics.CompileShader([]byte(builtinshader.Shader(builtinshader.FilterNearest, builtinshader.AddressUnsafe, false))) ir, err := graphics.CompileShader([]byte(builtinshader.Shader(builtinshader.FilterNearest, builtinshader.AddressUnsafe, false)))
if err != nil { if err != nil {
return fmt.Errorf("restorable: compiling the nearest shader failed: %w", err) return fmt.Errorf("restorable: compiling the nearest shader failed: %w", err)
} }
NearestFilterShader = NewShader(ir) nearestIR = ir
return nil return nil
}) })
wg.Go(func() error { wg.Go(func() error {
@ -70,10 +71,12 @@ func init() {
if err != nil { if err != nil {
return fmt.Errorf("restorable: compiling the linear shader failed: %w", err) return fmt.Errorf("restorable: compiling the linear shader failed: %w", err)
} }
LinearFilterShader = NewShader(ir) linearIR = ir
return nil return nil
}) })
if err := wg.Wait(); err != nil { if err := wg.Wait(); err != nil {
panic(err) panic(err)
} }
NearestFilterShader = NewShader(nearestIR)
LinearFilterShader = NewShader(linearIR)
} }