Browse Source

Check if _edit_set_position and _edit_set_rect was used outside an editor

(cherry picked from commit b80406770ff0fe108395354121e03743a8a7121e)
Kongfa Waroros 4 years ago
parent
commit
7646cbbca6
1 changed files with 2 additions and 0 deletions
  1. 2 0
      scene/gui/control.cpp

+ 2 - 0
scene/gui/control.cpp

@@ -93,6 +93,7 @@ void Control::_edit_set_state(const Dictionary &p_state) {
 
 
 void Control::_edit_set_position(const Point2 &p_position) {
 void Control::_edit_set_position(const Point2 &p_position) {
 #ifdef TOOLS_ENABLED
 #ifdef TOOLS_ENABLED
+	ERR_FAIL_COND_MSG(!Engine::get_singleton()->is_editor_hint(), "This function can only be used from editor plugins.");
 	set_position(p_position, CanvasItemEditor::get_singleton()->is_anchors_mode_enabled());
 	set_position(p_position, CanvasItemEditor::get_singleton()->is_anchors_mode_enabled());
 #else
 #else
 	// Unlikely to happen. TODO: enclose all _edit_ functions into TOOLS_ENABLED
 	// Unlikely to happen. TODO: enclose all _edit_ functions into TOOLS_ENABLED
@@ -114,6 +115,7 @@ Size2 Control::_edit_get_scale() const {
 
 
 void Control::_edit_set_rect(const Rect2 &p_edit_rect) {
 void Control::_edit_set_rect(const Rect2 &p_edit_rect) {
 #ifdef TOOLS_ENABLED
 #ifdef TOOLS_ENABLED
+	ERR_FAIL_COND_MSG(!Engine::get_singleton()->is_editor_hint(), "This function can only be used from editor plugins.");
 	set_position((get_position() + get_transform().basis_xform(p_edit_rect.position)).snapped(Vector2(1, 1)), CanvasItemEditor::get_singleton()->is_anchors_mode_enabled());
 	set_position((get_position() + get_transform().basis_xform(p_edit_rect.position)).snapped(Vector2(1, 1)), CanvasItemEditor::get_singleton()->is_anchors_mode_enabled());
 	set_size(p_edit_rect.size.snapped(Vector2(1, 1)), CanvasItemEditor::get_singleton()->is_anchors_mode_enabled());
 	set_size(p_edit_rect.size.snapped(Vector2(1, 1)), CanvasItemEditor::get_singleton()->is_anchors_mode_enabled());
 #else
 #else