Skip to content

Commit

Permalink
Prevent calling get_material for invalid gizmo
Browse files Browse the repository at this point in the history
  • Loading branch information
jsjtxietian committed Sep 20, 2024
1 parent 7c38376 commit e81ace5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions editor/plugins/node_3d_editor_gizmos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,10 @@ bool EditorNode3DGizmo::is_subgizmo_selected(int p_id) const {
return ed->is_current_selected_gizmo(this) && ed->is_subgizmo_selected(p_id);
}

bool EditorNode3DGizmo::is_gizmo_valid() const {
return valid;
}

Vector<int> EditorNode3DGizmo::get_subgizmo_selection() const {
Vector<int> ret;

Expand Down Expand Up @@ -1013,6 +1017,8 @@ Ref<StandardMaterial3D> EditorNode3DGizmoPlugin::get_material(const String &p_na
return materials[p_name][0];
}

ERR_FAIL_COND_V(!p_gizmo->is_gizmo_valid(), Ref<StandardMaterial3D>());

int index = (p_gizmo->is_selected() ? 1 : 0) + (p_gizmo->is_editable() ? 2 : 0);

Ref<StandardMaterial3D> mat = materials[p_name][index];
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/node_3d_editor_gizmos.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class EditorNode3DGizmo : public Node3DGizmo {
void handles_intersect_ray(Camera3D *p_camera, const Vector2 &p_point, bool p_shift_pressed, int &r_id, bool &r_secondary);
bool intersect_ray(Camera3D *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal);
bool is_subgizmo_selected(int p_id) const;
bool is_gizmo_valid() const;
Vector<int> get_subgizmo_selection() const;

virtual void clear() override;
Expand Down

0 comments on commit e81ace5

Please sign in to comment.