Skip to content

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

@mlange-42

Description

@mlange-42

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions