misc: chore: Fix possible NullReferenceExceptions, InvalidOperationExceptions

This commit is contained in:
KeatonTheBot
2025-10-06 11:48:21 -05:00
parent fa5b5b127e
commit 7a5b5dee6a
12 changed files with 63 additions and 45 deletions
+1 -1
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)
{
@@ -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;
}
}
}
@@ -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);
@@ -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)
{
@@ -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();
@@ -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 = [];
@@ -542,7 +542,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();
}
@@ -571,7 +571,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();
}
+1 -1
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();
@@ -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);
}
@@ -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()))
{
@@ -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;
}
}
}
}
@@ -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)