-
-
Couldn't load subscription status.
- Fork 1.2k
Fix Cinematic initialization and serialization bugs #2560
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
base: master
Are you sure you want to change the base?
Conversation
| */ | ||
| public AnimEvent(AnimComposer composer, String actionName, | ||
| String layerName) { | ||
| this.model = composer.getSpatial(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any instance where composer.getSpatial() returns null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm, I see you have null checks later.
| super.write(exporter); | ||
| OutputCapsule capsule = exporter.getCapsule(this); | ||
|
|
||
| capsule.write(model, "model", null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saving the model here will create a duplicate model on load.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see that you're switching out the original for the duplicate loaded from here. This is still really dangerous for several reasons:
- Possible infinite recursion: event saves model, which (directly or indirectly) saves the event.
- At least double memory footprint for the model.
- Multiple spatials are allowed to have the same name.
- Something else may be acting on the original spatial, and expecting it to still be attached.
It'd be ideal if model's reference could be saved instead of the model itself. Imo, that is a serious limitation of the serializer.
| super.write(ex); | ||
| OutputCapsule oc = ex.getCapsule(this); | ||
| oc.write(cinematicEvents.toArray(new CinematicEvent[cinematicEvents.size()]), "cinematicEvents", null); | ||
| oc.writeSavableArrayList((ArrayList) cinematicEvents, "cinematicEvents", null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If cinematicEvents is expected to be an ArrayList, just make it an ArrayList instead of a List.
Refactors and Improves the Cinematic class
This pull request enhances the
Cinematicclass, focusing on better documentation, serialization improvements, and memory management. Key updates include:SavableArrayListserialization/deserialization.Applicationfield to the class, initialized duringinitialize()and passed to event initialization for consistency.clearCameras()method to properly detach and clear all camera nodes from the scene, now called fromcleanup()to avoid memory leaks.initializedflag, clearing events, and removing camera nodes.cinematicEventslist non-final for deserialization.These changes improve maintainability, clarity, and the robustness of cinematic lifecycle management in the engine.
Enhance AnimEvent Serialization and Model Handling
This PR introduces improvements to the
AnimEventclass in thecom.jme3.cinematic.eventspackage by enhancing how animation events are associated with their models and how they are serialized/deserialized. The changes ensure more robust handling ofAnimComposerand the associatedSpatialmodel, especially when saving and loading animation events.Key Changes
Introduced a
private Spatial modelfield toAnimEventto keep track of the model associated with the animation event.modelfield from theAnimComposer.In
initEvent, if thecomposeris not set but themodelis, the code attempts to retrieve the correctAnimComposerfrom the model, ensuring reliable initialization even after deserialization.modelfield is now written to and read from the JME capsules, replacing the direct serialization ofcinematicandcomposerfields (which are no longer serialized).Added a custom
dispose()method to clean up references tocinematicandcomposerwhen the event is disposed, aiding memory management.Updated the copyright year.
Motivation
These changes address issues related to the persistence and restoration of animation events across sessions, improving the reliability of cinematic workflows in jMonkeyEngine. By serializing the model reference and reconstructing the composer as needed, the risk of null references or mismatched state is reduced.
Impact