Fix crashes if add_config_file_controls() is not called.
authorCarl Hetherington <cth@carlh.net>
Thu, 13 Mar 2025 23:30:24 +0000 (00:30 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 13 Mar 2025 23:30:24 +0000 (00:30 +0100)
e.g. when opening the player preferences.

src/wx/general_preferences_page.cc
src/wx/general_preferences_page.h

index 1ad79960764bfc1160cc6de4d1b3d527d88db95d..beed9012f651ab421bc7c1cd39846369707f14e4 100644 (file)
@@ -136,6 +136,10 @@ GeneralPage::add_config_file_controls(wxGridBagSizer* table, int& r)
 void
 GeneralPage::config_file_changed()
 {
+       if (!_config_file) {
+               return;
+       }
+
        auto config = Config::instance();
        auto const new_file = _config_file->path();
        if (!new_file || *new_file == config->config_read_file()) {
@@ -162,6 +166,10 @@ GeneralPage::config_file_changed()
 void
 GeneralPage::cinemas_file_changed()
 {
+       if (!_cinemas_file) {
+               return;
+       }
+
        if (auto path = _cinemas_file->path()) {
                Config::instance()->set_cinemas_file(*path);
        }
@@ -228,8 +236,12 @@ GeneralPage::config_changed()
 
        checked_set(_language, lang);
 
-       checked_set(_config_file, config->config_read_file());
-       checked_set(_cinemas_file, config->cinemas_file());
+       if (_config_file) {
+               checked_set(_config_file, config->config_read_file());
+       }
+       if (_cinemas_file) {
+               checked_set(_cinemas_file, config->cinemas_file());
+       }
 
        checked_set(_check_for_updates, config->check_for_updates());
        checked_set(_check_for_test_updates, config->check_for_test_updates());
index 34801a2cabdecc659761c6948ac01bd6d518298a..d871c2506e5ae5293653661b5bbcc1dacd92df0d 100644 (file)
@@ -60,12 +60,12 @@ private:
        void check_for_updates_changed();
        void check_for_test_updates_changed();
 
-       CheckBox* _set_language;
-       wxChoice* _language;
-       FilePickerCtrl* _config_file;
-       FilePickerCtrl* _cinemas_file;
-       CheckBox* _check_for_updates;
-       CheckBox* _check_for_test_updates;
+       CheckBox* _set_language = nullptr;
+       wxChoice* _language = nullptr;
+       FilePickerCtrl* _config_file = nullptr;
+       FilePickerCtrl* _cinemas_file = nullptr;
+       CheckBox* _check_for_updates = nullptr;
+       CheckBox* _check_for_test_updates = nullptr;
 };