Reset on initialization in ScriptAggregator, fixes segfault when calling Reset on an empty Aggregator.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
33f796eff8
commit
9f091308b0
|
@ -33,16 +33,22 @@ namespace CreatureLib::Battling {
|
|||
|
||||
public:
|
||||
ScriptAggregator() {};
|
||||
|
||||
explicit ScriptAggregator(const ArbUt::List<ScriptWrapper> &scripts)
|
||||
: _scripts(scripts.RawData()), _size(scripts.Count()){};
|
||||
: _scripts(scripts.RawData()), _size(scripts.Count()) {
|
||||
Reset();
|
||||
};
|
||||
|
||||
inline void Reset() {
|
||||
_index = 0;
|
||||
if (_size > 0) {
|
||||
if (_scripts[_index].IsSet()) {
|
||||
_setIndex = -1;
|
||||
}
|
||||
IncrementToNextNotNull(false);
|
||||
}
|
||||
}
|
||||
|
||||
inline bool HasNext() { return _index < _size; }
|
||||
|
||||
std::optional<ArbUt::BorrowedPtr<BattleScript>> GetNextNotNull() {
|
||||
|
|
|
@ -13,9 +13,11 @@ private:
|
|||
|
||||
public:
|
||||
explicit TestScript(const ArbUt::StringView &name) : _name(name) {};
|
||||
|
||||
const ArbUt::StringView &GetName() const noexcept override { return _name; }
|
||||
|
||||
void TestMethod(int &runCount) { runCount++; }
|
||||
|
||||
BattleScript *Clone() override { return new TestScript(_name); }
|
||||
};
|
||||
|
||||
|
@ -95,7 +97,8 @@ TEST_CASE("Script Aggregator properly iterates data of Script and Script Set.")
|
|||
set.Add(script2);
|
||||
set.Add(script3);
|
||||
auto vec =
|
||||
ArbUt::List<ScriptWrapper>{ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<BattleScript>*>(&script)),
|
||||
ArbUt::List<ScriptWrapper>{
|
||||
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<BattleScript> *>(&script)),
|
||||
ScriptWrapper::FromSet(&set)};
|
||||
auto aggr = ScriptAggregator(vec);
|
||||
while (aggr.HasNext()) {
|
||||
|
|
Loading…
Reference in New Issue