Fixed map replacement crash, and added some extra debug output #6
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.
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!