Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple windows bug: sprite on one window deletes shapes on other window #32

Open
duysqubix opened this issue Oct 10, 2023 · 0 comments

Comments

@duysqubix
Copy link
Contributor

When using multiple windows, I get glitches when using imdraw shapes on one window and a sprite on another one. Below is some code that reproduces the issue:
Window W1 only briefly shows the drawn white rectangle. Almost instantly, or after a short while, it disappears. When commenting out the line that draws the sprite, everything workd fine.

OS: Windows 10

Minimal reproducing example:

package main

import (
	"image/color"

	"github.com/faiface/pixel"
	"github.com/faiface/pixel/imdraw"
	"github.com/faiface/pixel/pixelgl"
	"golang.org/x/image/colornames"
)

func main() {
	pixelgl.Run(run)
}

func run() {
	w1 := createWindow("W1")
	w2 := createWindow("W2")

	draw := *imdraw.New(nil)

	for !w1.Closed() && !w2.Closed() {
		// Draw shapes on window 1
		w1.Clear(colornames.Black)
		draw.Color = colornames.White
		draw.Push(pixel.V(10, 10), pixel.V(700, 500))
		draw.Rectangle(0)
		draw.Draw(w1)
		draw.Reset()
		draw.Clear()
		w1.Update()

		// Draw a sprite on window 2
		w2.Clear(colornames.Black)
		picture := pixel.MakePictureData(pixel.R(0, 0, 100, 100))
		for i := 0; i < len(picture.Pix); i++ {
			picture.Pix[i] = color.RGBA{R: 255, G: 255, B: 255, A: 200}
		}
		sprite := pixel.NewSprite(picture, picture.Bounds())
		// This call seems to be the problem
		sprite.Draw(w2, pixel.IM)
		w2.Update()
	}
}

func createWindow(title string) *pixelgl.Window {
	cfg := pixelgl.WindowConfig{
		Title:  title,
		Bounds: pixel.R(0, 0, 800, 600),
	}

	window, err := pixelgl.NewWindow(cfg)
	if err != nil {
		panic(err)
	}
	return window
}

Original issue: faiface/pixel#314

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant