Skip to content

Commit

Permalink
Handle errors during shader decompilation
Browse files Browse the repository at this point in the history
  • Loading branch information
ds5678 committed Feb 5, 2024
1 parent c93934e commit 1114a67
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using AssetRipper.Export.Modules.Shaders.UltraShaderConverter.UShader.DirectX;
using AssetRipper.Export.Modules.Shaders.UltraShaderConverter.USIL;
using AssetRipper.Export.UnityProjects.Configuration;
using AssetRipper.Import.Logging;
using AssetRipper.IO.Files;
using AssetRipper.SourceGenerated.Classes.ClassID_48;
using AssetRipper.SourceGenerated.Extensions;
Expand All @@ -34,8 +35,18 @@ public sealed class USCShaderExporter : ShaderExporterBase
public override bool Export(IExportContainer container, IUnityObjectBase asset, string path)
{
using Stream fileStream = File.Create(path);
ExportBinary((IShader)asset, fileStream, ShaderExporterInstantiator);
return true;
try
{
ExportBinary((IShader)asset, fileStream, ShaderExporterInstantiator);
return true;
}
catch (Exception ex)
{
Logger.Error(ex);
fileStream.Position = 0;
DummyShaderTextExporter.ExportShader((IShader)asset, new InvariantStreamWriter(fileStream));
return false;
}
}

private static ShaderTextExporter ShaderExporterInstantiator(GPUPlatform graphicApi)
Expand Down Expand Up @@ -80,7 +91,7 @@ private static void ExportBinary(IShader shader, Stream stream, Func<GPUPlatform
{
using ShaderWriter writer = new ShaderWriter(stream, shader, exporterInstantiator);
writer.WriteQuotesAroundProgram = false;
string header = shader.Script?.String ?? "<unnamed>";
string header = shader.Script.String;
if (writer.Blobs.Length == 0)
{
writer.Write(header);
Expand All @@ -93,7 +104,7 @@ private static void ExportBinary(IShader shader, Stream stream, Func<GPUPlatform
else
{
using BinaryWriter writer = new BinaryWriter(stream);
writer.Write(shader.Script?.String ?? "<unnamed>");
writer.Write(shader.Script.String);
}
}

Expand Down

0 comments on commit 1114a67

Please sign in to comment.