InvalidOperationException: Trying to access unloaded resource (Shader Graphs/MaskingShader)

I’m porting a project over, and am getting the error below on every update.

I see this shader is in the /Packages/com.unity.polyspatial/Resources/Shaders/ directory - any idea what’s causing this?

Tried a Reimport All - no luck.
Unity 2022.3.18f1
PolySpatial 1.0.3

InvalidOperationException: Trying to access unloaded resource! [5c7a0d7c-c494-47d2-9d7a-a29daaa00d8c (has 1 polyspatial refs, is not unity referenced): resource alive: False iid=-617044 name=Shader Graphs/MaskingShader type=Material
Unity.PolySpatial.Internals.AssetRepresentation.get_Resource () (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/AssetManagement/AssetRepresentation.cs:39)
Unity.PolySpatial.Internals.LocalAssetManager.GetRegisteredResource (Unity.PolySpatial.Internals.PolySpatialAssetID assetID) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/AssetManagement/LocalAssetManager.cs:559)
Unity.PolySpatial.Internals.LocalAssetManager.GetRegisteredResource[T] (Unity.PolySpatial.Internals.PolySpatialAssetID assetID) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/AssetManagement/LocalAssetManager.cs:569)
Unity.PolySpatial.Internals.SpriteRendererTracker.CreateUpdateSpriteRendererMaterialIfNeeded (Unity.PolySpatial.Internals.PolySpatialSpriteRendererTrackingData* destination) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/Trackers/SpriteRendererTracker.cs:108)
Unity.PolySpatial.Internals.SpriteRendererTracker.TransferObjectData (UnityEngine.SpriteRenderer source, Unity.PolySpatial.Internals.TrackingData`1[Unity.PolySpatial.Internals.PolySpatialSpriteRendererTrackingData]* trackingData, Unity.PolySpatial.Internals.IChangeListWritable`1[TEngineData] engineData) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/Trackers/SpriteRendererTracker.cs:318)
Unity.PolySpatial.Internals.UnityObjectTracker`3[TObject,TEngineData,TTrackingData].TransferObjectData (TObject source, TTrackingData* trackingData) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/Trackers/UnityObjectTracker.cs:174)
Unity.PolySpatial.Internals.UnityObjectTracker`3[TObject,TEngineData,TTrackingData].TransferObjectAndUpdateTrackingData (UnityEngine.Object o, TTrackingData* data) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/Trackers/UnityObjectTracker.cs:474)
Unity.PolySpatial.Internals.SpriteRendererTracker.TrackNewAndModifiedObjects (UnityEngine.Object[] changedObjects) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/Trackers/SpriteRendererTracker.cs:606)
Unity.PolySpatial.Internals.UnityObjectTracker`3[TObject,TEngineData,TTrackingData].FetchTypeCallback (Unity.PolySpatial.Internals.ObjectDispatcherProxy+TypeDispatchData data) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/Trackers/UnityObjectTracker.cs:269)
Unity.PolySpatial.Internals.ObjectDispatcherProxy.<.ctor>b__12_0 (UnityEngine.TypeDispatchData real) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/InternalBridge/BridgeUtils.cs:118)
UnityEngine.ObjectDispatcher+<>c.<.cctor>b__54_0 (UnityEngine.Object[] changed, System.IntPtr changedID, System.IntPtr destroyedID, System.Int32 changedCount, System.Int32 destroyedCount, System.Action`1[T] callback) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Misc/ObjectDispatcher.bindings.cs:162)
UnityEngine.ObjectDispatcher:DispatchTypeChangesAndClear(Type, Action`1, Boolean, Boolean)
Unity.PolySpatial.Internals.ObjectDispatcherProxy:DispatchTypeChangesAndClear(Type, Action`1) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/InternalBridge/BridgeUtils.cs:180)
Unity.PolySpatial.Internals.UnityObjectTrackerBase:FetchDirtyOneTypeIntoLists(Type) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/Trackers/UnityObjectTracker.cs:30)
Unity.PolySpatial.Internals.UnityObjectTracker`3:TrackObjectChanges(LayerMask) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/Trackers/UnityObjectTracker.cs:249)
Unity.PolySpatial.Internals.PolySpatialUnityTracker:TrackObjectChanges(LayerMask) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/Trackers/PolySpatialUnityTracker.cs:190)
Unity.PolySpatial.Internals.PolySpatialUnitySimulation:UpdateInternal() (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/Trackers/PolySpatialUnitySimulation.cs:155)
Unity.PolySpatial.Internals.PolySpatialUnitySimulation:Update() (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/Trackers/PolySpatialUnitySimulation.cs:136)
Unity.PolySpatial.Internals.PolySpatialCore:PolySpatialAfterLateUpdate() (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/PolySpatialCore.cs:696)
UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at /Users/bokken/build/output/unity/unity/Editor/Mono/EditorApplication.cs:474)```

Possibly related, I’m also getting this repeated in the log in the simulator. The number in the first line changes.

