{"record":{"id":"169868a7049c85c1","repo":"FyroxEngine/Fyrox","slug":"animation-pool-must-be-empty-on-load","errorCode":null,"errorMessage":"Animation pool must be empty on load!","messagePattern":"Animation pool must be empty on load!","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"fyrox-animation/src/lib.rs","lineNumber":1113,"sourceCode":"    /// Removes queued animation events from every animation in the container.\n    ///\n    /// # Potential use cases\n    ///\n    /// Sometimes there is a need to use animation events only from one frame, in this case you should clear events each frame.\n    /// This situation might come up when you have multiple animations with signals, but at each frame not every event gets\n    /// processed. This might result in unwanted side effects, like multiple attack events may result in huge damage in a single\n    /// frame.\n    pub fn clear_animation_events(&mut self) {\n        for animation in self.pool.iter_mut() {\n            animation.events.clear();\n        }\n    }\n}\n\nimpl<T: EntityId> Visit for AnimationContainer<T> {\n    fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {\n        if visitor.is_reading() && self.pool.get_capacity() != 0 {\n            panic!(\"Animation pool must be empty on load!\");\n        }\n\n        let mut region = visitor.enter_region(name)?;\n\n        self.pool.visit(\"Pool\", &mut region)?;\n\n        Ok(())\n    }\n}\n\nimpl<T: EntityId> Index<Handle<Animation<T>>> for AnimationContainer<T> {\n    type Output = Animation<T>;\n\n    fn index(&self, index: Handle<Animation<T>>) -> &Self::Output {\n        &self.pool[index]\n    }\n}\n","sourceCodeStart":1095,"sourceCodeEnd":1131,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-animation/src/lib.rs#L1095-L1131","documentation":"AnimationContainer's Visit impl panics during deserialization when the animation pool already holds objects. Loading (reading) a container assumes it was freshly constructed with an empty pool; deserializing into a container with existing animations would append/mix pool records and corrupt indices. The library therefore enforces that the pool has zero capacity before read-mode visiting begins.","triggerScenarios":"Calling Visitor::read/load into an AnimationContainer whose internal pool has non-zero capacity, e.g. reusing an already-populated container as the deserialization target, or calling load twice on the same container.","commonSituations":"Reusing a scene/animation container across level reloads without recreating it; deserializing saved state into a live container that still contains animations from a previous session.","solutions":["Deserialize into a freshly constructed AnimationContainer (AnimationContainer::new()) instead of a reused one.","If reloading, drop the old container (or clear its pool) before starting the visit.","Check that custom save/load code does not pass a container that was already populated from a scene load."],"exampleFix":"// before\nlet mut animations = scene.animations_mut(); // already populated\nanimations.visit(\"Animations\", &mut visitor)?;\n// after\nlet mut animations = AnimationContainer::new(); // empty pool on load\nanimations.visit(\"Animations\", &mut visitor)?;\n*scene.animations_mut() = animations;","handlingStrategy":"validation","validationCode":"// fyrox (Rust) - ensure container is empty before loading\nassert!(container.pool.get_capacity() == 0, \"pool must be empty before read-visit\");","typeGuard":null,"tryCatchPattern":"// panics are not catchable in Rust safely; prevent instead:\nlet container = AnimationContainer::new(); // always load into fresh container","preventionTips":["Always deserialize into a newly constructed AnimationContainer.","Never reuse containers across loads/reloads without recreating them.","Swap the loaded container into the scene after visiting completes."],"tags":["serialization","panic","pool","deserialization"],"backgroundTag":"invalid-state-transition","analyzedSha":"76c91aad8eca488ce527b1af707be8b3b24ad72d","analyzedAt":"2026-09-10T16:04:01.633Z","contentChangedAt":"2026-09-10T16:04:01.633Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}