Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Z64Utils/Common/BitUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override string ToString()
if (Value.HasFlag(v))
{
var name = Enum.GetName(typeof(T), v);
Debug.Assert(name != null);
Utils.Assert(name != null);
if (count == 0)
ret = name;
else
Expand All @@ -33,7 +33,7 @@ public override string ToString()
if (count == 0)
{
var name = Enum.GetName(typeof(T), 0);
Debug.Assert(name != null);
Utils.Assert(name != null);
return name;
}

Expand Down
14 changes: 14 additions & 0 deletions Z64Utils/Common/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -130,5 +131,18 @@ public static byte[] ZlibDecompress(byte[] input, int decSize)
return outStream.GetBuffer();
}
}

class AssertFailedException : Exception { }

// Avoid using Debug.Assert because that uses FailFast which kills the application
// without giving us a chance to log the exception.
[Conditional("DEBUG")]
public static void Assert([DoesNotReturnIf(false)] bool condition)
{
if (!condition)
{
throw new AssertFailedException();
}
}
}
}
3 changes: 2 additions & 1 deletion Z64Utils/F3DZEX/Command/CmdInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common;
using RDP;

namespace F3DZEX.Command
Expand Down Expand Up @@ -407,7 +408,7 @@ private static object ConvertCommand(Type t, CmdInfo cmd)
throw new InvalidF3DZEXOpCodeException("Invalid ID");

object? obj = Activator.CreateInstance(t);
Debug.Assert(obj != null);
Utils.Assert(obj != null);

