{"record":{"id":"5b94bafa4a4f2cf8","repo":"EllanJiang/GameFramework","slug":"unload-scene-callbacks-is-invalid","errorCode":null,"errorMessage":"Unload scene callbacks is invalid.","messagePattern":"Unload scene callbacks is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.cs","lineNumber":1747,"sourceCode":"\n            m_ResourceLoader.LoadScene(sceneAssetName, priority, loadSceneCallbacks, userData);\n        }\n\n        /// <summary>\n        /// 异步卸载场景。\n        /// </summary>\n        /// <param name=\"sceneAssetName\">要卸载场景资源的名称。</param>\n        /// <param name=\"unloadSceneCallbacks\">卸载场景回调函数集。</param>\n        public void UnloadScene(string sceneAssetName, UnloadSceneCallbacks unloadSceneCallbacks)\n        {\n            if (string.IsNullOrEmpty(sceneAssetName))\n            {\n                throw new GameFrameworkException(\"Scene asset name is invalid.\");\n            }\n\n            if (unloadSceneCallbacks == null)\n            {\n                throw new GameFrameworkException(\"Unload scene callbacks is invalid.\");\n            }\n\n            m_ResourceLoader.UnloadScene(sceneAssetName, unloadSceneCallbacks, null);\n        }\n\n        /// <summary>\n        /// 异步卸载场景。\n        /// </summary>\n        /// <param name=\"sceneAssetName\">要卸载场景资源的名称。</param>\n        /// <param name=\"unloadSceneCallbacks\">卸载场景回调函数集。</param>\n        /// <param name=\"userData\">用户自定义数据。</param>\n        public void UnloadScene(string sceneAssetName, UnloadSceneCallbacks unloadSceneCallbacks, object userData)\n        {\n            if (string.IsNullOrEmpty(sceneAssetName))\n            {\n                throw new GameFrameworkException(\"Scene asset name is invalid.\");\n            }\n","sourceCodeStart":1729,"sourceCodeEnd":1765,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.cs#L1729-L1765","documentation":"ResourceManager.UnloadScene(string, UnloadSceneCallbacks) validates unloadSceneCallbacks and throws this GameFrameworkException when it is null. Callbacks are required so the caller is informed when the scene unload completes or fails. The check occurs immediately before forwarding to m_ResourceLoader.UnloadScene with a null userData.","triggerScenarios":"Calling UnloadScene(sceneAssetName, unloadSceneCallbacks) with unloadSceneCallbacks == null.","commonSituations":"Fire-and-forget unload attempts passing null; unassigned callback field; helper APIs that wrap UnloadScene and drop the callbacks parameter.","solutions":["Pass an initialized UnloadSceneCallbacks with the success and failure handlers","Provide no-op handlers if you do not care about the result","Fix wrapper methods to require or construct callbacks instead of forwarding null"],"exampleFix":"// before\nresourceManager.UnloadScene(sceneAssetName, null);\n// after\nresourceManager.UnloadScene(sceneAssetName, new UnloadSceneCallbacks(\n    onSuccess => { }, onFailure => { }));","handlingStrategy":"validation","validationCode":"if (unloadSceneCallbacks == null) throw new ArgumentException(\"unloadSceneCallbacks required\", nameof(unloadSceneCallbacks));","typeGuard":"bool HasUnloadCallbacks(UnloadSceneCallbacks? c) => c is not null;","tryCatchPattern":"try { resourceManager.UnloadScene(sceneAssetName, unloadCallbacks); } catch (GameFrameworkException ex) { Log.Error(ex.Message); }","preventionTips":["Construct UnloadSceneCallbacks with success and failure handlers","Do not attempt fire-and-forget unloads with null callbacks","Create a shared helper for unload callbacks to avoid repetition"],"tags":["csharp","gameframework","argument-null","scene-unloading"],"backgroundTag":"null-argument","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}