-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serialization and deserialization of the world changes world behaviour. #230
Comments
Upon further inspection, it appears as if the issue stems from the fact that archetypes use the hashed pointer address of their identifiers as a shorthand to represent their component list, so if the world is duplicated like this these pointer addresses change, and so the component set is not recognised as identical to one already in the archetypes list. This doesn't seem like it's going to be an easy fix :/ |
@Oberdiah thanks for raising this issue! This is indeed a bug, and your minimal example was super helpful. I've been able to write a similar version of your example as a unit test. You're right that the issue is with the hashed pointer addresses. If the identifiers were hashed simply by their values, this wouldn't be an issue, but the hashing is done by pointer address for optimization purposes. But there are actually two additional tables for looking up the identifiers owned by the archetypes stored in brood/src/archetypes/impl_serde.rs Lines 87 to 93 in ec18ed4
So the issue is coming when we are inserting a new entity, and it attempts to look up the archetype. This calls Line 219 in ec18ed4
Archetypes :
The one used for deserialization is But looking at Lines 221 to 227 in ec18ed4
foreign_identifier_lookup here, as that will actually find the existing archetype if there is one.
Looks like this was accidentally introduced in this commit: 59b4b22. I didn't account for the fact that lookup in the I've just pushed a fix to this branch, and I'll get a PR merged and a patch released to crates.io ASAP. Thanks again for raising this :) |
Blimey, that was fast! Once again, thanks for your work on this crate, it’s really such a godsend for my hobby project. |
No problem, I'm glad to help! I've just published the fix as version 0.9.1 on crates.io, let me know if you run into any other issues :) |
Below is a failing test that demonstrates the bug, using bincode for serialization/deserialization. Serde JSON exhibits the same behaviour:
The deserialized world debug prints to the following:
Which is definitely incorrect - there should never be two archetypes containing exactly the same components.
The text was updated successfully, but these errors were encountered: