diff --git a/src/BannedSymbols.BannedApiAnalyzers.txt b/src/BannedSymbols.BannedApiAnalyzers.txt index 3de391805c..2a8d9aca85 100644 --- a/src/BannedSymbols.BannedApiAnalyzers.txt +++ b/src/BannedSymbols.BannedApiAnalyzers.txt @@ -9,4 +9,6 @@ M:System.Convert.ToSingle(System.String);use float.{Try,}Parse M:System.Convert.ToUInt16(System.String);use ushort.{Try,}Parse M:System.Convert.ToUInt32(System.String);use uint.{Try,}Parse M:System.Convert.ToUInt64(System.String);use ulong.{Try,}Parse +M:System.Diagnostics.Debug.Assert(System.Boolean);include a unique message +M:System.Diagnostics.Trace.Assert(System.Boolean);include a unique message M:System.Windows.Forms.Control.Focus;use Activate for Forms, or Select otherwise diff --git a/src/BizHawk.Bizware.Graphics/BitmapBuffer.cs b/src/BizHawk.Bizware.Graphics/BitmapBuffer.cs index 8bcb1ce2fb..0352fb4502 100644 --- a/src/BizHawk.Bizware.Graphics/BitmapBuffer.cs +++ b/src/BizHawk.Bizware.Graphics/BitmapBuffer.cs @@ -65,7 +65,7 @@ namespace BizHawk.Bizware.Graphics public void UnlockBits(BitmapData bmpd) { - Debug.Assert(CurrLock == bmpd); + Debug.Assert(CurrLock == bmpd, "must pass in the same object obtained from " + nameof(LockBits)); if (WrappedBitmap != null) { diff --git a/src/BizHawk.Client.Common/DisplayManager/FilterManager.cs b/src/BizHawk.Client.Common/DisplayManager/FilterManager.cs index e0ab617a9f..f1e533f095 100644 --- a/src/BizHawk.Client.Common/DisplayManager/FilterManager.cs +++ b/src/BizHawk.Client.Common/DisplayManager/FilterManager.cs @@ -285,7 +285,7 @@ namespace BizHawk.Client.Common.FilterManager if (ps.Type == ProgramStepType.NewTarget) { var size = (Size)ps.Args; - Debug.Assert(size == outsize); + Debug.Assert(size == outsize, "size of last " + nameof(ProgramStepType.NewTarget) + " was set wrong"); Program[i] = new(ProgramStepType.FinalTarget, size, ps.Comment); break; } diff --git a/src/BizHawk.Client.Common/fwmanager/FirmwareManager.cs b/src/BizHawk.Client.Common/fwmanager/FirmwareManager.cs index ca9a229f60..ebbb69bf6b 100644 --- a/src/BizHawk.Client.Common/fwmanager/FirmwareManager.cs +++ b/src/BizHawk.Client.Common/fwmanager/FirmwareManager.cs @@ -1,7 +1,6 @@ #nullable enable using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; @@ -27,7 +26,7 @@ namespace BizHawk.Client.Common { var @base = File.ReadAllBytes(baseFilename); var (patched, actualHash) = PerformPatchInMemory(@base, in patchOption); - Trace.Assert(actualHash == patchOption.TargetHash); + if (actualHash != patchOption.TargetHash) throw new InvalidOperationException("patch produced incorrect output"); var patchedParentDir = Path.Combine(pathEntries[PathEntryCollection.GLOBAL, "Temp Files"].Path, "AutopatchedFirmware"); Directory.CreateDirectory(patchedParentDir); var ff = FirmwareDatabase.FirmwareFilesByHash[patchOption.TargetHash]; diff --git a/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs b/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs index e0d34f5049..ea1a2aa48b 100644 --- a/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs +++ b/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs @@ -821,13 +821,13 @@ namespace BizHawk.Client.EmuHawk private bool IsVisible(int index) { - Debug.Assert(FirstVisibleRow < LastFullyVisibleRow); + Debug.Assert(FirstVisibleRow < LastFullyVisibleRow, "rows out of order?"); return FirstVisibleRow <= index && index <= LastFullyVisibleRow; } public bool IsPartiallyVisible(int index) { - Debug.Assert(FirstVisibleRow < LastVisibleRow); + Debug.Assert(FirstVisibleRow < LastVisibleRow, "rows out of order?"); return FirstVisibleRow <= index && index <= LastVisibleRow; } diff --git a/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs b/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs index 69eeea9b3a..7828de339b 100644 --- a/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs +++ b/src/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs @@ -110,7 +110,7 @@ namespace BizHawk.Client.EmuHawk return; } - Debug.Assert(inFinalTarget); + Debug.Assert(inFinalTarget, "not in final target?"); // present and conclude drawing _graphicsControl.SwapBuffers(); diff --git a/src/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs b/src/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs index 71858075f2..89cf744d0b 100644 --- a/src/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs +++ b/src/BizHawk.Client.EmuHawk/tools/SNES/SNESGraphicsDebugger.cs @@ -24,6 +24,7 @@ using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; using System.Windows.Forms; @@ -459,7 +460,7 @@ namespace BizHawk.Client.EmuHawk dims.Height = dims.Width = Math.Max(dims.Width, dims.Height); allocate(dims.Width, dims.Height); numPixels = dims.Width * dims.Height; - System.Diagnostics.Debug.Assert(stride / 4 == dims.Width); + Debug.Assert(dims.Width * 4 == stride, "line is not `width` pixels at 32bpp?"); map = gd.FetchTilemap(bg.ScreenAddr, bg.ScreenSize); int paletteStart = 0; diff --git a/src/BizHawk.Common/BPSPatcher.cs b/src/BizHawk.Common/BPSPatcher.cs index 5f2c9aa13d..68b0c50f8f 100644 --- a/src/BizHawk.Common/BPSPatcher.cs +++ b/src/BizHawk.Common/BPSPatcher.cs @@ -148,7 +148,7 @@ namespace BizHawk.Common if (size is 0) { var rleSize = (data[i++] * 0x100) | data[i++]; - Debug.Assert(rleSize is not 0); + Debug.Assert(rleSize is not 0, "may not run-length-encode nothing"); records.Add((i, targetOffset, rleSize, true)); i++; } diff --git a/src/BizHawk.Common/Bit.cs b/src/BizHawk.Common/Bit.cs index fb1aff55ef..51da3672cc 100644 --- a/src/BizHawk.Common/Bit.cs +++ b/src/BizHawk.Common/Bit.cs @@ -14,19 +14,19 @@ namespace BizHawk.Common public static implicit operator Bit(int rhs) { - Debug.Assert((rhs & ~1) == 0); + Debug.Assert((rhs & ~1) is 0, "higher bits can't be used"); return new Bit((uint)rhs); } public static implicit operator Bit(uint rhs) { - Debug.Assert((rhs & ~1) == 0); + Debug.Assert((rhs & ~1) is 0, "higher bits can't be used"); return new Bit(rhs); } public static implicit operator Bit(byte rhs) { - Debug.Assert((rhs & ~1) == 0); + Debug.Assert((rhs & ~1) is 0, "higher bits can't be used"); return new Bit(rhs); } diff --git a/src/BizHawk.Common/EndiannessUtils.cs b/src/BizHawk.Common/EndiannessUtils.cs index e0322bdec0..af30ffc899 100644 --- a/src/BizHawk.Common/EndiannessUtils.cs +++ b/src/BizHawk.Common/EndiannessUtils.cs @@ -9,7 +9,7 @@ namespace BizHawk.Common { #if true //TODO benchmark (both methods work correctly); also there is another method involving shifting the (output copy of the) array over by 1 byte then manually writing every second byte var l = a.Length; - Debug.Assert(l % 2 == 0); + Debug.Assert(l % 2 is 0, "octets must be in pairs"); fixed (byte* p = &a[0]) for (var i = 0; i < l; i += 2) { var b = p[i]; @@ -17,7 +17,7 @@ namespace BizHawk.Common p[i + 1] = b; } #else - Debug.Assert(a.Length % 2 == 0); + Debug.Assert(a.Length % 2 is 0, "octets must be in pairs"); var shorts = MemoryMarshal.Cast(a); for (var i = 0; i < shorts.Length; i++) shorts[i] = BinaryPrimitives.ReverseEndianness(shorts[i]); #endif @@ -28,7 +28,7 @@ namespace BizHawk.Common { #if true //TODO benchmark (both methods work correctly) var l = a.Length; - Debug.Assert(l % 4 == 0); + Debug.Assert(l % 4 is 0, "octets must be in groups of 4"); fixed (byte* p = &a[0]) for (var i = 0; i < l; i += 4) { var b = p[i]; @@ -39,7 +39,7 @@ namespace BizHawk.Common p[i + 2] = b; } #else - Debug.Assert(a.Length % 4 == 0); + Debug.Assert(a.Length % 4 is 0, "octets must be in groups of 4"); var ints = MemoryMarshal.Cast(a); for (var i = 0; i < ints.Length; i++) ints[i] = BinaryPrimitives.ReverseEndianness(ints[i]); #endif diff --git a/src/BizHawk.Common/Extensions/CollectionExtensions.cs b/src/BizHawk.Common/Extensions/CollectionExtensions.cs index 8159f09ab7..288279fcb0 100644 --- a/src/BizHawk.Common/Extensions/CollectionExtensions.cs +++ b/src/BizHawk.Common/Extensions/CollectionExtensions.cs @@ -133,7 +133,7 @@ namespace BizHawk.Common.CollectionExtensions if (a.Length is 0) return b; var combined = new T[a.Length + b.Length]; var returned = ((ReadOnlySpan) a).ConcatArray(b, combined); - Debug.Assert(returned == combined); + Debug.Assert(returned == combined, "expecting return value to cover all of combined since the whole thing was written to"); return combined; } diff --git a/src/BizHawk.Common/Util.cs b/src/BizHawk.Common/Util.cs index 7b37bf9427..7a74dfd646 100644 --- a/src/BizHawk.Common/Util.cs +++ b/src/BizHawk.Common/Util.cs @@ -54,7 +54,7 @@ namespace BizHawk.Common if (tmp[0] != 0x1F || tmp[1] != 0x8B) throw new InvalidOperationException("GZIP header not present"); src.Seek(-4, SeekOrigin.End); var bytesRead = src.Read(tmp, offset: 0, count: tmp.Length); - Debug.Assert(bytesRead == tmp.Length); + Debug.Assert(bytesRead == tmp.Length, "failed to read tail"); src.Seek(0, SeekOrigin.Begin); using var gs = new GZipStream(src, CompressionMode.Decompress, true); var data = new byte[BitConverter.ToInt32(tmp, 0)]; diff --git a/src/BizHawk.Common/checksums/MD5Checksum.cs b/src/BizHawk.Common/checksums/MD5Checksum.cs index ae22a96cf4..1fbca25002 100644 --- a/src/BizHawk.Common/checksums/MD5Checksum.cs +++ b/src/BizHawk.Common/checksums/MD5Checksum.cs @@ -31,7 +31,7 @@ namespace BizHawk.Common if (_md5Impl == null) { _md5Impl = MD5.Create(); - Debug.Assert(_md5Impl.CanReuseTransform && _md5Impl.HashSize is EXPECTED_LENGTH); + Debug.Assert(_md5Impl.CanReuseTransform && _md5Impl.HashSize is EXPECTED_LENGTH, "nonstandard implementation?"); } return _md5Impl; } diff --git a/src/BizHawk.Common/checksums/SHA1Checksum.cs b/src/BizHawk.Common/checksums/SHA1Checksum.cs index 0abe8f4b1a..74c1fc5c88 100644 --- a/src/BizHawk.Common/checksums/SHA1Checksum.cs +++ b/src/BizHawk.Common/checksums/SHA1Checksum.cs @@ -49,7 +49,7 @@ namespace BizHawk.Common if (_sha1Impl == null) { _sha1Impl = SHA1.Create(); - Debug.Assert(_sha1Impl.CanReuseTransform && _sha1Impl.HashSize is EXPECTED_LENGTH); + Debug.Assert(_sha1Impl.CanReuseTransform && _sha1Impl.HashSize is EXPECTED_LENGTH, "nonstandard implementation?"); } return _sha1Impl; } diff --git a/src/BizHawk.Common/checksums/SHA256Checksum.cs b/src/BizHawk.Common/checksums/SHA256Checksum.cs index c8e5d58768..b999e02c48 100644 --- a/src/BizHawk.Common/checksums/SHA256Checksum.cs +++ b/src/BizHawk.Common/checksums/SHA256Checksum.cs @@ -31,7 +31,7 @@ namespace BizHawk.Common if (_sha256Impl == null) { _sha256Impl = SHA256.Create(); - Debug.Assert(_sha256Impl.CanReuseTransform && _sha256Impl.HashSize is EXPECTED_LENGTH); + Debug.Assert(_sha256Impl.CanReuseTransform && _sha256Impl.HashSize is EXPECTED_LENGTH, "nonstandard implementation?"); } return _sha256Impl; } diff --git a/src/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs b/src/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs index 37bca8e70c..d9af496981 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/MemoryCallbackSystem.cs @@ -276,7 +276,7 @@ namespace BizHawk.Emulation.Common private void RemoveAtInternal(int index) { - Debug.Assert(_modifyInProgress); + Debug.Assert(_modifyInProgress, "unexpected collection mutation state"); CopyIfRequired(); var removedItem = _items[index]; @@ -357,7 +357,7 @@ namespace BizHawk.Emulation.Common private void EndCopyOnWrite() { _copyOnWriteRequired--; - Debug.Assert(_copyOnWriteRequired >= 0); + Debug.Assert(_copyOnWriteRequired >= 0, "unexpected CoW state"); } public Enumerator GetEnumerator() diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IEmulator.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IEmulator.cs index f6b1ed3348..139e7b279d 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IEmulator.cs @@ -49,7 +49,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy { // target number of samples to emit: length of 1 frame minus whatever overflow samplesEmitted = TICKSINFRAME - frameOverflow; - Debug.Assert(samplesEmitted * 2 <= _soundbuff.Length); + Debug.Assert(samplesEmitted * 2 <= _soundbuff.Length, "buffer capacity exceeded"); if (LibGambatte.gambatte_runfor(GambatteState, FrameBuffer, 160, _soundbuff, ref samplesEmitted) > 0) { Array.Copy(FrameBuffer, VideoBuffer, FrameBuffer.Length); @@ -90,7 +90,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy inputFrameLengthInt = TICKSINFRAME; } samplesEmitted = inputFrameLengthInt - frameOverflow; - Debug.Assert(samplesEmitted * 2 <= _soundbuff.Length); + Debug.Assert(samplesEmitted * 2 <= _soundbuff.Length, "buffer capacity exceeded"); if (LibGambatte.gambatte_runfor(GambatteState, FrameBuffer, 160, _soundbuff, ref samplesEmitted) > 0) { Array.Copy(FrameBuffer, VideoBuffer, FrameBuffer.Length); diff --git a/src/BizHawk.Emulation.DiscSystem/DiscFormats/Blobs/Blob_ECM.cs b/src/BizHawk.Emulation.DiscSystem/DiscFormats/Blobs/Blob_ECM.cs index e56b4bfa06..f8cf244839 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscFormats/Blobs/Blob_ECM.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscFormats/Blobs/Blob_ECM.cs @@ -5,6 +5,7 @@ using System.IO; using System.Collections.Generic; +using System.Diagnostics; using BizHawk.Common.CollectionExtensions; using BizHawk.Common.NumberExtensions; @@ -171,7 +172,7 @@ namespace BizHawk.Emulation.DiscSystem //Console.WriteLine("binary searched"); //use this to check for mistaken LastReadIndex logic resulting in binary searches during sequential access var listIndex = Index.LowerBoundBinarySearch(idx => idx.LogicalOffset, offset); - System.Diagnostics.Debug.Assert(listIndex < Index.Count); + Debug.Assert(listIndex < Index.Count, "insertion point may not be after end"); //Console.WriteLine("byte_pos {0:X8} using index #{1} at offset {2:X8}", offset, listIndex, Index[listIndex].LogicalOffset); return listIndex; diff --git a/src/BizHawk.Emulation.DiscSystem/DiscoHawkLogic/ECMTest.cs b/src/BizHawk.Emulation.DiscSystem/DiscoHawkLogic/ECMTest.cs index 93d5051c10..0027a5738c 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscoHawkLogic/ECMTest.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscoHawkLogic/ECMTest.cs @@ -81,10 +81,9 @@ namespace BizHawk.Emulation.DiscSystem // plaindisc.ReadLBA_2352_Flat(item.Item1, chunkbuf_corlet, 0, item.Item2); // API has changed // ecmdisc.ReadLBA_2352_Flat(item.Item1, chunkbuf_mine, 0, item.Item2); // API has changed for (int i = 0; i < item.Item2; i++) - if (chunkbuf_corlet[i] != chunkbuf_mine[i]) - { - Debug.Assert(false); - } + { + Debug.Assert(chunkbuf_corlet[i] == chunkbuf_mine[i], $"buffers differ at [{t}; {i}]"); + } } } }