Interactive 2D wave optics simulator. Turn any image into a refractive scene, add sources, watch waves refract, diffract and interfere. Probes, intensity maps, video export.
C#
A malformed project, colour scheme or settings file is quoted in the log under its error
Alexander Graef901128410ae5
diff --git a/CLAUDE.md b/CLAUDE.mdindex 3bd7e92..920386b 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -75,7 +75,11 @@ harnesses run.grid): every engine logs its grid, canvas, rim, edges, stride, sub-steps and work groups when built; a GPU device'sfacts (versions, units, clock, memory, limits) once per process; the scratch request names the newest edit with itsvalue (after the debounce, so a typed number shows as typed); every change at Trace as old → new- (`PropertyValueChangedEventArgs` from `SetProperty`, carried by `ProjectChange.Values`, `library_check` proves it).+ (`PropertyValueChangedEventArgs` from `SetProperty`, carried by `ProjectChange.Values`, `library_check` proves it). **A malformed project, colour scheme or settings file is+ quoted in its error's entry** (2026-11-03, the user's rule): the catch logs an `UnreadableFileException` wrapping the error,+ whose `ToString` appends the file's text, the first 64 K characters and the line an XML error names beyond them, so the+ log file and the Messages pane's tooltip carry it while the status bar and the dialog keep the one-line message; the+ settings file needs it most, since the next save writes the defaults over it (moving it aside is still open).- **Do not resurrect**: a probe signal lane, timeline tracks, zoom and pan of the axis, thumbnails, a run progressbar, the scratch budget and its "not computed" note, a GPU JPEG front end, a Direct3D display path, a bentrotation lever. **Do not change**: the readout showing both frame and step (undecided).diff --git a/WaveDudeNext.WPF/Controls/ColorSchemePicker.cs b/WaveDudeNext.WPF/Controls/ColorSchemePicker.csindex ad369a0..c2f2d41 100644--- a/WaveDudeNext.WPF/Controls/ColorSchemePicker.cs+++ b/WaveDudeNext.WPF/Controls/ColorSchemePicker.cs@@ -279,7 +279,8 @@ public sealed class ColorSchemePicker : ComboBox}catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or InvalidOperationException or FormatException or System.Text.Json.JsonException){- Logger.Error(ex, "The colour scheme could not be loaded: {Message}", ex.Message);+ // the file's text goes into the log under the error (2026-11-03, the user's rule)+ Logger.Error(new UnreadableFileException(dialog.FileName, ex), "The colour scheme could not be loaded: {Message}", ex.Message);}}diff --git a/WaveDudeNext.WPF/MainWindow.xaml.cs b/WaveDudeNext.WPF/MainWindow.xaml.csindex 1e70cf5..7432c99 100644--- a/WaveDudeNext.WPF/MainWindow.xaml.cs+++ b/WaveDudeNext.WPF/MainWindow.xaml.cs@@ -242,7 +242,8 @@ public partial class MainWindow : Window}catch (Exception ex){- Logger.Error(ex, "Error while opening '{Path}'", fileName);+ // the file's text goes into the log under the error (2026-11-03, the user's rule); the dialog shows the error alone+ Logger.Error(new UnreadableFileException(fileName, ex), "Error while opening '{Path}'", fileName);ShowError(string.Format((string)FindResource("OpenError"), fileName), ex);}}@@ -304,7 +305,8 @@ public partial class MainWindow : Window}catch (Exception ex){- Logger.Error(ex, "Error while opening '{Path}'", fileName);+ // the file's text goes into the log under the error (2026-11-03, the user's rule); the dialog shows the error alone+ Logger.Error(new UnreadableFileException(fileName, ex), "Error while opening '{Path}'", fileName);ShowError(string.Format((string)FindResource("OpenError"), fileName), ex);}}diff --git a/WaveDudeNext.WPF/Rendering/ColorSchemeCatalog.cs b/WaveDudeNext.WPF/Rendering/ColorSchemeCatalog.csindex 0c86390..d3f5aaf 100644--- a/WaveDudeNext.WPF/Rendering/ColorSchemeCatalog.cs+++ b/WaveDudeNext.WPF/Rendering/ColorSchemeCatalog.cs@@ -49,7 +49,8 @@ public sealed class ColorSchemeCatalogpublic void Load(){var errors = new List<string>();- List<ColorScheme> user = ColorSchemeStore.LoadFolder(ColorSchemeStore.UserFolder, errors);+ // the store logs each unreadable user file itself, with the file's text under the error (2026-11-03)+ List<ColorScheme> user = ColorSchemeStore.LoadFolder(ColorSchemeStore.UserFolder, null);List<ColorScheme> builtIn = ColorSchemeStore.LoadBuiltIn(errors);_schemes = [.. user, .. builtIn];foreach (string error in errors)diff --git a/WaveDudeNext.WPF/Settings.cs b/WaveDudeNext.WPF/Settings.csindex 936aac7..68f1dea 100644--- a/WaveDudeNext.WPF/Settings.cs+++ b/WaveDudeNext.WPF/Settings.cs@@ -25,6 +25,7 @@ using System.Xml;using System.Xml.Serialization;using NLog;using WaveDudeNext.Engine;+using WaveDudeNext.Model;using WaveDudeNext.Runs;using WaveDudeNext.WPF.Docking;using WaveDudeNext.WPF.Theming;@@ -347,7 +348,8 @@ public sealed class Settings : INotifyPropertyChanged}catch (Exception ex) when (ex is InvalidOperationException or XmlException or IOException or UnauthorizedAccessException){- Logger.Error(ex, "The settings file '{Path}' is unreadable, using the defaults", FilePath);+ // the file's text goes into the log under the error (2026-11-03, the user's rule): the next save overwrites the file+ Logger.Error(new UnreadableFileException(FilePath, ex), "The settings file '{Path}' is unreadable, using the defaults", FilePath);}return new Settings();}diff --git a/WaveDudeNext/Model/UnreadableFileException.cs b/WaveDudeNext/Model/UnreadableFileException.csnew file mode 100644index 0000000..83052de--- /dev/null+++ b/WaveDudeNext/Model/UnreadableFileException.cs@@ -0,0 +1,127 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 Alexander Graef <[email protected]>+//+// This file is part of WaveDude Next, a 2D wave simulator.+//+// Based on the work of+// Jeroen Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026+// <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>+// 0x23 (Diffraction Limited), author of WaveSimulator2D+// <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>+//+// WaveDude Next is free software: you can redistribute it and/or modify it under+// the terms of the GNU General Public License as published by the Free Software+// Foundation, either version 3 of the License, or (at your option) any later+// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or+// <https://www.gnu.org/licenses/>.+++using System.Text;+using System.Xml;++namespace WaveDudeNext.Model;++/// <summary>+/// The exception a log entry carries for a file the application could not read (2026-11-03, the user's rule: a malformed+/// project, colour scheme or settings file goes into the log with its error, so a report can be diagnosed from the log+/// alone; the settings file in particular is overwritten by the defaults moments later). Wraps the error with the file's+/// text, which <see cref="ToString"/>, what the log's layouts and the Messages pane print, appends under the stack: the+/// first <see cref="MaxChars"/> characters, and the line an XML error names with its neighbours when that lies beyond+/// them. Thread-free.+/// </summary>+public sealed class UnreadableFileException : Exception+{+ /// <summary>+ /// Characters quoted from the file's start: a settings or scheme file is a few thousand, a project file without an+ /// image tens of thousands; a project with an embedded image is cut here, its head and the error's line being what matters.+ /// </summary>+ public const int MaxChars = 64 * 1024;++ /// <summary>Characters quoted each side of the position on a line the error names.</summary>+ private const int LineChars = 500;++ /// <summary>Wraps <paramref name="inner"/>, the error reading the file at <paramref name="path"/>, with the file's text.</summary>+ public UnreadableFileException(string path, Exception inner)+ : base($"The file '{path}' could not be read; its text is quoted under the error", inner)+ {+ Path = path;+ Text = Excerpt(path, inner);+ }++ /// <summary>The file's full path.</summary>+ public string Path { get; }++ /// <summary>The file's text as quoted: the first <see cref="MaxChars"/> characters, a note of what is cut, and an XML error's line when it lies beyond; or why the file could not be read at all.</summary>+ public string Text { get; }++ /// <summary>The error with its causes and stack, then the file's text under a rule naming the file.</summary>+ public override string ToString() => base.ToString() + Environment.NewLine + "--- the text of '" + Path + "' ---" + Environment.NewLine + Text;++ /// <summary>+ /// The quotation <see cref="Text"/> holds for a file at <paramref name="path"/> whose reading failed with+ /// <paramref name="error"/>: the head, cut at <see cref="MaxChars"/> with a note of the rest, and when an+ /// <see cref="XmlException"/> among the error's causes names a line beyond the head, that line cut to+ /// <see cref="LineChars"/> each side of its position. Invalid UTF-8 shows as the replacement character.+ /// </summary>+ public static string Excerpt(string path, Exception? error)+ {+ string text;+ try+ {+ text = File.ReadAllText(path, Encoding.UTF8);+ }+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)+ {+ return "(the file could not be read: " + ex.Message + ")";+ }+ if (text.Length <= MaxChars)+ {+ return text;+ }+ var quoted = new StringBuilder();+ quoted.Append(text, 0, MaxChars).Append(Environment.NewLine).Append("… ").Append(text.Length - MaxChars).Append(" more characters");+ if (XmlErrorOf(error) is { LineNumber: > 0 } xml && LineStart(text, xml.LineNumber) is int start && start >= MaxChars)+ {+ int end = text.IndexOf('\n', start);+ if (end < 0)+ {+ end = text.Length;+ }+ int at = Math.Clamp(start + Math.Max(0, xml.LinePosition - 1), start, end);+ int from = Math.Max(start, at - LineChars);+ int to = Math.Min(end, at + LineChars);+ quoted.Append(Environment.NewLine).Append("--- line ").Append(xml.LineNumber).Append(", position ").Append(xml.LinePosition)+ .Append(from > start || to < end ? " (cut) ---" : " ---").Append(Environment.NewLine).Append(text, from, to - from);+ }+ return quoted.ToString();+ }++ /// <summary>The XML error among <paramref name="error"/> and its causes, or null.</summary>+ private static XmlException? XmlErrorOf(Exception? error)+ {+ for (Exception? e = error; e != null; e = e.InnerException)+ {+ if (e is XmlException xml)+ {+ return xml;+ }+ }+ return null;+ }++ /// <summary>The offset at which the 1-based <paramref name="line"/> starts, or null when the text has fewer lines.</summary>+ private static int? LineStart(string text, int line)+ {+ int start = 0;+ for (int i = 1; i < line; i++)+ {+ start = text.IndexOf('\n', start);+ if (start < 0)+ {+ return null;+ }+ start++;+ }+ return start;+ }+}diff --git a/WaveDudeNext/Rendering/ColorSchemeStore.cs b/WaveDudeNext/Rendering/ColorSchemeStore.csindex d492597..1f92929 100644--- a/WaveDudeNext/Rendering/ColorSchemeStore.cs+++ b/WaveDudeNext/Rendering/ColorSchemeStore.cs@@ -21,6 +21,8 @@ using System.Text;using System.Text.Json;using System.Xml;using System.Xml.Serialization;+using NLog;+using WaveDudeNext.Model;namespace WaveDudeNext.Rendering;@@ -48,6 +50,8 @@ public static class ColorSchemeStore/// <summary>Extension of a standalone XML scheme file.</summary>public const string XmlExtension = ".wdscheme";+ private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();+/// <summary>Prefix of the embedded scheme resources (see the csproj's <c>LogicalName</c>).</summary>private const string ResourcePrefix = "ColorSchemes/";@@ -250,6 +254,8 @@ public static class ColorSchemeStore}catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or JsonException or InvalidOperationException or FormatException){+ // the file's text goes into the log under the error (2026-11-03, the user's rule); the caller's list gets the line+ Logger.Warn(new UnreadableFileException(file, ex), "Colour scheme file '{File}' not loaded: {Message}", file, ex.Message);errors?.Add(Path.GetFileName(file) + ": " + ex.Message);}}diff --git a/_tools/library_check/Program.cs b/_tools/library_check/Program.csindex 67f2d4d..eb12f6b 100644--- a/_tools/library_check/Program.cs+++ b/_tools/library_check/Program.cs@@ -272,6 +272,7 @@ internal static class ProgramCheckHistory();CheckClipboard();CheckProjectSchema();+ CheckUnreadableFile();CheckOpenEdges(W, H);CheckWorkGroups();CheckFrameStore(scene);@@ -1763,6 +1764,59 @@ internal static class Program/// the CPU captures of every shape equal to it and the GPU's within the card's arithmetic, a store of index/// bytes, the export's refusal of it, a spec with a quality, and a headless run plus a scratch frame in that shape./// </summary>+ /// <summary>+ /// The exception the log carries for an unreadable file (2026-11-03): its text quotes the file under the error, the+ /// whole of a small file, the first 64 K characters of a large one and then the line an XML error names, and says why+ /// when the file itself cannot be read.+ /// </summary>+ private static void CheckUnreadableFile()+ {+ Console.WriteLine("--- unreadable file: the log's quotation");+ string folder = Path.Combine(Path.GetTempPath(), "library_check-unreadable-" + Guid.NewGuid().ToString("N"));+ Directory.CreateDirectory(folder);+ try+ {+ // a duplicate attribute: the reader's error, with a line and a position+ string small = Path.Combine(folder, "small.wdproj");+ File.WriteAllText(small, "<?xml version=\"1.0\"?>\n<Project Version=\"3\" Version=\"3\" />\n");+ Exception? error = null;+ try+ {+ Project.Load(small);+ }+ catch (Exception ex)+ {+ error = ex;+ }+ UnreadableFileException? wrapped = error == null ? null : new UnreadableFileException(small, error);+ string text = wrapped?.ToString() ?? "";+ Check(wrapped != null && text.Contains("duplicate attribute", StringComparison.Ordinal) && text.Contains("--- the text of '", StringComparison.Ordinal) && wrapped.Text == File.ReadAllText(small),+ "a small malformed project: the error names the duplicate attribute, the quotation is the whole file");+ // a large file, the error on a line beyond the quoted head: a comment of 100,000 characters, then the duplicate+ string large = Path.Combine(folder, "large.wdproj");+ File.WriteAllText(large, "<?xml version=\"1.0\"?>\n<!-- " + new string('x', 100_000) + " -->\n<Project Version=\"3\" Version=\"3\" />\n");+ error = null;+ try+ {+ Project.Load(large);+ }+ catch (Exception ex)+ {+ error = ex;+ }+ wrapped = error == null ? null : new UnreadableFileException(large, error);+ Check(wrapped != null && wrapped.Text.Length < 70_000 && wrapped.Text.Contains(" more characters", StringComparison.Ordinal)+ && wrapped.Text.Contains("--- line 3, position", StringComparison.Ordinal) && wrapped.Text.Contains("<Project Version=\"3\" Version=\"3\" />", StringComparison.Ordinal),+ "a large malformed project: the first 64 K characters, then the line the XML error names");+ Check(UnreadableFileException.Excerpt(Path.Combine(folder, "missing.wdscheme"), null).StartsWith("(the file could not be read:", StringComparison.Ordinal),+ "a missing file: the quotation says why");+ }+ finally+ {+ Directory.Delete(folder, true);+ }+ }+/// <summary>/// A run's store bytes at another preview quality (the memory warning's arithmetic, 2026-11-03): ⌈frames / frame/// divisor⌉ frames of the canvas at the resolution divisor in the sample format, against the sizes written out, and a