Skip to content

Commit

Permalink
add flag to stop NaN logging
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrit committed Apr 3, 2024
1 parent d044c6f commit c6888c1
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions SeeSharp/Images/FrameBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public class FrameBuffer : IDisposable {
/// </summary>
public readonly Dictionary<string, dynamic> MetaData = new();

/// <summary>
/// If set to true, NaN and Inf values will not be written to the frame buffer, and the offending code's
/// stack trace, iteration number, and pixel position will not be logged.
/// </summary>
public bool IgnoreNanAndInf = false;

readonly Flags flags;
TevIpc tevIpc;
readonly string filename;
Expand Down Expand Up @@ -140,12 +146,12 @@ public FrameBuffer(int width, int height, string filename, Flags flags = Flags.N
/// <param name="row">Vertical pixel coordinate, [0, Height), top to bottom</param>
/// <param name="value">Color to add to the current value</param>
public virtual void Splat(int col, int row, RgbColor value) {
Image.AtomicAdd(col, row, value / CurIteration);
PixelVariance?.Splat(col, row, value);

// Catch invalid values in long running Release mode renderings.
// Ideally can be reproduced with a single sample from a correctly seeded RNG.
if (!float.IsFinite(value.Average)) {
if (IgnoreNanAndInf)
return;

// Catch invalid values in long running Release mode renderings.
// Ideally can be reproduced with a single sample from a correctly seeded RNG.
lock (NaNWarnings) {
if (NaNWarnings.Count < 4)
Logger.Warning($"NaN or Inf written to frame buffer. Iteration: {CurIteration}, Pixel: ({col},{row}). " +
Expand All @@ -156,6 +162,9 @@ public virtual void Splat(int col, int row, RgbColor value) {
NaNWarnings.Add(new(new Pixel(col, row), CurIteration, Environment.StackTrace));
}
}

Image.AtomicAdd(col, row, value / CurIteration);
PixelVariance?.Splat(col, row, value);
}

/// <summary>
Expand Down

0 comments on commit c6888c1

Please sign in to comment.