Reset on initialization in ScriptAggregator, fixes segfault when calling Reset on an empty Aggregator.
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
2021-04-17 15:08:26 +02:00
parent 33f796eff8
commit 9f091308b0
2 changed files with 57 additions and 48 deletions

View File

@@ -32,17 +32,23 @@ namespace CreatureLib::Battling {
}
public:
ScriptAggregator(){};
explicit ScriptAggregator(const ArbUt::List<ScriptWrapper>& scripts)
: _scripts(scripts.RawData()), _size(scripts.Count()){};
ScriptAggregator() {};
explicit ScriptAggregator(const ArbUt::List<ScriptWrapper> &scripts)
: _scripts(scripts.RawData()), _size(scripts.Count()) {
Reset();
};
inline void Reset() {
_index = 0;
if (_scripts[_index].IsSet()) {
_setIndex = -1;
if (_size > 0) {
if (_scripts[_index].IsSet()) {
_setIndex = -1;
}
IncrementToNextNotNull(false);
}
IncrementToNextNotNull(false);
}
inline bool HasNext() { return _index < _size; }
std::optional<ArbUt::BorrowedPtr<BattleScript>> GetNextNotNull() {
@@ -54,13 +60,13 @@ namespace CreatureLib::Battling {
}
ArbUt::BorrowedPtr<BattleScript> GetNext() {
auto& current = _scripts[_index];
auto &current = _scripts[_index];
if (!current.IsSet()) {
auto s = current.GetScript();
IncrementToNextNotNull();
return (*s);
} else {
auto& set = current.GetScriptSet()->GetIterator();
auto &set = current.GetScriptSet()->GetIterator();
auto v = set[_setIndex];
IncrementToNextNotNull();
return v;