Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug where the render texture cache would yield disposed textures #529

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 12 additions & 21 deletions TestProjects/PerceptionURP/Packages/packages-lock.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"com.unity.burst": {
"version": "1.4.6",
"version": "1.5.6",
"depth": 1,
"source": "registry",
"dependencies": {
Expand All @@ -19,12 +19,12 @@
"url": "https://packages.unity.com"
},
"com.unity.collections": {
"version": "0.9.0-preview.6",
"version": "1.1.0",
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.test-framework.performance": "2.0.8-preview",
"com.unity.burst": "1.3.0-preview.12"
"com.unity.burst": "1.5.4",
"com.unity.test-framework": "1.1.29"
},
"url": "https://packages.unity.com"
},
Expand Down Expand Up @@ -97,12 +97,10 @@
"depth": 0,
"source": "local",
"dependencies": {
"com.unity.burst": "1.4.6",
"com.unity.collections": "0.9.0-preview.6",
"com.unity.burst": "1.5.6",
"com.unity.collections": "1.1.0",
"com.unity.nuget.newtonsoft-json": "1.1.2",
"com.unity.render-pipelines.core": "7.1.6",
"com.unity.simulation.client": "0.0.10-preview.10",
"com.unity.simulation.core": "0.0.10-preview.25"
"com.unity.render-pipelines.core": "7.1.6"
}
},
"com.unity.render-pipelines.core": {
Expand Down Expand Up @@ -153,13 +151,6 @@
},
"url": "https://packages.unity.com"
},
"com.unity.simulation.client": {
"version": "0.0.10-preview.10",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.simulation.core": {
"version": "0.0.10-preview.26",
"depth": 0,
Expand All @@ -186,8 +177,8 @@
"url": "https://packages.unity.com"
},
"com.unity.test-framework": {
"version": "1.1.27",
"depth": 0,
"version": "1.1.29",
"depth": 2,
"source": "registry",
"dependencies": {
"com.unity.ext.nunit": "1.0.6",
Expand All @@ -197,12 +188,12 @@
"url": "https://packages.unity.com"
},
"com.unity.test-framework.performance": {
"version": "2.0.8-preview",
"depth": 2,
"version": "2.8.0-preview",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.test-framework": "1.1.0",
"com.unity.nuget.newtonsoft-json": "2.0.0-preview"
"com.unity.modules.jsonserialize": "1.0.0"
},
"url": "https://packages.unity.com"
},
Expand Down
4 changes: 2 additions & 2 deletions TestProjects/PerceptionURP/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2020.3.19f1
m_EditorVersionWithRevision: 2020.3.19f1 (68f137dc9bbe)
m_EditorVersion: 2020.3.11f1
m_EditorVersionWithRevision: 2020.3.11f1 (99c7afb366b3)
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ EditorUserSettings:
serializedVersion: 4
m_ConfigSettings:
RecentlyUsedScenePath-0:
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2805183df1c43d2bf6e824fdee3531722c0ce6281d
value: 22424703114646680e0b0227036c6f1f05122b2b21382a35633c133af6f9
flags: 0
RecentlyUsedScenePath-1:
value: 22424703114646680e0b0227036c6f1f05122b2b21382a35633c133af6f9
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
flags: 0
RecentlyUsedScenePath-2:
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2805183df1c43d2bf6e824fdee3531722c0ce6281d
flags: 0
vcSharedLogLevel:
value: 0d5e400f0650
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ protected override void OnEndRendering(ScriptableRenderContext scriptableRenderC
/// <inheritdoc/>
protected override void Cleanup()
{

Debug.Log("Cleaning UP");
if (m_TargetTextureOverride != null)
m_TargetTextureOverride.Release();

Expand Down
10 changes: 9 additions & 1 deletion com.unity.perception/Runtime/GroundTruth/RenderTextureReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public static void Capture<T>(ScriptableRenderContext context, RenderTexture sou
else
{
var cpuTexture = GetTextureFromCache(sourceTex.width, sourceTex.height, sourceTex.graphicsFormat);
if (!cpuTexture)
{
Debug.LogWarning("No texture from cache found!");
return;
}
RenderTexture.active = sourceTex;
cpuTexture.ReadPixels(new Rect(0, 0, sourceTex.width, sourceTex.height), 0, 0);
cpuTexture.Apply();
Expand Down Expand Up @@ -73,7 +78,10 @@ static void OnGpuReadback<T>(AsyncGPUReadbackRequest request, int frameCount, Re
static Texture2D GetTextureFromCache(int width, int height, GraphicsFormat graphicsFormat)
{
if (s_CachedCpuTextures.TryGetValue((width, height, graphicsFormat), out var texture))
return texture;
{
if (null != texture) return texture;
Debug.LogWarning("Found disposed or null texture in cache");
}
var newTexture = new Texture2D(width, height, graphicsFormat, TextureCreationFlags.None);
s_CachedCpuTextures[(width, height, graphicsFormat)] = newTexture;
return newTexture;
Expand Down