EllanJiang/GameFramework · error · GameFrameworkException
Resource group index
Error message
Resource group index '{0}' is invalid. What it means
During construction, ResourceGroupCollection validates every element of the resourceGroups array. It throws GameFrameworkException("Resource group index '{0}' is invalid.") when it encounters a null ResourceGroup at any index except the last (the last element is validated separately), reporting the offending index.
Solutions
- Filter out null entries with LINQ (groups.Where(g => g != null).ToArray()) before constructing.
- Fix the code that looks up groups by name so missing names are reported instead of inserting null.
- Verify all requested group names exist via ResourceManager.HasResourceGroup before assembling the array.
Example fix
// before
var groups = new ResourceGroup[] { rm.GetResourceGroup("UI"), rm.GetResourceGroup("Deleted") }; // second may be null
var col = new ResourceGroupCollection(groups, infos);
// after
var groups = new[] { rm.GetResourceGroup("UI"), rm.GetResourceGroup("Scene") }
.Where(g => g != null).ToArray();
var col = new ResourceGroupCollection(groups, infos); Defensive patterns
Strategy: validation
Validate before calling
groups = groups.Where(g => g != null).ToArray(); var col = new ResourceGroupCollection(groups, infos);
Type guard
bool AllGroupsNonNull(ResourceGroup[] groups) => groups.All(g => g != null);
Try / catch
try { var col = new ResourceGroupCollection(groups, infos); } catch (GameFrameworkException ex) { Log.Error(ex.Message); } Prevention
- Always filter nulls from group arrays before use
- Make group lookup methods throw or log on missing names instead of returning null
- Verify group names with HasResourceGroup before lookup
When it happens
Trigger: Passing an array containing null entries, e.g. new ResourceGroupCollection(new ResourceGroup[] { groupA, null, groupC }, infos).
Common situations: Building the array from a lookup that returned null for missing group names (dictionary TryGetValue default) and never filtering nulls; hardcoded group name lists where one name was renamed or removed.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Web request agent helper is invalid.
- Owner is invalid.
- Resource manager is invalid.
- Data provider helper is invalid.
- Type is invalid.
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/a638517c2fd248e1.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Resource/ResourceManager.ResourceGroupCollection.cs:47
/// <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));
}
}
}
if (resourceGroups[lastIndex] == null)
{
throw new GameFrameworkException(Utility.Text.Format("Resource group index '{0}' is invalid.", lastIndex));
}
m_ResourceGroups = resourceGroups;
m_ResourceInfos = resourceInfos;View on GitHub (pinned to d0c010b051)