{"record":{"id":"5416847f327c07e4","repo":"EllanJiang/GameFramework","slug":"task-is-invalid-resourcemanager-resourceloader","errorCode":null,"errorMessage":"Task is invalid.","messagePattern":"Task is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.ResourceLoader.LoadResourceAgent.cs","lineNumber":147,"sourceCode":"                }\n\n                public static void Clear()\n                {\n                    s_CachedResourceNames.Clear();\n                    s_LoadingAssetNames.Clear();\n                    s_LoadingResourceNames.Clear();\n                }\n\n                /// <summary>\n                /// 开始处理加载资源任务。\n                /// </summary>\n                /// <param name=\"task\">要处理的加载资源任务。</param>\n                /// <returns>开始处理任务的状态。</returns>\n                public StartTaskStatus Start(LoadResourceTaskBase task)\n                {\n                    if (task == null)\n                    {\n                        throw new GameFrameworkException(\"Task is invalid.\");\n                    }\n\n                    m_Task = task;\n                    m_Task.StartTime = DateTime.UtcNow;\n                    ResourceInfo resourceInfo = m_Task.ResourceInfo;\n\n                    if (!resourceInfo.Ready)\n                    {\n                        m_Task.StartTime = default(DateTime);\n                        return StartTaskStatus.HasToWait;\n                    }\n\n                    if (IsAssetLoading(m_Task.AssetName))\n                    {\n                        m_Task.StartTime = default(DateTime);\n                        return StartTaskStatus.HasToWait;\n                    }\n","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.ResourceLoader.LoadResourceAgent.cs#L129-L165","documentation":"LoadResourceAgent.Start receives the LoadResourceTask to execute and immediately validates it. A null task means there is nothing to process and the agent's state (m_Task, StartTime, ResourceInfo) could not be set up, so GameFramework throws.","triggerScenarios":"The internal task loop feeding a null LoadResourceTaskBase to an agent — possible when a task was consumed/removed twice, or custom code calls Start(null) directly.","commonSituations":"Custom modifications to the resource task queue (double dequeue, missing null check after TryDequeue); manually driving agents in unit tests without a task; version-upgrade code that changed task creation flow.","solutions":["Never call Start directly with null; let ResourceLoader's task loop manage tasks and check TryDequeue results.","Fix task-queue logic that dequeues or cancels a task twice.","In custom drivers/tests, construct a valid LoadResourceTask (via LoadResourceTask.Create) before calling Start.","Add a null check after TryDequeue in any custom scheduling code."],"exampleFix":"// before\nLoadResourceTaskBase task = null;\nagent.Start(task);\n// after\nif (m_TaskQueue.TryDequeue(out LoadResourceTaskBase task) && task != null)\n{\n    agent.Start(task);\n}","handlingStrategy":"validation","validationCode":"if (task == null) return StartTaskStatus.UnknownError; // guard before Start\nDebug.Assert(task != null, \"Cannot start a null LoadResourceTask\");","typeGuard":"bool IsValidTask(LoadResourceTaskBase t) => t != null;","tryCatchPattern":"try\n{\n    var status = agent.Start(task);\n}\ncatch (GameFrameworkException ex) when (ex.Message == \"Task is invalid.\")\n{\n    Debug.LogError(\"Task queue produced a null task; check dequeue logic.\");\n}","preventionTips":["Let ResourceLoader manage the task queue; avoid calling Start directly.","Null-check results of TryDequeue in custom scheduling code.","Ensure tasks are not cancelled/dequeued twice.","When driving agents in tests, build a real LoadResourceTask via LoadResourceTask.Create."],"tags":["gameframework","unity","null-argument","task-scheduling","resource-loading"],"backgroundTag":"null-argument","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}