Skip to content

Commit

Permalink
Fix segfault on behaviour's result update (#520)
Browse files Browse the repository at this point in the history
Move tracing result into terminating behaviour
  • Loading branch information
Gamezar authored Feb 15, 2024
1 parent 6b5ef37 commit 4e9d8ec
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions alica_engine/include/engine/BasicBehaviour.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class BasicBehaviour : private RunnableObject
FAILURE
};

static std::string resultToString(BehResult result);

void doInit() override;
void doRun() override;
void doTerminate() override;
Expand Down
23 changes: 18 additions & 5 deletions alica_engine/src/engine/BasicBehaviour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,26 @@ void BasicBehaviour::doRun()
}
}

std::string BasicBehaviour::resultToString(BehResult result)
{
switch (result) {
case BehResult::SUCCESS:
return "Success";
case BehResult::FAILURE:
return "Failure";
case BehResult::UNKNOWN:
return "Unknown";
}
return ""; // should never reach
}

void BasicBehaviour::doTerminate()
{
if (getTrace()) {
const std::string resultStr = resultToString(_behResult.load());
Logging::logInfo(LOGNAME) << "Behaviour: " << getName() << ", result: " << resultStr;
getTrace()->setTag("Result", resultStr);
}
try {
onTermination();
} catch (...) {
Expand All @@ -91,11 +109,6 @@ void BasicBehaviour::setResult(BehResult result)
auto prev = _behResult.exchange(result);
if (prev != result) {
_planBase->addFastPathEvent(getPlanContext());
if (getTrace()) {
const char* resultStr = (result == BehResult::SUCCESS ? "Success" : "Fail");
Logging::logInfo(LOGNAME) << "Behaviour: " << getName() << ", result: " << resultStr;
getTrace()->setTag("Result", resultStr);
}
}
}

Expand Down

0 comments on commit 4e9d8ec

Please sign in to comment.