EllanJiang/GameFramework · error · GameFrameworkException
Resource target ' ' dependency asset reference count is…
Error message
Resource target '{0}' dependency asset reference count is invalid. What it means
Thrown by ResourceObject.Release when decrementing a dependency asset's reference count finds no entry in m_ResourceDependencyCount. It indicates the resource object's dependency bookkeeping is inconsistent: the dependency was never registered or was already removed, so releasing it would corrupt counts.
Solutions
- Ensure each asset is released exactly once — pair every LoadAsset result with a single Unspawn/Release call.
- Do not release assets that failed to load or that were never returned as a handle.
- Avoid mixing asset handles across resource manager (or ResourceLoader) instances.
- Catch GameFrameworkException here and log the asset Name to identify the leaking/double-released object.
Example fix
// before (double release in two systems)
resourceComponent.Unspawn(asset);
entityLogic.OnDestroy(); // internally calls Unspawn(asset) again
// after
if (!released) { resourceComponent.Unspawn(asset); released = true; } Defensive patterns
Strategy: try-catch
Validate before calling
// Track your own handle set to detect double release
if (!releasedHandles.Add(asset)) throw new InvalidOperationException("Asset released twice"); Type guard
bool CanRelease(ResourceObject obj) => obj != null && obj.Target != null;
Try / catch
try { resourceComponent.Unspawn(asset); }
catch (GameFrameworkException ex) { Log.Error("Refcount invalid, likely double release: " + ex.Message); } Prevention
- Pair every load with exactly one release/unspawn
- Never release assets that failed to load
- Do not share handles across ResourceLoader instances
- Centralize release logic in one owner
When it happens
Trigger: Calling Unspawn/Release on a resource object whose dependency assets were removed from m_ResourceDependencyCount beforehand — e.g. double-releasing the same asset, releasing an asset whose load was partially completed/failed, or mixing load results from different ResourceLoader lifetimes.
Common situations: Double-free of an asset handle (release called twice by different systems), releasing assets after the resource manager's pools were rebuilt, or bugs in dependent-asset load failure cleanup leaving partial counts.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Resource loader is invalid.
- Resource target ' ' reference count is ' ' larger than 0.
- Asset target ' ' dependency asset reference count is…
- Asset target ' ' reference count is ' ' larger than 0.
- Can not find asset of scene
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/93e43c3340081cb5.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Resource/ResourceManager.ResourceLoader.ResourceObject.cs:114
{
if (!isShutdown)
{
int targetReferenceCount = 0;
if (m_ResourceLoader.m_ResourceDependencyCount.TryGetValue(Target, out targetReferenceCount) && targetReferenceCount > 0)
{
throw new GameFrameworkException(Utility.Text.Format("Resource target '{0}' reference count is '{1}' larger than 0.", Name, targetReferenceCount));
}
foreach (object dependencyResource in m_DependencyResources)
{
int referenceCount = 0;
if (m_ResourceLoader.m_ResourceDependencyCount.TryGetValue(dependencyResource, out referenceCount))
{
m_ResourceLoader.m_ResourceDependencyCount[dependencyResource] = referenceCount - 1;
}
else
{
throw new GameFrameworkException(Utility.Text.Format("Resource target '{0}' dependency asset reference count is invalid.", Name));
}
}
}
m_ResourceLoader.m_ResourceDependencyCount.Remove(Target);
m_ResourceHelper.Release(Target);
}
}
}
}
}
View on GitHub (pinned to d0c010b051)