Couldn't find object for -34432.
Unity.PolySpatial.Internals.PolySpatialUnitySimulation:SetDebugInfo(PolySpatialInstanceID)
Unity.PolySpatial.Internals.PolySpatialUnitySimulation:OnGameObjectsChanged(ChangeList`1)
Unity.PolySpatial.Internals.UnityObjectTracker`3:ProcessAllDestroyedObjects()
Unity.PolySpatial.Internals.UnityObjectTracker`3:ProcessDestroyedObjects()
Unity.PolySpatial.Internals.PolySpatialUnityTracker:Process()
Unity.PolySpatial.Internals.PolySpatialUnitySimulation:UpdateInternal()
Unity.PolySpatial.Internals.PolySpatialCore:PolySpatialAfterLateUpdate()

Hello! It looks like the underlying issue is that the custom material we create for the sprite is being garbage-collected inappropriately, perhaps because the sprite is retained when a scene is loaded (or Resources.UnloadUnusedAssets is being called manually). We’re eventually going to be making a change that should fix this incidentally (allowing custom materials/shaders on sprites), but I’ll make a separate task to fix this issue in case that doesn’t go into the next release.

This, on the other hand, just looks like a general error with the Extra Debug Information option. We should be able to fix that relatively easily, but you can ignore the log message for now.

1 Like

is this fixed now?

It should be, as far as I know. If you see it (or any bug), please file a bug report with a repro case and let us know the incident number (IN-#####) so that we can investigate.

i tested the latest version 1.1.4, and got another different but related error when calling unloadunusedresources, which causing UI stop responding.

InvalidOperationException: Unregistering asset 7c3dd692-8f30-491c-acb5-9bc8a523a602, but representation not registered
Unity.PolySpatial.Internals.LocalAssetManager.Unregister (Unity.PolySpatial.Internals.PolySpatialAssetID assetID) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/AssetManagement/LocalAssetManager.cs:480)
Unity.PolySpatial.Internals.MaterialConversionHelpers.UnregisterMaterialTextureAssets (Unity.PolySpatial.Internals.PolySpatialMaterialData& material) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/Rendering/MaterialConversionHelpers.cs:153)
Unity.PolySpatial.Internals.LocalAssetManager.DestroyMaterialData (Unity.PolySpatial.Internals.PolySpatialMaterialData oldData) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/AssetManagement/LocalAssetManager.cs:548)
Unity.PolySpatial.Internals.LocalAssetManager.UpdateOrCreateRegisteredMaterialData (UnityEngine.Material material) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/AssetManagement/LocalAssetManager.cs:282)
Unity.PolySpatial.Internals.LocalAssetManager.ProcessChangedAsset (Unity.PolySpatial.Internals.AssetRepresentation representation) (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/AssetManagement/LocalAssetManager.cs:1117)
Unity.PolySpatial.Internals.LocalAssetManager.ProcessChanges () (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/AssetManagement/LocalAssetManager.cs:834)
Unity.PolySpatial.Internals.PolySpatialUnitySimulation.UpdateInternal () (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/Trackers/PolySpatialUnitySimulation.cs:175)
Unity.PolySpatial.Internals.PolySpatialUnitySimulation.Update () (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/Trackers/PolySpatialUnitySimulation.cs:136)
Unity.PolySpatial.Internals.PolySpatialCore.PolySpatialAfterLateUpdate () (at /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/PolySpatialCore.cs:706)

[Diagnostics] EXCEPTION InvalidOperationException in PolySpatialCore:
  at Unity.PolySpatial.Internals.LocalAssetManager.Unregister (Unity.PolySpatial.Internals.PolySpatialAssetID assetID) [0x0005f] in /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/AssetManagement/LocalAssetManager.cs:480 
  at Unity.PolySpatial.Internals.MaterialConversionHelpers.UnregisterMaterialTextureAssets (Unity.PolySpatial.Internals.PolySpatialMaterialData& material) [0x00016] in /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/Rendering/MaterialConversionHelpers.cs:153 
  at Unity.PolySpatial.Internals.LocalAssetManager.DestroyMaterialData (Unity.PolySpatial.Internals.PolySpatialMaterialData oldData) [0x0004f] in /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/AssetManagement/LocalAssetManager.cs:548 
  at Unity.PolySpatial.Internals.LocalAssetManager.UpdateOrCreateRegisteredMaterialData (UnityEngine.Material material) [0x00034] in /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/AssetManagement/LocalAssetManager.cs:282 
  at Unity.PolySpatial.Internals.LocalAssetManager.ProcessChangedAsset (Unity.PolySpatial.Internals.AssetRepresentation representation) [0x000b0] in /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/AssetManagement/LocalAssetManager.cs:1117 
  at Unity.PolySpatial.Internals.LocalAssetManager.ProcessChanges () [0x00079] in /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/AssetManagement/LocalAssetManager.cs:834 
  at Unity.PolySpatial.Internals.PolySpatialUnitySimulation.UpdateInternal () [0x00094] in /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/Trackers/PolySpatialUnitySimulation.cs:175 
  at Unity.PolySpatial.Internals.PolySpatialUnitySimulation.Update () [0x0000a] in /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/Trackers/PolySpatialUnitySimulation.cs:136 
  at Unity.PolySpatial.Internals.PolySpatialCore.PolySpatialAfterLateUpdate () [0x000ce] in /Users/bokken/build/output/unity/quantum/Packages/com.unity.polyspatial/Runtime/PolySpatialCore.cs:694 

Can you help to resolve this problem?

Thanks,
Bin

It’s not immediately clear what would be causing this, but basically it looks like we’re mistakenly retaining a reference to a material that’s being unloaded. If you could create a repro case as a bug report and let us know the incident number (IN-#####), that would help us track down the issue.