EllanJiang/GameFramework · error · GameFrameworkException
Resource target ' ' reference count is ' ' larger than 0.
Error message
Resource target '{0}' reference count is '{1}' larger than 0. What it means
During Release (when not shutting down), GameFramework refuses to free a resource whose target still has a dependency reference count > 0, because unloading it would destroy memory that other assets depend on. It throws with the resource name and offending count, indicating an internal reference-counting inconsistency.
Solutions
- Ensure every LoadAsset has a matching UnloadAsset so dependency counts drop to 0 before release.
- Release resources only via the normal ResourceLoader eviction/shutdown flow, not manually.
- Check custom code that decrements m_ResourceDependencyCount for missed or extra decrements.
- If truly shutting down, use the shutdown path where isShutdown=true skips the check.
Example fix
// before
resourceComponent.UnloadAsset(uiAsset); // but dependent prefab assets still loaded
resourceLoader.Release(resourceObject, false);
// after
foreach (var dep in dependentAssets) { resourceComponent.UnloadAsset(dep); }
// then release only when reference count reaches 0 Defensive patterns
Strategy: try-catch
Validate before calling
if (m_ResourceDependencyCount.TryGetValue(resourceObject.Target, out int count) && count > 0)
{
Debug.LogError($"Cannot release '{resourceObject.Name}': {count} dependency references remain.");
return;
} Try / catch
try
{
resourceComponent.CheckResource / custom release path...
}
catch (GameFrameworkException ex) when (ex.Message.Contains("larger than 0"))
{
Debug.LogError("Released a resource that still has dependent references; fix acquire/release pairing.");
} Prevention
- Pair every LoadAsset with an UnloadAsset so counts reach zero before release.
- Never release resources manually; rely on ResourceLoader eviction/shutdown.
- Audit custom code touching m_ResourceDependencyCount for balanced increments/decrements.
- Only skip the check on full shutdown (isShutdown=true) where all resources are discarded.
When it happens
Trigger: A resource is released while m_ResourceDependencyCount still records references from other loaded assets/objects — e.g. release called before dependent assets were unloaded, custom code decrementing/releasing out of order, or callers forgetting to unload assets that incremented the count.
Common situations: Custom resource management that releases resources while scenes/UI still hold dependent assets; asymmetric acquire/release of AssetObjects; shutting down subsets of the resource system manually instead of on full shutdown (where isShutdown bypasses this check).
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 helper is invalid.
- Resource target ' ' dependency asset reference count is…
- appendErrorMessage
- Asset target ' ' dependency asset reference count is…
AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15).
Data as JSON: /api/errors/41681b6dbb421eda.
Report an issue: GitHub.
Appendix: source
Thrown at GameFramework/Resource/ResourceManager.ResourceLoader.ResourceObject.cs:102
int referenceCount = 0;
if (m_ResourceLoader.m_ResourceDependencyCount.TryGetValue(dependencyResource, out referenceCount))
{
m_ResourceLoader.m_ResourceDependencyCount[dependencyResource] = referenceCount + 1;
}
else
{
m_ResourceLoader.m_ResourceDependencyCount.Add(dependencyResource, 1);
}
}
protected internal override void Release(bool isShutdown)
{
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)