Kaynağa Gözat

fixed some OpenGL resource leaks

leonsal 8 yıl önce
ebeveyn
işleme
5a6f8fa684
4 değiştirilmiş dosya ile 26 ekleme ve 16 silme
  1. 5 0
      geometry/geometry.go
  2. 12 1
      gls/vbo.go
  3. 9 1
      gui/list.go
  4. 0 14
      gui/tree.go

+ 5 - 0
geometry/geometry.go

@@ -78,10 +78,15 @@ func (g *Geometry) Dispose() {
 		return
 	}
 
+	// Delete VAO and indices buffer
 	if g.gs != nil {
 		g.gs.DeleteVertexArrays(g.handleVAO)
 		g.gs.DeleteBuffers(g.handleIndices)
 	}
+	// Delete this geometry VBO buffers
+	for i := 0; i < len(g.vbos); i++ {
+		g.vbos[i].Dispose()
+	}
 	g.Init()
 }
 

+ 12 - 1
gls/vbo.go

@@ -11,7 +11,7 @@ import (
 
 // VBO abstracts an OpenGL Vertex Buffer Object
 type VBO struct {
-	gs      *GLS
+	gs      *GLS            // reference to GLS state
 	handle  uint32          // OpenGL handle for this VBO
 	usage   uint32          // Expected usage patter of the buffer
 	update  bool            // Update flag
@@ -77,6 +77,17 @@ func (vbo *VBO) AttribCount() int {
 	return len(vbo.attribs)
 }
 
+// Dispose disposes of this VBO OpenGL resources
+// As currently the VBO is used only by the Geometry object
+// it is not referenced counted.
+func (vbo *VBO) Dispose() {
+
+	if vbo.gs != nil {
+		vbo.gs.DeleteBuffers(vbo.handle)
+	}
+	vbo.gs = nil
+}
+
 // Sets the VBO buffer
 func (vbo *VBO) SetBuffer(buffer math32.ArrayF32) *VBO {
 

+ 9 - 1
gui/list.go

@@ -136,7 +136,15 @@ func (li *List) InsertAt(pos int, item IPanel) {
 // RemoveAt removes the list item from the specified position
 func (li *List) RemoveAt(pos int) IPanel {
 
-	return li.Scroller.RemoveAt(pos)
+	// Remove the list item from the internal scroller
+	pan := li.Scroller.RemoveAt(pos)
+	litem := pan.(*ListItem)
+
+	// Remove item from the list item children and disposes of the list item panel
+	item := litem.item
+	litem.Remove(item)
+	litem.Dispose()
+	return item
 }
 
 // Remove removes the specified item from the list

+ 0 - 14
gui/tree.go

@@ -128,20 +128,6 @@ func (t *Tree) Remove(child IPanel) {
 	}
 }
 
-//// Clear removes all items from the tree
-//func (t *Tree) Clear() {
-//
-//	for t.List.Len() > 0 {
-//		curr := t.List.ItemAt(0)
-//		node, ok := curr.(*TreeNode)
-//		if ok {
-//			node.remove()
-//		} else {
-//			t.List.Remove(curr)
-//		}
-//	}
-//}
-
 // Selected returns the currently selected element or nil
 func (t *Tree) Selected() IPanel {