You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to create a function map for the EntityManager::addComponent<component>() functions, I was running into an issue where the component objects would be added alphabetically which would result in segfaults as the AI component would always be added first. The AI component depends on the Transform component already being attached to the entity, thus the segfaults.
I couldn't figure out why this was happening as the function map itself is not alphabetical, nor are the entity template json files. Eventually I started digging into the nlohmann::json library which I am using in this project and I discovered that the default behavior for ordering json objects in the library is to sort them alphabetically:
Object Order
The JSON standard defines objects as "an unordered collection of zero or more name/value pairs". As such, an implementation does not need to preserve any specific order of object keys.
Default behavior: sort keys
The default type nlohmann::json uses a std::map to store JSON objects, and thus stores object keys sorted alphabetically.
When trying to create a function map for the
EntityManager::addComponent<component>()
functions, I was running into an issue where the component objects would be added alphabetically which would result in segfaults as theAI
component would always be added first. TheAI
component depends on theTransform
component already being attached to the entity, thus the segfaults.I couldn't figure out why this was happening as the function map itself is not alphabetical, nor are the entity template json files. Eventually I started digging into the nlohmann::json library which I am using in this project and I discovered that the default behavior for ordering json objects in the library is to sort them alphabetically:
So, the
EventManager.cpp
file uses thenlohmann::unordered_json
type.The text was updated successfully, but these errors were encountered: