File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -8,11 +8,14 @@ import (
88 _ "image/png"
99 "os"
1010 "path/filepath"
11- "runtime"
1211
1312 "github.com/AllenDang/cimgui-go/imgui"
1413)
1514
15+ // Texture implements a simple texture loader. It wraps backend's methods to allow creating textures easily.
16+ // IMPORTANT: as the texture is mainly handled by C OpenGL, it is not covered by Garbae Collector (GC).
17+ //
18+ // Remember to call (*Texture).Release when you no longer need it.
1619type Texture struct {
1720 ID imgui.TextureID
1821 Width int
@@ -28,13 +31,16 @@ func NewTextureFromRgba(rgba *image.RGBA) *Texture {
2831 Height : rgba .Bounds ().Dy (),
2932 }
3033
31- // Set finalizer
32- runtime .SetFinalizer (& texture , (* Texture ).release )
34+ // I leav it for documentation here:
35+ // GC runs in a separated thread so this may not work correctly (will crash opengl)
36+ // runtime.SetFinalizer(&texture, (*Texture).release)
3337
3438 return & texture
3539}
3640
37- func (t * Texture ) release () {
41+ // Release tells OpenGL that this texture is no longer needed.
42+ // ATTENTION: This will not be automatically handled by GC so remember to do it manually if you have many textures!
43+ func (t * Texture ) Release () {
3844 textureManager .DeleteTexture (t .ID )
3945}
4046
You can’t perform that action at this time.
0 commit comments