Skip to content

Commit

Permalink
Backport cloud rendering tear-down fixes
Browse files Browse the repository at this point in the history
The vertex buffer may be null if there is no
geometry within the view distance, but the tear-down
function will not check before trying to delete the
buffer.

Additionally, make sure that we de-allocate the vertex
buffer when there is no geometry visible, to avoid
leaking buffer handles.
  • Loading branch information
jellysquid3 committed Dec 10, 2024
1 parent 1bd4f06 commit b804224
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,24 @@ public void render(Camera camera,
}
}

MeshData builtBuffer = bufferBuilder.build();
@Nullable MeshData meshData = bufferBuilder.build();
@Nullable VertexBuffer vertexBuffer = null;

VertexBuffer vertexBuffer = null;
if (existingGeometry != null) {
vertexBuffer = existingGeometry.vertexBuffer();
}

if (builtBuffer != null) {
if (existingGeometry != null) {
vertexBuffer = existingGeometry.vertexBuffer();
}
if (meshData != null) {
if (vertexBuffer == null) {
vertexBuffer = new VertexBuffer(VertexBuffer.Usage.DYNAMIC);
}

uploadToVertexBuffer(vertexBuffer, builtBuffer);
uploadToVertexBuffer(vertexBuffer, meshData);
} else {
if (vertexBuffer != null) {
vertexBuffer.close();
vertexBuffer = null;
}
}

Tesselator.getInstance().clear();
Expand Down Expand Up @@ -521,7 +526,10 @@ public void destroy() {

if (this.builtGeometry != null) {
var vertexBuffer = this.builtGeometry.vertexBuffer();
vertexBuffer.close();

if (vertexBuffer != null) {
vertexBuffer.close();
}

this.builtGeometry = null;
}
Expand Down Expand Up @@ -746,7 +754,7 @@ public int getCellColor(int index) {
}
}

public record CloudGeometry(VertexBuffer vertexBuffer, CloudGeometryParameters params) {
public record CloudGeometry(@Nullable VertexBuffer vertexBuffer, CloudGeometryParameters params) {

}

Expand Down

0 comments on commit b804224

Please sign in to comment.