{"record":{"id":"1fa76783849c9f1b","repo":"EllanJiang/GameFramework","slug":"main-task-is-invalid","errorCode":null,"errorMessage":"Main task is invalid.","messagePattern":"Main task is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.ResourceLoader.cs","lineNumber":810,"sourceCode":"            public TaskInfo[] GetAllLoadAssetInfos()\n            {\n                return m_TaskPool.GetAllTaskInfos();\n            }\n\n            /// <summary>\n            /// 获取所有加载资源任务的信息。\n            /// </summary>\n            /// <param name=\"results\">所有加载资源任务的信息。</param>\n            public void GetAllLoadAssetInfos(List<TaskInfo> results)\n            {\n                m_TaskPool.GetAllTaskInfos(results);\n            }\n\n            private bool LoadDependencyAsset(string assetName, int priority, LoadResourceTaskBase mainTask, object userData)\n            {\n                if (mainTask == null)\n                {\n                    throw new GameFrameworkException(\"Main task is invalid.\");\n                }\n\n                ResourceInfo resourceInfo = null;\n                string[] dependencyAssetNames = null;\n                if (!CheckAsset(assetName, out resourceInfo, out dependencyAssetNames))\n                {\n                    return false;\n                }\n\n                if (resourceInfo.IsLoadFromBinary)\n                {\n                    return false;\n                }\n\n                LoadDependencyAssetTask dependencyTask = LoadDependencyAssetTask.Create(assetName, priority, resourceInfo, dependencyAssetNames, mainTask, userData);\n                foreach (string dependencyAssetName in dependencyAssetNames)\n                {\n                    if (!LoadDependencyAsset(dependencyAssetName, priority, dependencyTask, userData))","sourceCodeStart":792,"sourceCodeEnd":828,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.ResourceLoader.cs#L792-L828","documentation":"LoadDependencyAsset is a private helper that enqueues a dependency asset into a main LoadResourceTaskBase. If mainTask is null there is no valid task to attach the dependency to, indicating an internal state bug in the task-loading flow, so the framework throws this GameFrameworkException. Normal user code should never see it; it signals a framework-level invariant violation.","triggerScenarios":"An internal call path in which LoadDependencyAsset is invoked with a null mainTask — corrupted task management state, recursive dependency handling passing null, or modifications/hooks in LoadAsset/LoadScene task creation returning null.","commonSituations":"Custom patches to ResourceManager task flow; calling internal load helpers incorrectly from derived/custom resource components; framework version mismatch after partial upgrades of GameFramework assemblies.","solutions":["Inspect custom subclasses/patches of ResourceManager or ResourceLoader that could pass a null task into LoadDependencyAsset.","Update GameFramework to a consistent version so LoadAsset/LoadScene always construct a valid task before processing dependencies.","Check that asset/scene load calls are made after the resource component is initialized so tasks are created properly.","Capture the call stack and file a bug/reproduce with a minimal LoadAsset call if it occurs on unmodified framework code."],"exampleFix":"// before (custom derived loader)\nLoadDependencyAsset(depName, priority, null, userData); // throws\n// after\nvar mainTask = CreateLoadTask(assetName, priority, userData);\nif (mainTask != null)\n    LoadDependencyAsset(depName, priority, mainTask, userData);","handlingStrategy":"try-catch","validationCode":"// C# (only for custom task plumbing)\nif (mainTask == null)\n    throw new InvalidOperationException(\"LoadDependencyAsset requires a non-null main task.\");","typeGuard":"bool HasTask(LoadResourceTaskBase t) => t != null;","tryCatchPattern":"// C#\ntry { LoadAsset(assetName, priority, userData); }\ncatch (GameFrameworkException ex) when (ex.Message == \"Main task is invalid.\")\n{ log.Fatal(\"ResourceManager task state corrupted\", ex); }","preventionTips":["Do not modify or bypass ResourceManager's internal task creation flow.","Keep GameFramework assemblies at one consistent version.","Initialize the ResourceComponent before issuing any asset/scene loads.","If extending the loader, always construct a valid task before adding dependencies."],"tags":["gameframework","resource","task","internal"],"backgroundTag":"internal-invariant-violation","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"}