Skip to content

Commit a902bae

Browse files
committed
Updated project, switched to URP, and added more guards against accidental extreme allocations.
1 parent 43f2e5a commit a902bae

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

ExampleProjectors/Splat.mat

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
%TAG !u! tag:unity3d.com,2011:
33
--- !u!21 &2100000
44
Material:
5-
serializedVersion: 6
5+
serializedVersion: 8
66
m_ObjectHideFlags: 0
77
m_CorrespondingSourceObject: {fileID: 0}
88
m_PrefabInstance: {fileID: 0}
99
m_PrefabAsset: {fileID: 0}
1010
m_Name: Splat
1111
m_Shader: {fileID: 4800000, guid: 01fbbcdc080ae1f408f4d363f8bcc20d, type: 3}
12-
m_ShaderKeywords: _BACKFACECULLING_ON _DISABLE_SSR_TRANSPARENT _NORMALMAP_TANGENT_SPACE
12+
m_ValidKeywords:
13+
- _BACKFACECULLING_ON
14+
m_InvalidKeywords:
15+
- _DISABLE_SSR_TRANSPARENT
16+
- _NORMALMAP_TANGENT_SPACE
1317
m_LightmapFlags: 4
1418
m_EnableInstancingVariants: 0
1519
m_DoubleSidedGI: 0
@@ -125,6 +129,7 @@ Material:
125129
m_Texture: {fileID: 0}
126130
m_Scale: {x: 1, y: 1}
127131
m_Offset: {x: 0, y: 0}
132+
m_Ints: []
128133
m_Floats:
129134
- _AORemapMax: 1
130135
- _AORemapMin: 0
@@ -269,6 +274,8 @@ Material:
269274
- _UVDetailsMappingMask: {r: 1, g: 0, b: 0, a: 0}
270275
- _UVMappingMask: {r: 1, g: 0, b: 0, a: 0}
271276
- _UVMappingMaskEmissive: {r: 1, g: 0, b: 0, a: 0}
277+
- _Vector0: {r: 2, g: -2, b: 1, a: 0}
278+
- _Vector1: {r: -1, g: 1, b: 0, a: 0}
272279
m_BuildTextureStacks: []
273280
--- !u!114 &5448608158274631724
274281
MonoBehaviour:
@@ -283,3 +290,6 @@ MonoBehaviour:
283290
m_Name:
284291
m_EditorClassIdentifier:
285292
version: 11
293+
hdPluginSubTargetMaterialVersions:
294+
m_Keys: []
295+
m_Values:

Scripts/DecalableInfo.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ public void Render(CommandBuffer buffer, Material projector, string textureName)
114114
float maxBounds = Mathf.Max(maxA, bounds.extents.y*bounds.extents.z);
115115
int worldScale = Mathf.RoundToInt(maxBounds*PaintDecal.GetTexelsPerMeter());
116116
int textureScale = Mathf.Clamp(CeilPowerOfTwo(worldScale), 16, 2048);
117-
if (!PaintDecal.TryReserveMemory(dilationEnabled ? 2*textureScale*textureScale*4 : textureScale*textureScale*4)) {
117+
if (float.IsNaN(textureScale) || float.IsInfinity(textureScale)) {
118+
textureScale = 1024;
119+
}
120+
int reserveMemory = dilationEnabled ? 2 * textureScale * textureScale * 4 : textureScale * textureScale * 4;
121+
reserveMemory = Mathf.Clamp(reserveMemory, 0, 2 * 2048 * 2048 * 4);
122+
if (!PaintDecal.TryReserveMemory(reserveMemory)) {
118123
return;
119124
}
120125

0 commit comments

Comments
 (0)