{"record":{"id":"6cfe7d016cdd5fbc","repo":"EllanJiang/GameFramework","slug":"load-scene-callbacks-is-invalid","errorCode":null,"errorMessage":"Load scene callbacks is invalid.","messagePattern":"Load scene callbacks is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.cs","lineNumber":1663,"sourceCode":"\n            m_ResourceLoader.UnloadAsset(asset);\n        }\n\n        /// <summary>\n        /// 异步加载场景。\n        /// </summary>\n        /// <param name=\"sceneAssetName\">要加载场景资源的名称。</param>\n        /// <param name=\"loadSceneCallbacks\">加载场景回调函数集。</param>\n        public void LoadScene(string sceneAssetName, LoadSceneCallbacks loadSceneCallbacks)\n        {\n            if (string.IsNullOrEmpty(sceneAssetName))\n            {\n                throw new GameFrameworkException(\"Scene asset name is invalid.\");\n            }\n\n            if (loadSceneCallbacks == null)\n            {\n                throw new GameFrameworkException(\"Load scene callbacks is invalid.\");\n            }\n\n            m_ResourceLoader.LoadScene(sceneAssetName, Constant.DefaultPriority, loadSceneCallbacks, null);\n        }\n\n        /// <summary>\n        /// 异步加载场景。\n        /// </summary>\n        /// <param name=\"sceneAssetName\">要加载场景资源的名称。</param>\n        /// <param name=\"priority\">加载场景资源的优先级。</param>\n        /// <param name=\"loadSceneCallbacks\">加载场景回调函数集。</param>\n        public void LoadScene(string sceneAssetName, int priority, LoadSceneCallbacks loadSceneCallbacks)\n        {\n            if (string.IsNullOrEmpty(sceneAssetName))\n            {\n                throw new GameFrameworkException(\"Scene asset name is invalid.\");\n            }\n","sourceCodeStart":1645,"sourceCodeEnd":1681,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.cs#L1645-L1681","documentation":"ResourceManager.LoadScene(sceneAssetName, loadSceneCallbacks) throws this when loadSceneCallbacks is null. Scene loading is asynchronous, so the framework requires a LoadSceneCallbacks object to always deliver success, failure, and dependency-asset notifications.","triggerScenarios":"Calling LoadScene with null as the LoadSceneCallbacks parameter, or a helper that conditionally builds callbacks returning null.","commonSituations":"A wrapper with an optional callbacks argument defaulting to null; a refactoring that removed the LoadSceneCallbacks construction; passing null because scene load 'always succeeds' in the current flow.","solutions":["Pass a constructed LoadSceneCallbacks instance with at least the scene-load success and failure handlers.","Ensure any helper/wrapper always supplies a default callbacks object when the caller omits one.","Use empty-bodied handlers instead of null when notifications are not needed."],"exampleFix":"// before\nm_ResourceManager.LoadScene(sceneAssetName, null);\n// after\nvar callbacks = new LoadSceneCallbacks(OnSceneLoadSuccess, OnSceneLoadFailure, OnSceneLoadUpdate, OnSceneLoadDependencyAsset);\nm_ResourceManager.LoadScene(sceneAssetName, callbacks);","handlingStrategy":"validation","validationCode":"if (loadSceneCallbacks == null)\n{\n    loadSceneCallbacks = new LoadSceneCallbacks(OnSceneLoadSuccess, OnSceneLoadFailure);\n}","typeGuard":"static bool HasCallbacks(LoadSceneCallbacks c) => c != null;","tryCatchPattern":"try\n{\n    m_ResourceManager.LoadScene(sceneAssetName, callbacks);\n}\ncatch (GameFrameworkException ex)\n{\n    Log.Error(\"LoadScene failed: {0}\", ex.Message);\n}","preventionTips":["Always construct LoadSceneCallbacks at the call site.","Provide default handlers in wrapper methods instead of null parameters.","Verify async loads always have failure handlers to avoid silent hangs."],"tags":["csharp","gameframework","argument-validation","callbacks"],"backgroundTag":"missing-required-argument","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}