EllanJiang/GameFramework · error · GameFrameworkException

Resource groups is invalid.

Error message

Resource groups is invalid.

What it means

The ResourceGroupCollection constructor aggregates multiple ResourceGroup objects and requires a non-empty array of them. It throws GameFrameworkException("Resource groups is invalid.") when resourceGroups is null or has length 0, because the collection would otherwise have nothing to aggregate.

Solutions

  1. Check that the groups array is non-null and contains at least one ResourceGroup before constructing the collection.
  2. Fix the group-selection logic so at least one valid group is collected.
  3. If an empty selection is legitimate, skip creating the collection instead of constructing it.

Example fix

// before
ResourceGroup[] groups = GetSelectedGroups(); // may be empty
var col = new ResourceGroupCollection(groups, resourceInfos);
// after
ResourceGroup[] groups = GetSelectedGroups();
if (groups == null || groups.Length == 0) return; // or log/skip
var col = new ResourceGroupCollection(groups, resourceInfos);
Defensive patterns

Strategy: validation

Validate before calling

if (groups == null || groups.Length == 0)
    throw new InvalidOperationException("At least one resource group is required");
var col = new ResourceGroupCollection(groups, infos);

Type guard

bool IsValidGroups(ResourceGroup[] groups) => groups != null && groups.Length > 0;

Try / catch

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

Prevention

When it happens

Trigger: Calling new ResourceGroupCollection(null, infos) or new ResourceGroupCollection(new ResourceGroup[0], infos).

Common situations: Building an update/verification set from groups selected by name where no group matched the filter, producing an empty or null array before constructing the collection.

Related errors


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

Appendix: source

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

        /// </summary>
        private sealed class ResourceGroupCollection : IResourceGroupCollection
        {
            private readonly ResourceGroup[] m_ResourceGroups;
            private readonly Dictionary<ResourceName, ResourceInfo> m_ResourceInfos;
            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])

View on GitHub (pinned to d0c010b051)