← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug_1794339_center_wo_parent into lp:widelands

 

Klaus Halfmann has proposed merging lp:~widelands-dev/widelands/bug_1794339_center_wo_parent into lp:widelands.

Commit message:
Avoid null access in Window::center_to_parent()

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1794339 in widelands: "segfault joining game"
  https://bugs.launchpad.net/widelands/+bug/1794339

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug_1794339_center_wo_parent/+merge/355873

Simple check if Window has a parent instead of crashing.

This leaves the window in the top-lfet corner, but avoids the crash.

Gun: can we center to some global window instead.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug_1794339_center_wo_parent into lp:widelands.
=== modified file 'src/ui_basic/window.cc'
--- src/ui_basic/window.cc	2018-07-08 13:53:45 +0000
+++ src/ui_basic/window.cc	2018-09-29 14:33:07 +0000
@@ -221,13 +221,17 @@
 }
 
 /**
- * Move the window so that it is centered wrt the parent.
-*/
+ * Move the window so that it is centered inside the parent.
+ *
+ * Do nothing if window has no parent.
+ */
 void Window::center_to_parent() {
-	Panel& parent = *get_parent();
+	Panel* parent = get_parent();
 
-	set_pos(Vector2i((static_cast<int32_t>(parent.get_inner_w()) - get_w()) / 2,
-	                 (static_cast<int32_t>(parent.get_inner_h()) - get_h()) / 2));
+    if (parent) {
+        set_pos(Vector2i((static_cast<int32_t>(parent->get_inner_w()) - get_w()) / 2,
+                         (static_cast<int32_t>(parent->get_inner_h()) - get_h()) / 2));
+    }
 }
 
 /**


Follow ups