EllanJiang/GameFramework · error · GameFrameworkException

Asset target ' ' dependency asset reference count is…

Error message

Asset target '{0}' dependency asset reference count is invalid.

What it means

During AssetObject.Release, the loader decrements the dependency reference count for each dependency asset. If a dependency asset has no entry in m_AssetDependencyCount at all, the counts are out of sync with what was recorded at load time, so the framework throws. This indicates the dependency bookkeeping was corrupted or the asset object state diverged from the loader's dictionaries.

Solutions

  1. Ensure each asset is unloaded exactly once — guard against double UnloadAsset calls.
  2. Keep all AssetObject creation/release through ResourceLoader so dependency counts are incremented/decremented symmetrically.
  3. If you clear or reset loader dictionaries, release all live AssetObjects first.
  4. Log Name and the dependency list at release time to find which dependency lost its count entry.

Example fix

// before
if (m_Loaded) { loader.UnloadAsset(asset); } // flag not reset, second call throws
// after
if (m_Loaded) { loader.UnloadAsset(asset); m_Loaded = false; }
Defensive patterns

Strategy: validation

Validate before calling

bool CanUnload(object asset) => m_UnloadedAssets.Add(asset); // returns false on duplicate unload
if (!CanUnload(asset)) return;

Try / catch

try { loader.UnloadAsset(asset); }
catch (GameFrameworkException ex) { Log.Error("Dependency count out of sync for {0}: {1}", assetName, ex.Message); }

Prevention

When it happens

Trigger: Releasing an AssetObject whose m_DependencyAssets contains entries never registered in m_AssetDependencyCount (e.g. counts already removed by a prior release, or dependency list mutated after Create).

Common situations: Calling UnloadAsset twice on the same asset; mixing manual AssetObject manipulation with the loader's ref counting; loader state reset (dictionary cleared) while AssetObjects still held.

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


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

Appendix: source

Thrown at GameFramework/Resource/ResourceManager.ResourceLoader.AssetObject.cs:127

                {
                    if (!isShutdown)
                    {
                        int targetReferenceCount = 0;
                        if (m_ResourceLoader.m_AssetDependencyCount.TryGetValue(Target, out targetReferenceCount) && targetReferenceCount > 0)
                        {
                            throw new GameFrameworkException(Utility.Text.Format("Asset target '{0}' reference count is '{1}' larger than 0.", Name, targetReferenceCount));
                        }

                        foreach (object dependencyAsset in m_DependencyAssets)
                        {
                            int referenceCount = 0;
                            if (m_ResourceLoader.m_AssetDependencyCount.TryGetValue(dependencyAsset, out referenceCount))
                            {
                                m_ResourceLoader.m_AssetDependencyCount[dependencyAsset] = referenceCount - 1;
                            }
                            else
                            {
                                throw new GameFrameworkException(Utility.Text.Format("Asset target '{0}' dependency asset reference count is invalid.", Name));
                            }
                        }

                        m_ResourceLoader.m_ResourcePool.Unspawn(m_Resource);
                    }

                    m_ResourceLoader.m_AssetDependencyCount.Remove(Target);
                    m_ResourceLoader.m_AssetToResourceMap.Remove(Target);
                    m_ResourceHelper.Release(Target);
                }
            }
        }
    }
}

View on GitHub (pinned to d0c010b051)