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

Intended way to cleanup resources associated with canvas #52

Open
smolderant opened this issue Sep 4, 2017 · 1 comment
Open

Intended way to cleanup resources associated with canvas #52

smolderant opened this issue Sep 4, 2017 · 1 comment

Comments

@smolderant
Copy link

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.

@faiface
Copy link
Owner

faiface commented Sep 7, 2017

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.

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

2 participants