{"record":{"id":"74346566e54f5330","repo":"EllanJiang/GameFramework","slug":"resource-is-invalid","errorCode":null,"errorMessage":"Resource is invalid.","messagePattern":"Resource is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Resource/ResourceManager.ResourceLoader.AssetObject.cs","lineNumber":54,"sourceCode":"                {\n                    get\n                    {\n                        int targetReferenceCount = 0;\n                        m_ResourceLoader.m_AssetDependencyCount.TryGetValue(Target, out targetReferenceCount);\n                        return base.CustomCanReleaseFlag && targetReferenceCount <= 0;\n                    }\n                }\n\n                public static AssetObject Create(string name, object target, List<object> dependencyAssets, object resource, IResourceHelper resourceHelper, ResourceLoader resourceLoader)\n                {\n                    if (dependencyAssets == null)\n                    {\n                        throw new GameFrameworkException(\"Dependency assets is invalid.\");\n                    }\n\n                    if (resource == null)\n                    {\n                        throw new GameFrameworkException(\"Resource is invalid.\");\n                    }\n\n                    if (resourceHelper == null)\n                    {\n                        throw new GameFrameworkException(\"Resource helper is invalid.\");\n                    }\n\n                    if (resourceLoader == null)\n                    {\n                        throw new GameFrameworkException(\"Resource loader is invalid.\");\n                    }\n\n                    AssetObject assetObject = ReferencePool.Acquire<AssetObject>();\n                    assetObject.Initialize(name, target);\n                    assetObject.m_DependencyAssets.AddRange(dependencyAssets);\n                    assetObject.m_Resource = resource;\n                    assetObject.m_ResourceHelper = resourceHelper;\n                    assetObject.m_ResourceLoader = resourceLoader;","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Resource/ResourceManager.ResourceLoader.AssetObject.cs#L36-L72","documentation":"AssetObject.Create requires a non-null resource; the asset object must reference the underlying resource object it was loaded from so it can be ref-counted in the resource pool. A null resource means the caller tried to register an asset with no backing resource.","triggerScenarios":"Calling AssetObject.Create (directly or via ResourceLoader paths) with resource == null, e.g. when a custom load routine passes the loaded asset as target but forgets the resource parameter.","commonSituations":"Custom IResourceHelper/ResourceLoader integration that returns the asset but not its resource handle; calling Create in a load-success callback where the resource lookup failed silently and null was forwarded.","solutions":["Ensure the load pipeline resolves the Resource object and pass it to AssetObject.Create.","Check your IResourceHelper implementation so a successful load always yields a non-null resource.","Assert/verify the resource parameter at the call site before invoking Create."],"exampleFix":"// before\nAssetObject.Create(name, target, deps, null, helper, loader);\n// after\nvar resource = m_ResourcePool.Spawn(resourceName) as Resource;\nAssetObject.Create(name, target, deps, resource, helper, loader);","handlingStrategy":"validation","validationCode":"if (resource == null) throw new InvalidOperationException(\"Resource must be resolved before AssetObject.Create.\");","typeGuard":"bool HasResource(object resource) => resource != null;","tryCatchPattern":null,"preventionTips":["Resolve the Resource from the pool before creating the AssetObject.","Make IResourceHelper implementations guarantee non-null resources on success callbacks.","Assert non-null resource in load-success callbacks."],"tags":["argument-validation","resource","gameframework"],"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"}