summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorRubidium <rubidium@openttd.org>2021-05-12 19:44:00 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-05-13 10:03:26 +0200
commit7755f81bb8ba1c6a47e3a528acbbc462e56adaff (patch)
treeaff19b5894e3a5546e43f610ca6a3c0a9e154c8d /src/script
parentd7ce61f10674567c97a1edd78ea1baf4e08153f2 (diff)
downloadopenttd-7755f81bb8ba1c6a47e3a528acbbc462e56adaff.tar.xz
Codechange: make explicit that virtual functions in a con/destructor are resolved statically
This as during construction the sub class has not been initialized yet, and during destruction the sub class has already been destroyed, so the overriding virtual function would be accessing uninitialized data.
Diffstat (limited to 'src/script')
-rw-r--r--src/script/script_config.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/script/script_config.cpp b/src/script/script_config.cpp
index 9bb953c4c..eeab51bed 100644
--- a/src/script/script_config.cpp
+++ b/src/script/script_config.cpp
@@ -37,6 +37,7 @@ void ScriptConfig::Change(const char *name, int version, bool force_exact_match,
this->SetSetting(item.name, InteractiveRandomRange(item.max_value + 1 - item.min_value) + item.min_value);
}
}
+
this->AddRandomDeviation();
}
}
@@ -52,7 +53,9 @@ ScriptConfig::ScriptConfig(const ScriptConfig *config)
for (const auto &item : config->settings) {
this->settings[stredup(item.first)] = item.second;
}
- this->AddRandomDeviation();
+
+ /* Virtual functions get called statically in constructors, so make it explicit to remove any confusion. */
+ this->ScriptConfig::AddRandomDeviation();
}
ScriptConfig::~ScriptConfig()