foreach (var prop in t.GetProperties())
{
Expand Down
2 changes: 1 addition & 1 deletion Z64Utils/F3DZEX/Disassembler/Disassembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public List<string> Disassemble()
if (macroDis != null)
{
dis = macroDis;
Debug.Assert(cmdCount > 0);
Utils.Assert(cmdCount > 0);
toSkip = cmdCount - 1;
comments = new List<string>()
{
Expand Down
5 changes: 3 additions & 2 deletions Z64Utils/F3DZEX/Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Common;
using RDP;
using Z64;

Expand Down Expand Up @@ -118,7 +119,7 @@ public byte[] ReadBytes(uint vaddr, int count)
{
case SegmentType.Fill:
{
Debug.Assert(seg.Data != null);
Utils.Assert(seg.Data != null);
byte[] buff = new byte[count];
int rest = count;
int dstOff = 0;
Expand All @@ -139,7 +140,7 @@ public byte[] ReadBytes(uint vaddr, int count)
return buff;
}
case SegmentType.Buffer:
Debug.Assert(seg.Data != null);
Utils.Assert(seg.Data != null);
if (addr.SegmentOff + count <= seg.Data.Length)
{
byte[] buff = new byte[count];
Expand Down
13 changes: 7 additions & 6 deletions Z64Utils/F3DZEX/Render/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common;
using F3DZEX.Command;
using N64;
using OpenTK;
Expand Down Expand Up @@ -324,12 +325,12 @@ void AssertInitialized()
{
if (!_initialized)
throw new Exception("Not initialized (yet)!");
Debug.Assert(_rdpVtxDrawer != null);
Debug.Assert(_gridDrawer != null);
Debug.Assert(_axisDrawer != null);
Debug.Assert(_textDrawer != null);
Debug.Assert(_tex0 != null);
Debug.Assert(_tex1 != null);
Utils.Assert(_rdpVtxDrawer != null);
Utils.Assert(_gridDrawer != null);
Utils.Assert(_axisDrawer != null);
Utils.Assert(_textDrawer != null);
Utils.Assert(_tex0 != null);
Utils.Assert(_tex1 != null);
}

public void ClearErrors() => ErrorMsg = null;
Expand Down
7 changes: 4 additions & 3 deletions Z64Utils/F3DZEX/Render/TextDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Common;
using OpenTK;
using OpenTK.Graphics.OpenGL;
using OpenTK.Mathematics;
Expand Down Expand Up @@ -57,9 +58,9 @@ public TextDrawer()
_tex = new TextureHandler();

TextFont = new Font("Arial", 50);
Debug.Assert(_font != null);
Debug.Assert(_charSpaces != null);
Debug.Assert(_texData != null);
Utils.Assert(_font != null);
Utils.Assert(_charSpaces != null);
Utils.Assert(_texData != null);

_lastStr = null;
Scale = 0.35f;
Expand Down
3 changes: 2 additions & 1 deletion Z64Utils/Forms/AnalyzerSettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Common;
using F3DZEX.Command;

namespace Z64.Forms
Expand Down Expand Up @@ -79,7 +80,7 @@ private void buttonRestrivtive_Click(object sender, EventArgs e)
foreach (var patternStr in patternsStr)
{
var pattern = Z64ObjectAnalyzer.Config.OpCodePattern.Parse(patternStr);
Debug.Assert(pattern != null);
Utils.Assert(pattern != null);
Result.Patterns.Add(pattern);
}
UpdateTextBoxes();
Expand Down
4 changes: 2 additions & 2 deletions Z64Utils/Forms/CollisionViewerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ private void NewRender()
{
_polygons = new RenderColPoly[_colHeader.NbPolygons];

Debug.Assert(_colHeader.PolygonsHolder != null);
Debug.Assert(_colHeader.VerticesHolder != null);
Utils.Assert(_colHeader.PolygonsHolder != null);
Utils.Assert(_colHeader.VerticesHolder != null);
for (int i = 0; i < _colHeader.NbPolygons; i++)
{
Z64Object.CollisionPolygonsHolder.CollisionPoly colPoly = _colHeader
Expand Down
10 changes: 5 additions & 5 deletions Z64Utils/Forms/DListViewerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void RenderCallback(Matrix4 proj, Matrix4 view)
_renderer.ModelMtxStack.Push(
Matrix4.CreateTranslation(routine.X, routine.Y, routine.Z)
);
Debug.Assert(routine.Dlist != null);
Utils.Assert(routine.Dlist != null);
_renderer.RenderDList(routine.Dlist);
_renderer.ModelMtxStack.Pop();
}
Expand Down Expand Up @@ -367,13 +367,13 @@ private void AddRoutineMenuItem_Click(object sender, System.EventArgs e)
);
if (form.ShowDialog() == DialogResult.OK)
{
Debug.Assert(form.Result != null);
Utils.Assert(form.Result != null);
var parts = form.Result.Replace(" ", "").Split(";");
int x = 0,
y = 0,
z = 0;
var addr = SegmentedAddress.Parse(parts[0], true);
Debug.Assert(addr != null);
Utils.Assert(addr != null);
if (parts.Length > 1)
{
x = int.Parse(parts[1]);
Expand Down Expand Up @@ -401,12 +401,12 @@ private void EditRoutineMenuItem_Click(object sender, EventArgs e)

if (form.ShowDialog() == DialogResult.OK)
{
Debug.Assert(form.Result != null);
Utils.Assert(form.Result != null);
var parts = form.Result.Replace(" ", "").Split(";");

routine.X = routine.Y = routine.Z = 0;
var addr = SegmentedAddress.Parse(parts[0], true);
Debug.Assert(addr != null);
Utils.Assert(addr != null);
routine.Address = addr;

if (parts.Length > 1)
Expand Down
34 changes: 17 additions & 17 deletions Z64Utils/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ private void UpdateControls(bool inTask = false)

private void UpdateFileList(bool forceReload)
{
Debug.Assert(_game != null);
Debug.Assert(_fileItemsText != null);
Utils.Assert(_game != null);
Utils.Assert(_fileItemsText != null);

if (forceReload)
_lastSearch = null;
Expand Down Expand Up @@ -153,7 +153,7 @@ private void OpenObjectAnalyzer(Z64Game game, byte[] data, string fileName, stri

if (valueForm.ShowDialog() == DialogResult.OK)
{
Debug.Assert(valueForm.Result != null);
Utils.Assert(valueForm.Result != null);
var form = new ObjectAnalyzerForm(
game,
data,
Expand Down Expand Up @@ -237,7 +237,7 @@ private void RomOpenItem_Click(object sender, EventArgs e)

private void RomSaveItem_Click(object sender, EventArgs e)
{
Debug.Assert(_game != null);
Utils.Assert(_game != null);
saveFileDialog1.FileName = "";
saveFileDialog1.Filter = $"{Filters.N64}|{Filters.ALL}";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
Expand All @@ -250,7 +250,7 @@ private void RomSaveItem_Click(object sender, EventArgs e)

private void RomExportFsItem_Click(object sender, EventArgs e)
{
Debug.Assert(_game != null);
Utils.Assert(_game != null);
folderBrowserDialog1.SelectedPath = "";
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
Expand Down Expand Up @@ -280,7 +280,7 @@ private void RomExportFsItem_Click(object sender, EventArgs e)

private void RomImportNamesItem_Click(object sender, EventArgs e)
{
Debug.Assert(_game != null);
Utils.Assert(_game != null);
openFileDialog1.FileName = "";
openFileDialog1.Filter = $"{Filters.TXT}|{Filters.ALL}";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
Expand All @@ -292,7 +292,7 @@ private void RomImportNamesItem_Click(object sender, EventArgs e)

private void RomExportNamesItem_Click(object sender, EventArgs e)
{
Debug.Assert(_game != null);
Utils.Assert(_game != null);
saveFileDialog1.FileName = "";
saveFileDialog1.Filter = $"{Filters.TXT}|{Filters.ALL}";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
Expand All @@ -303,7 +303,7 @@ private void RomExportNamesItem_Click(object sender, EventArgs e)

private void InjectToolStripMenuItem_Click(object sender, EventArgs e)
{
Debug.Assert(_game != null);
Utils.Assert(_game != null);
if (listView_files.SelectedIndices.Count != 1)
return;
var item = listView_files.SelectedItems[0];
Expand All @@ -320,7 +320,7 @@ private void InjectToolStripMenuItem_Click(object sender, EventArgs e)

private void SaveToolStripMenuItem1_Click(object sender, EventArgs e)
{
Debug.Assert(_game != null);
Utils.Assert(_game != null);
if (listView_files.SelectedIndices.Count != 1)
return;
var item = listView_files.SelectedItems[0];
Expand Down Expand Up @@ -362,7 +362,7 @@ private void OpenObjectViewerForExternalFile(byte[] data, string fileName)

if (valueForm.ShowDialog() == DialogResult.OK)
{
Debug.Assert(valueForm.Result != null);
Utils.Assert(valueForm.Result != null);
var form = new ObjectAnalyzerForm(
_game,
data,
Expand All @@ -376,7 +376,7 @@ private void OpenObjectViewerForExternalFile(byte[] data, string fileName)

private void OpenObjectViewerToolStripMenuItem_Click(object sender, EventArgs e)
{
Debug.Assert(_game != null);
Utils.Assert(_game != null);
if (listView_files.SelectedIndices.Count != 1)
return;
var item = listView_files.SelectedItems[0];
Expand All @@ -401,7 +401,7 @@ private void OpenObjectViewerToolStripMenuItem_Click(object sender, EventArgs e)

private void renameToolStripMenuItem_Click(object sender, EventArgs e)
{
Debug.Assert(_game != null);
Utils.Assert(_game != null);
if (listView_files.SelectedIndices.Count != 1)
return;
var item = listView_files.SelectedItems[0];
Expand All @@ -416,7 +416,7 @@ private void renameToolStripMenuItem_Click(object sender, EventArgs e)
);
if (valueForm.ShowDialog() == DialogResult.OK)
{
Debug.Assert(valueForm.Result != null);
Utils.Assert(valueForm.Result != null);
_game.Version.RenameFile(file.VRomStart, valueForm.Result);
listView_files.SelectedItems[0].Text = valueForm.Result;
}
Expand All @@ -429,7 +429,7 @@ private void TextBox_fileFilter_TextChanged(object sender, EventArgs e)

private void OpenDlistViewerToolStripMenuItem_Click(object sender, EventArgs e)
{
Debug.Assert(_game != null);
Utils.Assert(_game != null);
DListViewerForm.OpenInstance(_game);
}

Expand All @@ -440,13 +440,13 @@ private void f3DEXDisassemblerToolStripMenuItem_Click(object sender, EventArgs e

private void ROMRAMConversionsToolStripMenuItem_Click(object sender, EventArgs e)
{
Debug.Assert(_game != null);
Utils.Assert(_game != null);
new ConversionForm(_game).Show();
}

private void textureViewerToolStripMenuItem_Click(object sender, EventArgs e)
{
Debug.Assert(_game != null);
Utils.Assert(_game != null);
new TextureViewer(_game).Show();
}

Expand Down Expand Up @@ -492,7 +492,7 @@ private void objectAnalyzerToolStripMenuItem_Click(object sender, EventArgs e)

private void listView_files_DoubleClick(object sender, EventArgs e)
{
Debug.Assert(_game != null);
Utils.Assert(_game != null);
if (listView_files.SelectedIndices.Count != 1)
return;
var item = listView_files.SelectedItems[0];
Expand Down
4 changes: 3 additions & 1 deletion Z64Utils/Forms/ModelViewerControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace Z64.Forms
{
public partial class ModelViewerControl : GLControl
{
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();

public Matrix4 Projection => _projectionMtx;
public Matrix4 View => _viewMtx;

Expand Down Expand Up @@ -120,7 +122,7 @@ public void Render()
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Logger.Warn(ex);
}

if (Height == 0)
Expand Down
Loading