Fix EventManager RTTI failures across shared-library boundaries#3459
Open
taylorhoward92 wants to merge 8 commits intogazebosim:mainfrom
Open
Fix EventManager RTTI failures across shared-library boundaries#3459taylorhoward92 wants to merge 8 commits intogazebosim:mainfrom
taylorhoward92 wants to merge 8 commits intogazebosim:mainfrom
Conversation
When plugins are loaded with RTLD_LOCAL and built with hidden visibility (the default via gz-cmake), each dylib gets its own copy of the RTTI type_info for the same C++ type. This causes three problems in EventManager: 1. dynamic_cast across the boundary returns nullptr even though the object really is the requested type. 2. typeid(E).hash_code() returns different values for the same type in different dylibs, so the unordered_map creates duplicate entries. 3. operator== on type_info references compares pointer identity, which also differs across dylibs. Fix by: - Replacing dynamic_cast with static_cast (the map key already guarantees the correct type by construction). - Switching the Hasher to name-based hashing via std::hash<std::string>(typeid::name()). - Adding a name-based fallback in EqualTo so that the same type loaded from different shared libraries compares equal. Signed-off-by: Taylor Howard <taylor.howard@absiko.com.au>
8a02996 to
6b1df76
Compare
The Hasher functor uses std::hash<std::string> but <string> was not included, causing a cpplint include_what_you_use failure. Generated-by: Claude Code Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Taylor Howard <taylor.howard@absiko.com.au>
11 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🦟 Bug fix
Fixes #1992
Summary
When plugins are loaded with
RTLD_LOCALand built with hidden visibility (the default via gz-cmake), each dylib gets its own copy of the RTTItype_infofor the same C++ type. This causesdynamic_castto returnnullptrinEventManager::Connect,Emit, andConnectionCounteven though the object really is the requested type. It also causestypeid(E).hash_code()andoperator==ontype_inforeferences to disagree across dylib boundaries, creating duplicate map entries.This is the root cause of the issues described in #1992.
Changes
dynamic_castwithstatic_castinConnect(),Emit(), andConnectionCount(). The map key already guarantees the correct type by construction.Hasherto name-based hashing viastd::hash<std::string>(typeid::name()).EqualToso that the same type loaded from different shared libraries compares equal.Checklist
codecheckpassed (See contributing)Generated-by: Claude Code
Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-byandGenerated-bymessages.