Skip to content

Commit

Permalink
graphicsdriver/metal: Bug fix: Had to set the vsync state again at re…
Browse files Browse the repository at this point in the history
…setting

Fixes hajimehoshi#1364
  • Loading branch information
hajimehoshi committed Oct 13, 2020
1 parent 01be505 commit fe55854
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/windowsize/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,12 @@ func (g *game) Update(screen *ebiten.Image) error {
ebiten.SetFullscreen(fullscreen)
ebiten.SetRunnableOnUnfocused(runnableOnUnfocused)
ebiten.SetCursorVisible(cursorVisible)
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)
Expand Down
5 changes: 5 additions & 0 deletions internal/graphicsdriver/metal/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type view struct {
uiview uintptr

windowChanged bool
vsync bool

device mtl.Device
ml ca.MetalLayer
Expand All @@ -48,6 +49,7 @@ func (v *view) setDisplaySyncEnabled(enabled bool) {
// recursive function call via Run is forbidden.
// Fix this to use d.t.Run to avoid confusion.
v.ml.SetDisplaySyncEnabled(enabled)
v.vsync = enabled
}

func (v *view) colorPixelFormat() mtl.PixelFormat {
Expand All @@ -70,6 +72,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
}

Expand Down

0 comments on commit fe55854

Please sign in to comment.