From d5e50ba1e45c6671696cf2c4f8ee68a05606a607 Mon Sep 17 00:00:00 2001
From: Brandon Grimshaw
Date: Wed, 12 Jun 2024 12:38:18 +1000
Subject: [PATCH] Account for empty variant arrays in parser
It's possible for entries in `.shadervariants` assets to have an empty variants array. Eg. `variants: []`.
This causes the parser to go out-of-bounds in the `yaml` list when the final entry has an empty variants array.
When not the final entry, it probably causes the next entry to be parsed incorrectly.
---
ShaderStripperVariantCollection.cs | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/ShaderStripperVariantCollection.cs b/ShaderStripperVariantCollection.cs
index 34b2ccf..10f5595 100644
--- a/ShaderStripperVariantCollection.cs
+++ b/ShaderStripperVariantCollection.cs
@@ -145,6 +145,19 @@ public override void Initialize(){
// Move to variants contents (skip current line, "second:" and "variants:")
i += 3;
+
+ // it's possible for the variants array to be empty (represented by `variants: []`)
+ if (i >= yaml.Count) {
+ // this was the final entry, we've reached EOF
+ break;
+ }
+
+ if (GetYamlIndent(yaml[i]) == indent) {
+ // the variants array was empty and we're now on the `- first:` line of the next entry
+ i -= 1; // decrement here because the loop will increment
+ continue;
+ }
+
indent = GetYamlIndent(yaml[i]);
var sv = new ShaderVariantCollection.ShaderVariant();
for (; i