Skip to content

Commit

Permalink
Use updateData instead of re-creating buffers for repopulated paint a…
Browse files Browse the repository at this point in the history
…rrays.

Fixes issue #6839 (memory leak on frequent calls to setFeatureState). The leak was caused by mismatched calls to "createVertexBuffer" and "destroy".
Improves performance of PaintStates benchmark. The performance improvement is presumably because we're able to take advantage of the DYNAMIC_DRAW option intended for frequently updated buffers.
  • Loading branch information
ChrisLoer committed Jun 25, 2018
1 parent 8121e9d commit 8be1075
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/data/program_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ class SourceExpressionBinder<T> implements Binder<T> {

upload(context: Context) {
if (this.paintVertexArray && this.paintVertexArray.arrayBuffer) {
this.paintVertexBuffer = context.createVertexBuffer(this.paintVertexArray, this.paintVertexAttributes, this.expression.isStateDependent);
if (this.paintVertexBuffer && this.paintVertexBuffer.buffer) {
this.paintVertexBuffer.updateData(this.paintVertexArray);
} else {
this.paintVertexBuffer = context.createVertexBuffer(this.paintVertexArray, this.paintVertexAttributes, this.expression.isStateDependent);
}
}
}

Expand Down Expand Up @@ -280,7 +284,11 @@ class CompositeExpressionBinder<T> implements Binder<T> {

upload(context: Context) {
if (this.paintVertexArray && this.paintVertexArray.arrayBuffer) {
this.paintVertexBuffer = context.createVertexBuffer(this.paintVertexArray, this.paintVertexAttributes, this.expression.isStateDependent);
if (this.paintVertexBuffer && this.paintVertexBuffer.buffer) {
this.paintVertexBuffer.updateData(this.paintVertexArray);
} else {
this.paintVertexBuffer = context.createVertexBuffer(this.paintVertexArray, this.paintVertexAttributes, this.expression.isStateDependent);
}
}
}

Expand Down

0 comments on commit 8be1075

Please sign in to comment.