Skip to content
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

Fixed map replacement crash, and added some extra debug output #6

Merged
merged 1 commit into from
Jul 13, 2021

Conversation

josephduchesne
Copy link

I changed the way that map layer reloading is done to avoid causing problems for the collision filter registry.

The collision filter registry creates a map of layer names to collision filter IDs, which correspond to box2d's bitfield collision filtering. When layers are loaded, their names are assigned collision filter ids (0-15), and when models are loaded, their physics bodies are assigned corresponding bitmasks. Changing that mapping mid-run is not currently handled, since it would require re-calculating the CFR bitmasks for all active physics bodies (layers and models). This is possible to implement, but fairly complicated to do.

Instead, when a new set of layers is loaded, the CFR is maintained unchanged. New layer names get new CFR entries, but if the name already exists, the CFR is not changed. Instead, the existing layer is deleted, and then it's replacement is loaded.

If a layer doesn't exist in the new layer list, it's flagged for deletion, but because the CFR doesn't handle deletion gracefully in the current code, the layer is left alone, but it's contents is cleared (which clears the visualization and box2d entities for that layer).

I've tested loading between two different world files about 40 times (repeat loading the same world, and switching back and forth), and this seems stable. Let me know if it works for your use case!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants