EllanJiang/GameFramework · error · GameFrameworkException

Resource infos is invalid.

Error message

Resource infos is invalid.

What it means

The ResourceGroupCollection constructor requires a valid Dictionary<ResourceName, ResourceInfo> reference to look up resource metadata. It throws GameFrameworkException("Resource infos is invalid.") when resourceInfos is null, because every resource name aggregated from the groups must be resolved to a ResourceInfo.

Solutions

  1. Ensure ResourceManager resource infos are initialized (InitResources/UpdateResources completed) before constructing the collection.
  2. Pass the manager's actual resource-info dictionary instead of a local null variable.
  3. Guard the construction behind a null check on the dictionary and defer until it is available.

Example fix

// before
var col = new ResourceGroupCollection(groups, null);
// after
if (resourceInfos == null) throw new InvalidOperationException("Init resources first");
var col = new ResourceGroupCollection(groups, resourceInfos);
Defensive patterns

Strategy: validation

Validate before calling

if (resourceInfos == null)
    throw new InvalidOperationException("Resource infos not initialized; call InitResources first");
var col = new ResourceGroupCollection(groups, resourceInfos);

Type guard

bool HasResourceInfos(Dictionary<ResourceName, ResourceInfo> infos) => infos != null && infos.Count > 0;

Try / catch

try { var col = new ResourceGroupCollection(groups, infos); } catch (GameFrameworkException ex) { Log.Error(ex.Message); }

Prevention

When it happens

Trigger: Calling new ResourceGroupCollection(groups, null) — typically the resource-info dictionary failed to load or was never populated before collection construction.

Common situations: Calling the constructor before ResourceManager finished building m_ResourceInfos (e.g. before InitResources/UpdateResources completed), or after a failed resource initialization left the dictionary null.

Related errors


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/7cb2f10738dcc18c. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/Resource/ResourceManager.ResourceGroupCollection.cs:39

            private readonly HashSet<ResourceName> m_ResourceNames;
            private long m_TotalLength;
            private long m_TotalCompressedLength;

            /// <summary>
            /// 初始化资源组集合的新实例。
            /// </summary>
            /// <param name="resourceGroups">资源组集合。</param>
            /// <param name="resourceInfos">资源信息引用。</param>
            public ResourceGroupCollection(ResourceGroup[] resourceGroups, Dictionary<ResourceName, ResourceInfo> resourceInfos)
            {
                if (resourceGroups == null || resourceGroups.Length < 1)
                {
                    throw new GameFrameworkException("Resource groups is invalid.");
                }

                if (resourceInfos == null)
                {
                    throw new GameFrameworkException("Resource infos is invalid.");
                }

                int lastIndex = resourceGroups.Length - 1;
                for (int i = 0; i < lastIndex; i++)
                {
                    if (resourceGroups[i] == null)
                    {
                        throw new GameFrameworkException(Utility.Text.Format("Resource group index '{0}' is invalid.", i));
                    }

                    for (int j = i + 1; j < resourceGroups.Length; j++)
                    {
                        if (resourceGroups[i] == resourceGroups[j])
                        {
                            throw new GameFrameworkException(Utility.Text.Format("Resource group '{0}' duplicated.", resourceGroups[i].Name));
                        }
                    }
                }

View on GitHub (pinned to d0c010b051)