mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
gpu,gpu/headless: plug a resource leak when taking screenshots
Ever since commit 8ff654628, the headless implementation has used two
GPU backend (not renderer) instances, one for the renderer and one for
creating the offscreen texture to render into. This arrangment leaks
resources because the backends only clear temporary storage at
BeginFrame, which is not called when reading pixel data from renders.
This change adds an internal constructor, gpu.NewWithDevice, to allow
headless.Window to share its device with the renderer, fixing the leak.
It also makes the code simpler (took me a while to debug this issue); in
fact I'm surprised it even works.
This is not a great fix: it adds an exported yet internal constructor,
and the ownership transfer of the device is surprising enough to warrant
two comments.
Fixes gio#322
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -296,11 +296,19 @@ const (
|
||||
materialTexture
|
||||
)
|
||||
|
||||
// New creates a GPU for the given API.
|
||||
func New(api API) (GPU, error) {
|
||||
d, err := driver.NewDevice(api)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewWithDevice(d)
|
||||
}
|
||||
|
||||
// NewWithDevice creates a GPU with a pre-existing device.
|
||||
//
|
||||
// Note: for internal use only.
|
||||
func NewWithDevice(d driver.Device) (GPU, error) {
|
||||
d.BeginFrame(nil, false, image.Point{})
|
||||
defer d.EndFrame()
|
||||
forceCompute := os.Getenv("GIORENDERER") == "forcecompute"
|
||||
|
||||
Reference in New Issue
Block a user