Skip to content

Commit

Permalink
fix: change typeid check to dynamic_cast (#1409)
Browse files Browse the repository at this point in the history
This PR changes the way we check for compatibility in the `WhiteBoard` as sometimes the typeid check would fail, even if the cast would work.

The reason for the failure is not fully understood, but a `dynamic_cast` is ok in this case, as this is not a time-critical operation.
  • Loading branch information
asalzburger committed Aug 10, 2022
1 parent 968993e commit fdc6075
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,14 @@ inline const T& ActsExamples::WhiteBoard::get(const std::string& name) const {
throw std::out_of_range("Object '" + name + "' does not exists");
}
const IHolder* holder = it->second.get();
if (typeid(T) != holder->type()) {

const auto* castedHolder = dynamic_cast<const HolderT<T>*>(holder);
if (castedHolder == nullptr) {
throw std::out_of_range("Type mismatch for object '" + name + "'");
}

ACTS_VERBOSE("Retrieved object '" << name << "'");
return reinterpret_cast<const HolderT<T>*>(holder)->value;
return castedHolder->value;
}

inline bool ActsExamples::WhiteBoard::exists(const std::string& name) const {
Expand Down

0 comments on commit fdc6075

Please sign in to comment.