Skip to content

Commit 47f7554

Browse files
committed
Fix immediate mesh modifications that don't call set_mesh
Mesh_instance_2d has no way to know when the mesh had been modified unless you called set_mesh. This meant that you could modify the underlying mesh without it knowing which could result in incorrect result. Modified mesh_instance_2d to be more similar to mesh_instance_3d which connects to the changed signal of the mesh and reacts occordingly.
1 parent 2e14492 commit 47f7554

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

scene/2d/mesh_instance_2d.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,20 @@ void MeshInstance2D::_bind_methods() {
5454
}
5555

5656
void MeshInstance2D::set_mesh(const Ref<Mesh> &p_mesh) {
57+
if (mesh == p_mesh) {
58+
return;
59+
}
60+
61+
if (mesh.is_valid()) {
62+
mesh->disconnect_changed(callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
63+
}
64+
5765
mesh = p_mesh;
66+
67+
if (mesh.is_valid()) {
68+
mesh->connect_changed(callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
69+
}
70+
5871
queue_redraw();
5972
}
6073

scene/resources/immediate_mesh.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ void ImmediateMesh::surface_end() {
312312
uses_uv2s = false;
313313

314314
surface_active = false;
315+
316+
emit_changed();
315317
}
316318

317319
void ImmediateMesh::clear_surfaces() {

0 commit comments

Comments
 (0)