{"record":{"id":"94079ea0320a67ec","repo":"stride3d/stride","slug":"already-initialized","errorCode":null,"errorMessage":"Already initialized.","messagePattern":"Already initialized\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Games/GameSystemCollection.cs","lineNumber":203,"sourceCode":"                foreach (var contentable in contentableGameSystems)\n                {\n                    currentlyContentGameSystems.Add(contentable);\n                }\n            }\n\n            foreach (var contentable in currentlyContentGameSystems)\n            {\n                contentable.UnloadContent();\n            }\n\n            currentlyContentGameSystems.Clear();\n        }\n\n        public void Initialize()\n        {\n            if (State != GameSystemState.None)\n            {\n                throw new InvalidOperationException(\"Already initialized.\");\n            }\n\n            State = GameSystemState.Initialized;\n\n            InitializePendingGameSystems();\n        }\n\n        private void InitializePendingGameSystems()\n        {\n            // Add all game systems that were added to this game instance before the game started.\n            while (pendingGameSystems.Count != 0)\n            {\n                var gameSystemName = GetGameSystemName(pendingGameSystems[0]);\n                using (var profile = Profiler.Begin(GameProfilingKeys.GameSystemInitialize, gameSystemName))\n                    pendingGameSystems[0].Initialize();\n                if (State == GameSystemState.ContentLoaded && pendingGameSystems[0] is IContentable)\n                {\n                    var contentable = (IContentable)pendingGameSystems[0];","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Games/GameSystemCollection.cs#L185-L221","documentation":"GameSystemCollection.Initialize throws this InvalidOperationException if called when State is anything other than None, i.e. the collection has already been initialized. This prevents double initialization of game systems.","triggerScenarios":"Calling Initialize() twice on the same GameSystemCollection; calling it on a collection that LoadContent already advanced past Initialized; shared collection initialized by both host code and Game.","commonSituations":"Re-initializing after a restart without recreating systems; both a custom host and the game engine initializing the same systems; accidental duplicate init calls in test setup.","solutions":["Call Initialize() only once per collection instance, or create a new collection for a new lifecycle","Check State == GameSystemState.None before calling Initialize","Make init code idempotent at the call site (track your own initialized flag)"],"exampleFix":"// before\nsystems.Initialize();\nsystems.Initialize(); // throws\n// after\nif (systems.State == GameSystemState.None) systems.Initialize();","handlingStrategy":"validation","validationCode":"if (systems.State == GameSystemState.None) systems.Initialize();","typeGuard":null,"tryCatchPattern":"try { systems.Initialize(); } catch (InvalidOperationException ex) when (ex.Message == \"Already initialized.\") { /* already done, no-op */ }","preventionTips":["Initialize each collection exactly once","Recreate the collection for a new lifecycle","Centralize init in one owner component"],"tags":["lifecycle","game-systems","invalid-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}