diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2023-05-16 00:31:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-16 00:31:56 +0200 |
commit | 8cfa19a078ecc7c5690740a8c669d1ecbd04bb0c (patch) | |
tree | 5d5e16393bbca27a0d79835c3e09b15ae6cae937 /scene/main/window.cpp | |
parent | 313f613352960b4d1455f0e179315de5e582b6ea (diff) | |
parent | 0a9f72d5a80c8957ef5172f546c9076089862cef (diff) | |
download | redot-engine-8cfa19a078ecc7c5690740a8c669d1ecbd04bb0c.tar.gz |
Merge pull request #77000 from reduz/make-more-base-nodes-thread-safe
Make more base nodes thread safe
Diffstat (limited to 'scene/main/window.cpp')
-rw-r--r-- | scene/main/window.cpp | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 79d41abe87..2c8edec36d 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -43,6 +43,8 @@ // Dynamic properties. bool Window::_set(const StringName &p_name, const Variant &p_value) { + ERR_MAIN_THREAD_GUARD_V(false); + String name = p_name; if (!name.begins_with("theme_override")) { return false; @@ -113,6 +115,8 @@ bool Window::_set(const StringName &p_name, const Variant &p_value) { } bool Window::_get(const StringName &p_name, Variant &r_ret) const { + ERR_READ_THREAD_GUARD_V(false); + String sname = p_name; if (!sname.begins_with("theme_override")) { return false; @@ -144,6 +148,8 @@ bool Window::_get(const StringName &p_name, Variant &r_ret) const { } void Window::_get_property_list(List<PropertyInfo> *p_list) const { + ERR_READ_THREAD_GUARD; + Ref<Theme> default_theme = ThemeDB::get_singleton()->get_default_theme(); p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Theme Overrides", "theme_override_"), PROPERTY_HINT_NONE, "theme_override_", PROPERTY_USAGE_GROUP)); @@ -261,6 +267,8 @@ void Window::_validate_property(PropertyInfo &p_property) const { // void Window::set_title(const String &p_title) { + ERR_MAIN_THREAD_GUARD; + title = p_title; if (embedder) { @@ -280,19 +288,25 @@ void Window::set_title(const String &p_title) { } String Window::get_title() const { + ERR_READ_THREAD_GUARD_V(String()); return title; } void Window::set_initial_position(Window::WindowInitialPosition p_initial_position) { + ERR_MAIN_THREAD_GUARD; + initial_position = p_initial_position; notify_property_list_changed(); } Window::WindowInitialPosition Window::get_initial_position() const { + ERR_READ_THREAD_GUARD_V(WINDOW_INITIAL_POSITION_ABSOLUTE); return initial_position; } void Window::set_current_screen(int p_screen) { + ERR_MAIN_THREAD_GUARD; + current_screen = p_screen; if (window_id == DisplayServer::INVALID_WINDOW_ID) { return; @@ -301,6 +315,8 @@ void Window::set_current_screen(int p_screen) { } int Window::get_current_screen() const { + ERR_READ_THREAD_GUARD_V(0); + if (window_id != DisplayServer::INVALID_WINDOW_ID) { current_screen = DisplayServer::get_singleton()->window_get_current_screen(window_id); } @@ -308,6 +324,8 @@ int Window::get_current_screen() const { } void Window::set_position(const Point2i &p_position) { + ERR_MAIN_THREAD_GUARD; + position = p_position; if (embedder) { @@ -319,23 +337,30 @@ void Window::set_position(const Point2i &p_position) { } Point2i Window::get_position() const { + ERR_READ_THREAD_GUARD_V(Point2i()); + return position; } void Window::set_size(const Size2i &p_size) { + ERR_MAIN_THREAD_GUARD; + size = p_size; _update_window_size(); } Size2i Window::get_size() const { + ERR_READ_THREAD_GUARD_V(Size2i()); return size; } void Window::reset_size() { + ERR_MAIN_THREAD_GUARD; set_size(Size2i()); } Point2i Window::get_position_with_decorations() const { + ERR_READ_THREAD_GUARD_V(Point2i()); if (window_id != DisplayServer::INVALID_WINDOW_ID) { return DisplayServer::get_singleton()->window_get_position_with_decorations(window_id); } @@ -343,6 +368,7 @@ Point2i Window::get_position_with_decorations() const { } Size2i Window::get_size_with_decorations() const { + ERR_READ_THREAD_GUARD_V(Size2i()); if (window_id != DisplayServer::INVALID_WINDOW_ID) { return DisplayServer::get_singleton()->window_get_size_with_decorations(window_id); } @@ -366,6 +392,7 @@ void Window::_validate_limit_size() { } void Window::set_max_size(const Size2i &p_max_size) { + ERR_MAIN_THREAD_GUARD; Size2i max_size_clamped = _clamp_limit_size(p_max_size); if (max_size == max_size_clamped) { return; @@ -377,10 +404,12 @@ void Window::set_max_size(const Size2i &p_max_size) { } Size2i Window::get_max_size() const { + ERR_READ_THREAD_GUARD_V(Size2i()); return max_size; } void Window::set_min_size(const Size2i &p_min_size) { + ERR_MAIN_THREAD_GUARD; Size2i min_size_clamped = _clamp_limit_size(p_min_size); if (min_size == min_size_clamped) { return; @@ -392,10 +421,12 @@ void Window::set_min_size(const Size2i &p_min_size) { } Size2i Window::get_min_size() const { + ERR_READ_THREAD_GUARD_V(Size2i()); return min_size; } void Window::set_mode(Mode p_mode) { + ERR_MAIN_THREAD_GUARD; mode = p_mode; if (embedder) { @@ -407,6 +438,7 @@ void Window::set_mode(Mode p_mode) { } Window::Mode Window::get_mode() const { + ERR_READ_THREAD_GUARD_V(MODE_WINDOWED); if (window_id != DisplayServer::INVALID_WINDOW_ID) { mode = (Mode)DisplayServer::get_singleton()->window_get_mode(window_id); } @@ -414,6 +446,7 @@ Window::Mode Window::get_mode() const { } void Window::set_flag(Flags p_flag, bool p_enabled) { + ERR_MAIN_THREAD_GUARD; ERR_FAIL_INDEX(p_flag, FLAG_MAX); flags[p_flag] = p_enabled; @@ -428,6 +461,7 @@ void Window::set_flag(Flags p_flag, bool p_enabled) { } bool Window::get_flag(Flags p_flag) const { + ERR_READ_THREAD_GUARD_V(false); ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false); if (window_id != DisplayServer::INVALID_WINDOW_ID) { if (!is_in_edited_scene_root()) { @@ -438,6 +472,7 @@ bool Window::get_flag(Flags p_flag) const { } bool Window::is_maximize_allowed() const { + ERR_READ_THREAD_GUARD_V(false); if (window_id != DisplayServer::INVALID_WINDOW_ID) { return DisplayServer::get_singleton()->window_is_maximize_allowed(window_id); } @@ -445,12 +480,14 @@ bool Window::is_maximize_allowed() const { } void Window::request_attention() { + ERR_MAIN_THREAD_GUARD; if (window_id != DisplayServer::INVALID_WINDOW_ID) { DisplayServer::get_singleton()->window_request_attention(window_id); } } void Window::move_to_foreground() { + ERR_MAIN_THREAD_GUARD; if (embedder) { embedder->_sub_window_grab_focus(this); @@ -460,6 +497,7 @@ void Window::move_to_foreground() { } bool Window::can_draw() const { + ERR_READ_THREAD_GUARD_V(false); if (!is_inside_tree()) { return false; } @@ -471,24 +509,28 @@ bool Window::can_draw() const { } void Window::set_ime_active(bool p_active) { + ERR_MAIN_THREAD_GUARD; if (window_id != DisplayServer::INVALID_WINDOW_ID) { DisplayServer::get_singleton()->window_set_ime_active(p_active, window_id); } } void Window::set_ime_position(const Point2i &p_pos) { + ERR_MAIN_THREAD_GUARD; if (window_id != DisplayServer::INVALID_WINDOW_ID) { DisplayServer::get_singleton()->window_set_ime_position(p_pos, window_id); } } bool Window::is_embedded() const { + ERR_READ_THREAD_GUARD_V(false); ERR_FAIL_COND_V(!is_inside_tree(), false); return get_embedder() != nullptr; } bool Window::is_in_edited_scene_root() const { + ERR_READ_THREAD_GUARD_V(false); #ifdef TOOLS_ENABLED return is_part_of_edited_scene(); #else @@ -680,6 +722,7 @@ void Window::_event_callback(DisplayServer::WindowEvent p_event) { } void Window::update_mouse_cursor_shape() { + ERR_MAIN_THREAD_GUARD; // The default shape is set in Viewport::_gui_input_event. To instantly // see the shape in the viewport we need to trigger a mouse motion event. Ref<InputEventMouseMotion> mm; @@ -693,14 +736,17 @@ void Window::update_mouse_cursor_shape() { } void Window::show() { + ERR_MAIN_THREAD_GUARD; set_visible(true); } void Window::hide() { + ERR_MAIN_THREAD_GUARD; set_visible(false); } void Window::set_visible(bool p_visible) { + ERR_MAIN_THREAD_GUARD; if (visible == p_visible) { return; } @@ -816,6 +862,7 @@ void Window::_make_transient() { } void Window::set_transient(bool p_transient) { + ERR_MAIN_THREAD_GUARD; if (transient == p_transient) { return; } @@ -834,10 +881,12 @@ void Window::set_transient(bool p_transient) { } bool Window::is_transient() const { + ERR_READ_THREAD_GUARD_V(false); return transient; } void Window::set_exclusive(bool p_exclusive) { + ERR_MAIN_THREAD_GUARD; if (exclusive == p_exclusive) { return; } @@ -867,10 +916,12 @@ void Window::set_exclusive(bool p_exclusive) { } bool Window::is_exclusive() const { + ERR_READ_THREAD_GUARD_V(false); return exclusive; } bool Window::is_visible() const { + ERR_READ_THREAD_GUARD_V(false); return visible; } @@ -1061,6 +1112,7 @@ void Window::_update_window_callbacks() { } Viewport *Window::get_embedder() const { + ERR_READ_THREAD_GUARD_V(nullptr); Viewport *vp = get_parent_viewport(); while (vp) { @@ -1078,6 +1130,7 @@ Viewport *Window::get_embedder() const { } void Window::_notification(int p_what) { + ERR_MAIN_THREAD_GUARD; switch (p_what) { case NOTIFICATION_POSTINITIALIZE: { initialized = true; @@ -1215,6 +1268,7 @@ void Window::_notification(int p_what) { } void Window::set_content_scale_size(const Size2i &p_size) { + ERR_MAIN_THREAD_GUARD; ERR_FAIL_COND(p_size.x < 0); ERR_FAIL_COND(p_size.y < 0); content_scale_size = p_size; @@ -1222,38 +1276,46 @@ void Window::set_content_scale_size(const Size2i &p_size) { } Size2i Window::get_content_scale_size() const { + ERR_READ_THREAD_GUARD_V(Size2i()); return content_scale_size; } void Window::set_content_scale_mode(ContentScaleMode p_mode) { + ERR_MAIN_THREAD_GUARD; content_scale_mode = p_mode; _update_viewport_size(); } Window::ContentScaleMode Window::get_content_scale_mode() const { + ERR_READ_THREAD_GUARD_V(CONTENT_SCALE_MODE_DISABLED); return content_scale_mode; } void Window::set_content_scale_aspect(ContentScaleAspect p_aspect) { + ERR_MAIN_THREAD_GUARD; content_scale_aspect = p_aspect; _update_viewport_size(); } Window::ContentScaleAspect Window::get_content_scale_aspect() const { + ERR_READ_THREAD_GUARD_V(CONTENT_SCALE_ASPECT_IGNORE); return content_scale_aspect; } void Window::set_content_scale_factor(real_t p_factor) { + ERR_MAIN_THREAD_GUARD; ERR_FAIL_COND(p_factor <= 0); content_scale_factor = p_factor; _update_viewport_size(); } real_t Window::get_content_scale_factor() const { + ERR_READ_THREAD_GUARD_V(0); return content_scale_factor; } void Window::set_use_font_oversampling(bool p_oversampling) { + ERR_MAIN_THREAD_GUARD; if (is_inside_tree() && window_id != DisplayServer::MAIN_WINDOW_ID) { ERR_FAIL_MSG("Only the root window can set and use font oversampling."); } @@ -1262,10 +1324,12 @@ void Window::set_use_font_oversampling(bool p_oversampling) { } bool Window::is_using_font_oversampling() const { + ERR_READ_THREAD_GUARD_V(false); return use_font_oversampling; } DisplayServer::WindowID Window::get_window_id() const { + ERR_READ_THREAD_GUARD_V(DisplayServer::INVALID_WINDOW_ID); if (embedder) { return parent->get_window_id(); } @@ -1273,6 +1337,7 @@ DisplayServer::WindowID Window::get_window_id() const { } void Window::set_mouse_passthrough_polygon(const Vector<Vector2> &p_region) { + ERR_MAIN_THREAD_GUARD; mpath = p_region; if (window_id == DisplayServer::INVALID_WINDOW_ID) { return; @@ -1285,6 +1350,7 @@ Vector<Vector2> Window::get_mouse_passthrough_polygon() const { } void Window::set_wrap_controls(bool p_enable) { + ERR_MAIN_THREAD_GUARD; wrap_controls = p_enable; if (!is_inside_tree()) { @@ -1299,6 +1365,7 @@ void Window::set_wrap_controls(bool p_enable) { } bool Window::is_wrapping_controls() const { + ERR_READ_THREAD_GUARD_V(false); return wrap_controls; } @@ -1320,6 +1387,7 @@ Size2 Window::_get_contents_minimum_size() const { } void Window::child_controls_changed() { + ERR_MAIN_THREAD_GUARD; if (!is_inside_tree() || !visible || updating_child_controls) { return; } @@ -1397,6 +1465,7 @@ void Window::_window_drop_files(const Vector<String> &p_files) { } Viewport *Window::get_parent_viewport() const { + ERR_READ_THREAD_GUARD_V(nullptr); if (get_parent()) { return get_parent()->get_viewport(); } else { @@ -1405,6 +1474,7 @@ Viewport *Window::get_parent_viewport() const { } Window *Window::get_parent_visible_window() const { + ERR_READ_THREAD_GUARD_V(nullptr); Viewport *vp = get_parent_viewport(); Window *window = nullptr; while (vp) { @@ -1422,6 +1492,7 @@ Window *Window::get_parent_visible_window() const { } void Window::popup_on_parent(const Rect2i &p_parent_rect) { + ERR_MAIN_THREAD_GUARD; ERR_FAIL_COND(!is_inside_tree()); ERR_FAIL_COND_MSG(window_id == DisplayServer::MAIN_WINDOW_ID, "Can't popup the main window."); @@ -1439,6 +1510,7 @@ void Window::popup_on_parent(const Rect2i &p_parent_rect) { } void Window::popup_centered_clamped(const Size2i &p_size, float p_fallback_ratio) { + ERR_MAIN_THREAD_GUARD; ERR_FAIL_COND(!is_inside_tree()); ERR_FAIL_COND_MSG(window_id == DisplayServer::MAIN_WINDOW_ID, "Can't popup the main window."); @@ -1470,6 +1542,7 @@ void Window::popup_centered_clamped(const Size2i &p_size, float p_fallback_ratio } void Window::popup_centered(const Size2i &p_minsize) { + ERR_MAIN_THREAD_GUARD; ERR_FAIL_COND(!is_inside_tree()); ERR_FAIL_COND_MSG(window_id == DisplayServer::MAIN_WINDOW_ID, "Can't popup the main window."); @@ -1498,6 +1571,7 @@ void Window::popup_centered(const Size2i &p_minsize) { } void Window::popup_centered_ratio(float p_ratio) { + ERR_MAIN_THREAD_GUARD; ERR_FAIL_COND(!is_inside_tree()); ERR_FAIL_COND_MSG(window_id == DisplayServer::MAIN_WINDOW_ID, "Can't popup the main window."); ERR_FAIL_COND_MSG(p_ratio <= 0.0 || p_ratio > 1.0, "Ratio must be between 0.0 and 1.0!"); @@ -1524,6 +1598,7 @@ void Window::popup_centered_ratio(float p_ratio) { } void Window::popup(const Rect2i &p_screen_rect) { + ERR_MAIN_THREAD_GUARD; emit_signal(SNAME("about_to_popup")); if (!get_embedder() && get_flag(FLAG_POPUP)) { @@ -1582,6 +1657,7 @@ void Window::popup(const Rect2i &p_screen_rect) { } Rect2i Window::fit_rect_in_parent(Rect2i p_rect, const Rect2i &p_parent_rect) const { + ERR_READ_THREAD_GUARD_V(Rect2i()); Size2i limit = p_parent_rect.size; if (p_rect.position.x + p_rect.size.x > limit.x) { p_rect.position.x = limit.x - p_rect.size.x; @@ -1604,10 +1680,12 @@ Rect2i Window::fit_rect_in_parent(Rect2i p_rect, const Rect2i &p_parent_rect) co } Size2 Window::get_contents_minimum_size() const { + ERR_READ_THREAD_GUARD_V(Size2()); return _get_contents_minimum_size(); } Size2 Window::get_clamped_minimum_size() const { + ERR_READ_THREAD_GUARD_V(Size2()); if (!wrap_controls) { return min_size; } @@ -1616,6 +1694,7 @@ Size2 Window::get_clamped_minimum_size() const { } void Window::grab_focus() { + ERR_MAIN_THREAD_GUARD; if (embedder) { embedder->_sub_window_grab_focus(this); } else if (window_id != DisplayServer::INVALID_WINDOW_ID) { @@ -1624,10 +1703,12 @@ void Window::grab_focus() { } bool Window::has_focus() const { + ERR_READ_THREAD_GUARD_V(false); return focused; } Rect2i Window::get_usable_parent_rect() const { + ERR_READ_THREAD_GUARD_V(Rect2i()); ERR_FAIL_COND_V(!is_inside_tree(), Rect2()); Rect2i parent_rect; if (is_embedded()) { @@ -1657,18 +1738,22 @@ void Window::remove_child_notify(Node *p_child) { // Theming. void Window::set_theme_owner_node(Node *p_node) { + ERR_MAIN_THREAD_GUARD; theme_owner->set_owner_node(p_node); } Node *Window::get_theme_owner_node() const { + ERR_READ_THREAD_GUARD_V(nullptr); return theme_owner->get_owner_node(); } bool Window::has_theme_owner_node() const { + ERR_READ_THREAD_GUARD_V(false); return theme_owner->has_owner_node(); } void Window::set_theme(const Ref<Theme> &p_theme) { + ERR_MAIN_THREAD_GUARD; if (theme == p_theme) { return; } @@ -1700,6 +1785,7 @@ void Window::set_theme(const Ref<Theme> &p_theme) { } Ref<Theme> Window::get_theme() const { + ERR_READ_THREAD_GUARD_V(Ref<Theme>()); return theme; } @@ -1748,6 +1834,7 @@ void Window::_update_embedded_window() { } void Window::set_theme_type_variation(const StringName &p_theme_type) { + ERR_MAIN_THREAD_GUARD; theme_type_variation = p_theme_type; if (is_inside_tree()) { notification(NOTIFICATION_THEME_CHANGED); @@ -1755,12 +1842,14 @@ void Window::set_theme_type_variation(const StringName &p_theme_type) { } StringName Window::get_theme_type_variation() const { + ERR_READ_THREAD_GUARD_V(StringName()); return theme_type_variation; } /// Theme property lookup. Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName &p_theme_type) const { + ERR_READ_THREAD_GUARD_V(Ref<Texture2D>()); if (!initialized) { WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); } @@ -1784,6 +1873,7 @@ Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName } Ref<StyleBox> Window::get_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const { + ERR_READ_THREAD_GUARD_V(Ref<StyleBox>()); if (!initialized) { WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); } @@ -1807,6 +1897,7 @@ Ref<StyleBox> Window::get_theme_stylebox(const StringName &p_name, const StringN } Ref<Font> Window::get_theme_font(const StringName &p_name, const StringName &p_theme_type) const { + ERR_READ_THREAD_GUARD_V(Ref<Font>()); if (!initialized) { WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); } @@ -1830,6 +1921,7 @@ Ref<Font> Window::get_theme_font(const StringName &p_name, const StringName &p_t } int Window::get_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const { + ERR_READ_THREAD_GUARD_V(0); if (!initialized) { WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); } @@ -1853,6 +1945,7 @@ int Window::get_theme_font_size(const StringName &p_name, const StringName &p_th } Color Window::get_theme_color(const StringName &p_name, const StringName &p_theme_type) const { + ERR_READ_THREAD_GUARD_V(Color()); if (!initialized) { WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); } @@ -1876,6 +1969,7 @@ Color Window::get_theme_color(const StringName &p_name, const StringName &p_them } int Window::get_theme_constant(const StringName &p_name, const StringName &p_theme_type) const { + ERR_READ_THREAD_GUARD_V(0); if (!initialized) { WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); } @@ -1899,6 +1993,7 @@ int Window::get_theme_constant(const StringName &p_name, const StringName &p_the } bool Window::has_theme_icon(const StringName &p_name, const StringName &p_theme_type) const { + ERR_READ_THREAD_GUARD_V(false); if (!initialized) { WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); } @@ -1915,6 +2010,7 @@ bool Window::has_theme_icon(const StringName &p_name, const StringName &p_theme_ } bool Window::has_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const { + ERR_READ_THREAD_GUARD_V(false); if (!initialized) { WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); } @@ -1931,6 +2027,7 @@ bool Window::has_theme_stylebox(const StringName &p_name, const StringName &p_th } bool Window::has_theme_font(const StringName &p_name, const StringName &p_theme_type) const { + ERR_READ_THREAD_GUARD_V(false); if (!initialized) { WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); } @@ -1947,6 +2044,7 @@ bool Window::has_theme_font(const StringName &p_name, const StringName &p_theme_ } bool Window::has_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const { + ERR_READ_THREAD_GUARD_V(false); if (!initialized) { WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); } @@ -1963,6 +2061,7 @@ bool Window::has_theme_font_size(const StringName &p_name, const StringName &p_t } bool Window::has_theme_color(const StringName &p_name, const StringName &p_theme_type) const { + ERR_READ_THREAD_GUARD_V(false); if (!initialized) { WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); } @@ -1979,6 +2078,7 @@ bool Window::has_theme_color(const StringName &p_name, const StringName &p_theme } bool Window::has_theme_constant(const StringName &p_name, const StringName &p_theme_type) const { + ERR_READ_THREAD_GUARD_V(false); if (!initialized) { WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); } @@ -1997,6 +2097,7 @@ bool Window::has_theme_constant(const StringName &p_name, const StringName &p_th /// Local property overrides. void Window::add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon) { + ERR_MAIN_THREAD_GUARD; ERR_FAIL_COND(!p_icon.is_valid()); if (theme_icon_override.has(p_name)) { @@ -2009,6 +2110,7 @@ void Window::add_theme_icon_override(const StringName &p_name, const Ref<Texture } void Window::add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) { + ERR_MAIN_THREAD_GUARD; ERR_FAIL_COND(!p_style.is_valid()); if (theme_style_override.has(p_name)) { @@ -2021,6 +2123,7 @@ void Window::add_theme_style_override(const StringName &p_name, const Ref<StyleB } void Window::add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font) { + ERR_MAIN_THREAD_GUARD; ERR_FAIL_COND(!p_font.is_valid()); if (theme_font_override.has(p_name)) { @@ -2033,21 +2136,25 @@ void Window::add_theme_font_override(const StringName &p_name, const Ref<Font> & } void Window::add_theme_font_size_override(const StringName &p_name, int p_font_size) { + ERR_MAIN_THREAD_GUARD; theme_font_size_override[p_name] = p_font_size; _notify_theme_override_changed(); } void Window::add_theme_color_override(const StringName &p_name, const Color &p_color) { + ERR_MAIN_THREAD_GUARD; theme_color_override[p_name] = p_color; _notify_theme_override_changed(); } void Window::add_theme_constant_override(const StringName &p_name, int p_constant) { + ERR_MAIN_THREAD_GUARD; theme_constant_override[p_name] = p_constant; _notify_theme_override_changed(); } void Window::remove_theme_icon_override(const StringName &p_name) { + ERR_MAIN_THREAD_GUARD; if (theme_icon_override.has(p_name)) { theme_icon_override[p_name]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed)); } @@ -2057,6 +2164,7 @@ void Window::remove_theme_icon_override(const StringName &p_name) { } void Window::remove_theme_style_override(const StringName &p_name) { + ERR_MAIN_THREAD_GUARD; if (theme_style_override.has(p_name)) { theme_style_override[p_name]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed)); } @@ -2066,6 +2174,7 @@ void Window::remove_theme_style_override(const StringName &p_name) { } void Window::remove_theme_font_override(const StringName &p_name) { + ERR_MAIN_THREAD_GUARD; if (theme_font_override.has(p_name)) { theme_font_override[p_name]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed)); } @@ -2075,46 +2184,55 @@ void Window::remove_theme_font_override(const StringName &p_name) { } void Window::remove_theme_font_size_override(const StringName &p_name) { + ERR_MAIN_THREAD_GUARD; theme_font_size_override.erase(p_name); _notify_theme_override_changed(); } void Window::remove_theme_color_override(const StringName &p_name) { + ERR_MAIN_THREAD_GUARD; theme_color_override.erase(p_name); _notify_theme_override_changed(); } void Window::remove_theme_constant_override(const StringName &p_name) { + ERR_MAIN_THREAD_GUARD; theme_constant_override.erase(p_name); _notify_theme_override_changed(); } bool Window::has_theme_icon_override(const StringName &p_name) const { + ERR_READ_THREAD_GUARD_V(false); const Ref<Texture2D> *tex = theme_icon_override.getptr(p_name); return tex != nullptr; } bool Window::has_theme_stylebox_override(const StringName &p_name) const { + ERR_READ_THREAD_GUARD_V(false); const Ref<StyleBox> *style = theme_style_override.getptr(p_name); return style != nullptr; } bool Window::has_theme_font_override(const StringName &p_name) const { + ERR_READ_THREAD_GUARD_V(false); const Ref<Font> *font = theme_font_override.getptr(p_name); return font != nullptr; } bool Window::has_theme_font_size_override(const StringName &p_name) const { + ERR_READ_THREAD_GUARD_V(false); const int *font_size = theme_font_size_override.getptr(p_name); return font_size != nullptr; } bool Window::has_theme_color_override(const StringName &p_name) const { + ERR_READ_THREAD_GUARD_V(false); const Color *color = theme_color_override.getptr(p_name); return color != nullptr; } bool Window::has_theme_constant_override(const StringName &p_name) const { + ERR_READ_THREAD_GUARD_V(false); const int *constant = theme_constant_override.getptr(p_name); return constant != nullptr; } @@ -2122,24 +2240,29 @@ bool Window::has_theme_constant_override(const StringName &p_name) const { /// Default theme properties. float Window::get_theme_default_base_scale() const { + ERR_READ_THREAD_GUARD_V(0); return theme_owner->get_theme_default_base_scale(); } Ref<Font> Window::get_theme_default_font() const { + ERR_READ_THREAD_GUARD_V(Ref<Font>()); return theme_owner->get_theme_default_font(); } int Window::get_theme_default_font_size() const { + ERR_READ_THREAD_GUARD_V(0); return theme_owner->get_theme_default_font_size(); } /// Bulk actions. void Window::begin_bulk_theme_override() { + ERR_MAIN_THREAD_GUARD; bulk_theme_override = true; } void Window::end_bulk_theme_override() { + ERR_MAIN_THREAD_GUARD; ERR_FAIL_COND(!bulk_theme_override); bulk_theme_override = false; @@ -2149,6 +2272,7 @@ void Window::end_bulk_theme_override() { // Rect2i Window::get_parent_rect() const { + ERR_READ_THREAD_GUARD_V(Rect2i()); ERR_FAIL_COND_V(!is_inside_tree(), Rect2i()); if (is_embedded()) { //viewport @@ -2185,14 +2309,17 @@ Rect2i Window::get_parent_rect() const { } void Window::set_clamp_to_embedder(bool p_enable) { + ERR_MAIN_THREAD_GUARD; clamp_to_embedder = p_enable; } bool Window::is_clamped_to_embedder() const { + ERR_READ_THREAD_GUARD_V(false); return clamp_to_embedder; } void Window::set_layout_direction(Window::LayoutDirection p_direction) { + ERR_MAIN_THREAD_GUARD; ERR_FAIL_INDEX((int)p_direction, 4); layout_dir = p_direction; @@ -2200,10 +2327,12 @@ void Window::set_layout_direction(Window::LayoutDirection p_direction) { } Window::LayoutDirection Window::get_layout_direction() const { + ERR_READ_THREAD_GUARD_V(LAYOUT_DIRECTION_INHERITED); return layout_dir; } bool Window::is_layout_rtl() const { + ERR_READ_THREAD_GUARD_V(false); if (layout_dir == LAYOUT_DIRECTION_INHERITED) { if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) { return true; @@ -2244,6 +2373,7 @@ bool Window::is_layout_rtl() const { } void Window::set_auto_translate(bool p_enable) { + ERR_MAIN_THREAD_GUARD; if (p_enable == auto_translate) { return; } @@ -2254,14 +2384,17 @@ void Window::set_auto_translate(bool p_enable) { } bool Window::is_auto_translating() const { + ERR_READ_THREAD_GUARD_V(false); return auto_translate; } Transform2D Window::get_final_transform() const { + ERR_READ_THREAD_GUARD_V(Transform2D()); return window_transform * stretch_transform * global_canvas_transform; } Transform2D Window::get_screen_transform_internal(bool p_absolute_position) const { + ERR_READ_THREAD_GUARD_V(Transform2D()); Transform2D embedder_transform; if (get_embedder()) { embedder_transform.translate_local(get_position()); @@ -2273,6 +2406,7 @@ Transform2D Window::get_screen_transform_internal(bool p_absolute_position) cons } Transform2D Window::get_popup_base_transform() const { + ERR_READ_THREAD_GUARD_V(Transform2D()); if (is_embedding_subwindows()) { return Transform2D(); } |