mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
internal/graphicscommand: clear the queue regardless of an error
There was a potential issue that commands in the queue are never reset when an error happens and the queue continues to send errors. This is problematic especially for testings. This change fixes the issue by Go's defer.
This commit is contained in:
parent
ad0e0e3e66
commit
e21636fbb9
@ -225,6 +225,23 @@ func (q *commandQueue) flush(graphicsDriver graphicsdriver.Graphics) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
// Release the commands explicitly (#1803).
|
||||
// Apparently, the part of a slice between len and cap-1 still holds references.
|
||||
// Then, resetting the length by [:0] doesn't release the references.
|
||||
for i, c := range q.commands {
|
||||
if c, ok := c.(*drawTrianglesCommand); ok {
|
||||
q.drawTrianglesCommandPool.put(c)
|
||||
}
|
||||
q.commands[i] = nil
|
||||
}
|
||||
q.commands = q.commands[:0]
|
||||
q.nvertices = 0
|
||||
q.nindices = 0
|
||||
q.tmpNumVertexFloats = 0
|
||||
q.tmpNumIndices = 0
|
||||
}()
|
||||
|
||||
es := q.indices
|
||||
vs := q.vertices
|
||||
debug.Logf("Graphics commands:\n")
|
||||
@ -324,21 +341,6 @@ func (q *commandQueue) flush(graphicsDriver graphicsdriver.Graphics) error {
|
||||
cs = cs[nc:]
|
||||
}
|
||||
graphicsDriver.End(present)
|
||||
|
||||
// Release the commands explicitly (#1803).
|
||||
// Apparently, the part of a slice between len and cap-1 still holds references.
|
||||
// Then, resetting the length by [:0] doesn't release the references.
|
||||
for i, c := range q.commands {
|
||||
if c, ok := c.(*drawTrianglesCommand); ok {
|
||||
q.drawTrianglesCommandPool.put(c)
|
||||
}
|
||||
q.commands[i] = nil
|
||||
}
|
||||
q.commands = q.commands[:0]
|
||||
q.nvertices = 0
|
||||
q.nindices = 0
|
||||
q.tmpNumVertexFloats = 0
|
||||
q.tmpNumIndices = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user