From fe6a2daef4507cc7a74b27ddf906198545720a6d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 14 Oct 2020 01:55:32 +0900 Subject: [PATCH] graphicsdriver/metal: Bug fix: Had to set the vsync state again at resetting Fixes #1364 --- examples/windowsize/main.go | 7 ++++++- internal/graphicsdriver/metal/view.go | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/windowsize/main.go b/examples/windowsize/main.go index cacba5ea3..7beb8bc99 100644 --- a/examples/windowsize/main.go +++ b/examples/windowsize/main.go @@ -231,7 +231,12 @@ func (g *game) Update() error { } else { ebiten.SetCursorMode(ebiten.CursorModeHidden) } - ebiten.SetVsyncEnabled(vsyncEnabled) + + // Set vsync enabled only when this is needed. + // This makes a bug around vsync initialization more explicit (#1364). + if vsyncEnabled != ebiten.IsVsyncEnabled() { + ebiten.SetVsyncEnabled(vsyncEnabled) + } ebiten.SetMaxTPS(tps) ebiten.SetWindowDecorated(decorated) ebiten.SetWindowPosition(positionX, positionY) diff --git a/internal/graphicsdriver/metal/view.go b/internal/graphicsdriver/metal/view.go index eabc526f7..996bf2761 100644 --- a/internal/graphicsdriver/metal/view.go +++ b/internal/graphicsdriver/metal/view.go @@ -28,6 +28,7 @@ type view struct { uiview uintptr windowChanged bool + vsync bool device mtl.Device ml ca.MetalLayer @@ -45,6 +46,7 @@ func (v *view) getMTLDevice() mtl.Device { func (v *view) setDisplaySyncEnabled(enabled bool) { v.ml.SetDisplaySyncEnabled(enabled) + v.vsync = enabled } func (v *view) colorPixelFormat() mtl.PixelFormat { @@ -67,6 +69,9 @@ func (v *view) reset() error { // MTLPixelFormatBGRA10_XR_sRGB. v.ml.SetPixelFormat(mtl.PixelFormatBGRA8UNorm) v.ml.SetMaximumDrawableCount(3) + + // The vsync state might be reset. Set the state again (#1364). + v.ml.SetDisplaySyncEnabled(v.vsync) return nil }