diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2017-05-02 11:24:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-02 11:24:41 +0200 |
commit | 28173ad35d72fad12b2810133a3c3d1827bdeeec (patch) | |
tree | 792abdc412426fcdb6ad8c7c185c66d220b69309 | |
parent | ab9d7241d9dfd9ffeab345e062f3a7d5f6c00320 (diff) | |
parent | d78efddbf582d4f9af852948baee1b0e6bab4744 (diff) |
Merge pull request #8620 from Zylann/issue8617_window_dialog_stylebox
Fix #8617 WindowDialog with custom panel background crashes godot
-rw-r--r-- | scene/gui/dialogs.cpp | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 835775e13b..cf5321e907 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -54,20 +54,24 @@ void WindowDialog::_fix_size() { // Windows require additional padding to keep the window chrome visible. Ref<StyleBoxTexture> panel = get_stylebox("panel", "WindowDialog"); - float top = panel->get_expand_margin_size(MARGIN_TOP); - float left = panel->get_expand_margin_size(MARGIN_LEFT); - float bottom = panel->get_expand_margin_size(MARGIN_BOTTOM); - float right = panel->get_expand_margin_size(MARGIN_RIGHT); - pos.x = MAX(left, MIN(pos.x, viewport_size.x - size.x - right)); - pos.y = MAX(top, MIN(pos.y, viewport_size.y - size.y - bottom)); - set_global_position(pos); - - // Also resize the window to fit if a resize should be possible at all. - if (resizable) { - size.x = MIN(size.x, viewport_size.x - left - right); - size.y = MIN(size.y, viewport_size.y - top - bottom); - set_size(size); + // Check validity, because the theme could contain a different type of StyleBox + if (panel.is_valid()) { + float top = panel->get_expand_margin_size(MARGIN_TOP); + float left = panel->get_expand_margin_size(MARGIN_LEFT); + float bottom = panel->get_expand_margin_size(MARGIN_BOTTOM); + float right = panel->get_expand_margin_size(MARGIN_RIGHT); + + pos.x = MAX(left, MIN(pos.x, viewport_size.x - size.x - right)); + pos.y = MAX(top, MIN(pos.y, viewport_size.y - size.y - bottom)); + set_global_position(pos); + + // Also resize the window to fit if a resize should be possible at all. + if (resizable) { + size.x = MIN(size.x, viewport_size.x - left - right); + size.y = MIN(size.y, viewport_size.y - top - bottom); + set_size(size); + } } } |