misc: chore: Fix possible NullReferenceExceptions, InvalidOperationExceptions

This commit is contained in:
KeatonTheBot 2025-09-30 15:03:01 -05:00
parent fa682d406e
commit 51b32981b6
15 changed files with 70 additions and 49 deletions

View file

@ -58,7 +58,7 @@ namespace ARMeilleure.Translation
private static string GetKey(MethodInfo info)
{
return $"{info.DeclaringType.Name}.{info.Name}";
return $"{info.DeclaringType?.Name}.{info.Name}";
}
private static readonly SortedList<string, DelegateInfo> _delegates;

View file

@ -316,13 +316,16 @@ namespace ARMeilleure.Translation
{
_root = newNode;
}
else if (start.CompareTo(parent.Start) < 0)
else if (parent != null && start.CompareTo(parent.Start) < 0)
{
parent.Left = newNode;
}
else
{
parent.Right = newNode;
if (parent != null)
{
parent.Right = newNode;
}
}
PropagateIncrease(newNode);

View file

@ -147,7 +147,7 @@ namespace Ryujinx.Graphics.GAL
return false;
}
if (Descriptors != null)
if (Descriptors != null && other.Descriptors != null)
{
if (Descriptors.Count != other.Descriptors.Count)
{

View file

@ -240,44 +240,47 @@ namespace Ryujinx.Graphics.Vulkan
int dstOffset = 0;
bool activeRange = false;
for (int i = 0; i < list.Count; i++)
if (list != null)
{
var range = list[i];
int rangeEnd = range.Offset + range.Size;
if (activeRange)
for (int i = 0; i < list.Count; i++)
{
if (range.Offset >= endOffset)
var range = list[i];
int rangeEnd = range.Offset + range.Size;
if (activeRange)
{
break;
if (range.Offset >= endOffset)
{
break;
}
}
}
else
{
if (rangeEnd <= offset)
else
{
continue;
if (rangeEnd <= offset)
{
continue;
}
activeRange = true;
}
activeRange = true;
}
int baseSize = range.Offset - srcOffset;
int baseSize = range.Offset - srcOffset;
if (baseSize > 0)
{
baseData.Slice(dstOffset, baseSize).CopyTo(result.Slice(dstOffset, baseSize));
srcOffset += baseSize;
dstOffset += baseSize;
}
if (baseSize > 0)
{
baseData.Slice(dstOffset, baseSize).CopyTo(result.Slice(dstOffset, baseSize));
srcOffset += baseSize;
dstOffset += baseSize;
}
int modSize = Math.Min(rangeEnd - srcOffset, endOffset - srcOffset);
if (modSize != 0)
{
modData.Slice(dstOffset, modSize).CopyTo(result.Slice(dstOffset, modSize));
srcOffset += modSize;
dstOffset += modSize;
int modSize = Math.Min(rangeEnd - srcOffset, endOffset - srcOffset);
if (modSize != 0)
{
modData.Slice(dstOffset, modSize).CopyTo(result.Slice(dstOffset, modSize));
srcOffset += modSize;
dstOffset += modSize;
}
}
}

View file

@ -1691,6 +1691,11 @@ namespace Ryujinx.Graphics.Vulkan
return false;
}
if (_renderPass == null)
{
return true;
}
var pipeline = pbp == PipelineBindPoint.Compute
? _newState.CreateComputePipeline(Gd, Device, _program, PipelineCache)
: _newState.CreateGraphicsPipeline(Gd, Device, _program, PipelineCache, _renderPass.Get(Cbs).Value);

View file

@ -48,7 +48,7 @@ namespace Ryujinx.Graphics.Vulkan
return false;
}
if (SetDescriptors != null)
if (SetDescriptors != null && other.SetDescriptors != null)
{
if (SetDescriptors.Count != other.SetDescriptors.Count)
{

View file

@ -231,7 +231,7 @@ namespace Ryujinx.Graphics.Vulkan
private void FreeCompletedManualDescriptorSets()
{
FenceHolder signalledFence = null;
while (_pendingManualDsConsumptions.TryPeek(out var pds) && (pds.Fence == signalledFence || pds.Fence.IsSignaled()))
while (_pendingManualDsConsumptions.TryPeek(out var pds) && pds.Fence != null && (pds.Fence == signalledFence || pds.Fence.IsSignaled()))
{
signalledFence = pds.Fence; // Already checked - don't need to do it again.
var dequeued = _pendingManualDsConsumptions.Dequeue();

View file

@ -134,14 +134,18 @@ namespace Ryujinx.Graphics.Vulkan
// Register this render pass with all render target views.
var textures = fb.GetAttachmentViews();
foreach (var texture in textures)
if (fb != null)
{
texture.AddRenderPass(key, this);
var textures = fb.GetAttachmentViews();
foreach (var texture in textures)
{
texture.AddRenderPass(key, this);
}
_textures = textures;
}
_textures = textures;
_key = key;
_forcedFences = [];

View file

@ -544,7 +544,7 @@ namespace Ryujinx.Graphics.Vulkan
pipeline.StagesCount = 1;
pipeline.PipelineLayout = PipelineLayout;
pipeline.CreateComputePipeline(_gd, _device, this, (_gd.Pipeline as PipelineBase).PipelineCache);
pipeline.CreateComputePipeline(_gd, _device, this, ((PipelineBase)_gd.Pipeline).PipelineCache);
pipeline.Dispose();
}
@ -573,7 +573,7 @@ namespace Ryujinx.Graphics.Vulkan
pipeline.StagesCount = (uint)_shaders.Length;
pipeline.PipelineLayout = PipelineLayout;
pipeline.CreateGraphicsPipeline(_gd, _device, this, (_gd.Pipeline as PipelineBase).PipelineCache, renderPass.Value, throwOnError: true);
pipeline.CreateGraphicsPipeline(_gd, _device, this, ((PipelineBase)_gd.Pipeline).PipelineCache, renderPass.Value, throwOnError: true);
pipeline.Dispose();
}

View file

@ -266,7 +266,7 @@ namespace Ryujinx.Graphics.Vulkan
public void FreeCompleted()
{
FenceHolder signalledFence = null;
while (_pendingCopies.TryPeek(out var pc) && (pc.Fence == signalledFence || pc.Fence.IsSignaled()))
while (_pendingCopies.TryPeek(out var pc) && pc.Fence != null && (pc.Fence == signalledFence || pc.Fence.IsSignaled()))
{
signalledFence = pc.Fence; // Already checked - don't need to do it again.
var dequeued = _pendingCopies.Dequeue();

View file

@ -58,7 +58,7 @@ namespace Ryujinx.HLE.Debugger
internal KProcess Process => Device.System?.DebugGetApplicationProcess();
internal IDebuggableProcess DebugProcess => Device.System?.DebugGetApplicationProcessDebugInterface();
private KThread[] GetThreads() => DebugProcess.GetThreadUids().Select(x => DebugProcess.GetThread(x)).ToArray();
internal bool IsProcessAarch32 => DebugProcess.GetThread(gThread.Value).Context.IsAarch32;
internal bool IsProcessAarch32 => gThread != null && DebugProcess.GetThread(gThread.Value).Context.IsAarch32;
private KernelContext KernelContext => Device.System.KernelContext;
const int GdbRegisterCount64 = 68;

View file

@ -1099,7 +1099,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
}
if (!IPAddress.TryParse(ldnServer, out IPAddress ipAddress))
{
ipAddress = Dns.GetHostEntry(ldnServer).AddressList[0];
ipAddress = Dns.GetHostEntry(ldnServer ?? string.Empty).AddressList[0];
}
NetworkClient = new LdnMasterProxyClient(ipAddress.ToString(), LanPlayPort, context.Device.Configuration);
}

View file

@ -267,7 +267,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Proxy
// Attempt to find matching configuration. If we don't find one, wait for a bit and try again.
// Woken by new tokens coming in from the master server.
IPAddress address = (session.Socket.RemoteEndPoint as IPEndPoint).Address;
IPAddress address = (session.Socket.RemoteEndPoint as IPEndPoint)?.Address;
byte[] addressBytes = ProxyHelpers.AddressTo16Byte(address);
long time;
@ -282,7 +282,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Proxy
// Allow any client that has a private IP to connect. (indicated by the server as all 0 in the token)
bool isPrivate = waitToken.PhysicalIp.AsSpan().SequenceEqual(new byte[16]);
bool ipEqual = isPrivate || waitToken.AddressFamily == address.AddressFamily && waitToken.PhysicalIp.AsSpan().SequenceEqual(addressBytes);
bool ipEqual = address != null && (isPrivate || waitToken.AddressFamily == address.AddressFamily && waitToken.PhysicalIp.AsSpan().SequenceEqual(addressBytes));
if (ipEqual && waitToken.Token.AsSpan().SequenceEqual(config.Token.AsSpan()))
{

View file

@ -37,7 +37,10 @@ namespace Ryujinx.Ava.UI.Controls
private void SearchBox_OnKeyUp(object sender, KeyEventArgs args)
{
(DataContext as MainWindowViewModel).SearchText = (sender as TextBox)?.Text;
if (DataContext is MainWindowViewModel model)
{
model.SearchText = (sender as TextBox)?.Text;
}
}
}
}

View file

@ -38,7 +38,10 @@ namespace Ryujinx.Ava.UI.Controls
private void SearchBox_OnKeyUp(object sender, KeyEventArgs args)
{
(DataContext as MainWindowViewModel).SearchText = (sender as TextBox)?.Text;
if (DataContext is MainWindowViewModel model)
{
model.SearchText = (sender as TextBox)?.Text;
}
}
private async void IdString_OnClick(object sender, RoutedEventArgs e)