pixel icon indicating copy to clipboard operation
pixel copied to clipboard

Intended way to cleanup resources associated with canvas

Open smolderant opened this issue 6 years ago • 1 comments

Hello,

I've been messing around with pixelgl canvas stuff learning enough from your lights demo to get going. Drawing to a canvas and then drawing that canvas to the main window seems like a good approach for various GUI elements to just show a portion of the GUI content at a time (in combination with a scrollbar for example) (if there's another approach you'd recommend let me know!).

I was working on some code to implement GUI element creation and noticed that there is some resource leak when I draw a sprite to a canvas that I'm not sure how to clean up, it appears to be in the glhf space, and the canvas has a function to give you the frame for example but its delete() function is not exported. I didn't dig very far into glhf yet, as I'm looking for the right approach to cleanup things created with pixelgl using pixelgl.

Here's an example of the resource leak, the framerate should be visible in your window title. I don't intend to actually create a new canvas every frame, but I am interested in what I am supposed to do to get the framerate to be stable with this code rather than now where the framerate steadily deteriorates from ~350fps to <20 in my case over the course of 30 seconds. Below is the code in question that is within a render loop.

testCanvas := pixelgl.NewCanvas(pixel.R(0, 0, 30, 30)) testCanvas.SetComposeMethod(pixel.ComposeOver) testCanvas.Clear(colornames.Antiquewhite) gs.sprite.Draw(testCanvas, pixel.IM.Moved(testCanvas.Bounds().Center()))//framerate is stable without this line testCanvas.Draw(win, pixel.IM.Moved(win.Bounds().Center()))

I would appreciate any insight here, thanks for reading.

smolderant avatar Sep 04 '17 04:09 smolderant

Hi, I'm sorry I didn't respond earlier, I was pretty busy.

So, the intended way to release such resources is through the garbage collector. All GLHF objects have associated finalizers which deallocate the OpenGL resources associated with the objects.

It's possible that I have a bug and I'm not releasing some OpenGL object. I'll take a look at it ASAP when I have time.

faiface avatar Sep 07 '17 17:09 faiface