From fe7b6018266f4111a501857fbe8b2114006e25a6 Mon Sep 17 00:00:00 2001 From: KeatonTheBot Date: Sat, 13 Dec 2025 13:32:29 -0600 Subject: [PATCH] misc: chore: Fix possible NullReferenceExceptions, suppress warnings --- src/ARMeilleure/Translation/IntervalTree.cs | 2 +- .../SoundIoHardwareDeviceSession.cs | 54 +++++++++---------- .../AppleHv/HvAddressSpaceRange.cs | 6 +-- .../Threed/Blender/AdvancedBlendFunctions.cs | 7 ++- .../Image/TextureBindingsArrayCache.cs | 6 +-- .../Effects/FxaaPostProcessingEffect.cs | 6 +++ src/Ryujinx.HLE/HOS/ModLoader.cs | 4 +- .../Services/Bluetooth/IBluetoothDriver.cs | 2 +- .../HOS/Services/Bluetooth/IBluetoothUser.cs | 2 +- .../FileSystemProxy/FileSystemProxyHelper.cs | 4 +- .../HOS/Services/Fs/IFileSystemProxy.cs | 2 +- src/Ryujinx.HLE/HOS/Services/IpcService.cs | 4 +- .../LdnRyu/LdnMasterProxyClient.cs | 7 ++- .../HOS/Services/Nv/INvDrvServices.cs | 4 +- .../NvHostAsGpu/NvHostAsGpuDeviceFile.cs | 2 +- .../Sockets/Bsd/Impl/ManagedSocket.cs | 6 +-- .../Services/Sockets/Bsd/Types/BsdMsgHdr.cs | 1 + .../HOS/Services/Sockets/Nsd/IManager.cs | 2 +- .../SslService/SslManagedSocketConnection.cs | 23 ++++---- src/Ryujinx.HLE/UI/RenderingSurfaceInfo.cs | 3 +- .../Friends/Detail/Ipc/NotificationService.cs | 6 +-- .../Sdk/Sf/Cmif/ServerDomainManager.cs | 7 +-- .../VirtualMemoryManagerBase.cs | 4 +- .../SequenceReaderExtensionsTests.cs | 4 +- .../UI/Views/User/UserEditorView.axaml.cs | 4 +- .../UserProfileImageSelectorView.axaml.cs | 2 +- .../UI/Views/User/UserRecovererView.axaml.cs | 2 +- .../Views/User/UserSaveManagerView.axaml.cs | 2 +- src/Ryujinx/UI/Windows/StyleableWindow.cs | 2 +- 29 files changed, 100 insertions(+), 80 deletions(-) diff --git a/src/ARMeilleure/Translation/IntervalTree.cs b/src/ARMeilleure/Translation/IntervalTree.cs index 072016ef7..4bea8ff0b 100644 --- a/src/ARMeilleure/Translation/IntervalTree.cs +++ b/src/ARMeilleure/Translation/IntervalTree.cs @@ -316,7 +316,7 @@ namespace ARMeilleure.Translation { _root = newNode; } - else if (start.CompareTo(parent.Start) < 0) + else if (start.CompareTo(parent!.Start) < 0) { parent.Left = newNode; } diff --git a/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs b/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs index 1540cd0e3..c751a31a5 100644 --- a/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs +++ b/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs @@ -143,7 +143,7 @@ namespace Ryujinx.Audio.Backends.SoundIo { for (int frame = 0; frame < frameCount; frame++) { - ((byte*)area.Pointer)[0] = srcptr[frame * bytesPerFrame]; + (((byte*)area.Pointer)!)[0] = srcptr[frame * bytesPerFrame]; area.Pointer += area.Step; } @@ -152,7 +152,7 @@ namespace Ryujinx.Audio.Backends.SoundIo { for (int frame = 0; frame < frameCount; frame++) { - ((short*)area.Pointer)[0] = ((short*)srcptr)[frame * bytesPerFrame >> 1]; + (((short*)area.Pointer)!)[0] = ((short*)srcptr)[frame * bytesPerFrame >> 1]; area.Pointer += area.Step; } @@ -161,7 +161,7 @@ namespace Ryujinx.Audio.Backends.SoundIo { for (int frame = 0; frame < frameCount; frame++) { - ((int*)area.Pointer)[0] = ((int*)srcptr)[frame * bytesPerFrame >> 2]; + (((int*)area.Pointer)!)[0] = ((int*)srcptr)[frame * bytesPerFrame >> 2]; area.Pointer += area.Step; } @@ -190,10 +190,10 @@ namespace Ryujinx.Audio.Backends.SoundIo for (int frame = 0; frame < frameCount; frame++) { // Channel 1 - ((byte*)area1.Pointer)[0] = srcptr[(frame * bytesPerFrame) + 0]; + (((byte*)area1.Pointer)!)[0] = srcptr[(frame * bytesPerFrame) + 0]; // Channel 2 - ((byte*)area2.Pointer)[0] = srcptr[(frame * bytesPerFrame) + 1]; + (((byte*)area2.Pointer)!)[0] = srcptr[(frame * bytesPerFrame) + 1]; area1.Pointer += area1.Step; area2.Pointer += area2.Step; @@ -204,10 +204,10 @@ namespace Ryujinx.Audio.Backends.SoundIo for (int frame = 0; frame < frameCount; frame++) { // Channel 1 - ((short*)area1.Pointer)[0] = ((short*)srcptr)[(frame * bytesPerFrame >> 1) + 0]; + (((short*)area1.Pointer)!)[0] = ((short*)srcptr)[(frame * bytesPerFrame >> 1) + 0]; // Channel 2 - ((short*)area2.Pointer)[0] = ((short*)srcptr)[(frame * bytesPerFrame >> 1) + 1]; + (((short*)area2.Pointer)!)[0] = ((short*)srcptr)[(frame * bytesPerFrame >> 1) + 1]; area1.Pointer += area1.Step; area2.Pointer += area2.Step; @@ -218,10 +218,10 @@ namespace Ryujinx.Audio.Backends.SoundIo for (int frame = 0; frame < frameCount; frame++) { // Channel 1 - ((int*)area1.Pointer)[0] = ((int*)srcptr)[(frame * bytesPerFrame >> 2) + 0]; + (((int*)area1.Pointer)!)[0] = ((int*)srcptr)[(frame * bytesPerFrame >> 2) + 0]; // Channel 2 - ((int*)area2.Pointer)[0] = ((int*)srcptr)[(frame * bytesPerFrame >> 2) + 1]; + (((int*)area2.Pointer)!)[0] = ((int*)srcptr)[(frame * bytesPerFrame >> 2) + 1]; area1.Pointer += area1.Step; area2.Pointer += area2.Step; @@ -260,22 +260,22 @@ namespace Ryujinx.Audio.Backends.SoundIo for (int frame = 0; frame < frameCount; frame++) { // Channel 1 - ((byte*)area1.Pointer)[0] = srcptr[(frame * bytesPerFrame) + 0]; + (((byte*)area1.Pointer)!)[0] = srcptr[(frame * bytesPerFrame) + 0]; // Channel 2 - ((byte*)area2.Pointer)[0] = srcptr[(frame * bytesPerFrame) + 1]; + (((byte*)area2.Pointer)!)[0] = srcptr[(frame * bytesPerFrame) + 1]; // Channel 3 - ((byte*)area3.Pointer)[0] = srcptr[(frame * bytesPerFrame) + 2]; + (((byte*)area3.Pointer)!)[0] = srcptr[(frame * bytesPerFrame) + 2]; // Channel 4 - ((byte*)area4.Pointer)[0] = srcptr[(frame * bytesPerFrame) + 3]; + (((byte*)area4.Pointer)!)[0] = srcptr[(frame * bytesPerFrame) + 3]; // Channel 5 - ((byte*)area5.Pointer)[0] = srcptr[(frame * bytesPerFrame) + 4]; + (((byte*)area5.Pointer)!)[0] = srcptr[(frame * bytesPerFrame) + 4]; // Channel 6 - ((byte*)area6.Pointer)[0] = srcptr[(frame * bytesPerFrame) + 5]; + (((byte*)area6.Pointer)!)[0] = srcptr[(frame * bytesPerFrame) + 5]; area1.Pointer += area1.Step; area2.Pointer += area2.Step; @@ -290,22 +290,22 @@ namespace Ryujinx.Audio.Backends.SoundIo for (int frame = 0; frame < frameCount; frame++) { // Channel 1 - ((short*)area1.Pointer)[0] = ((short*)srcptr)[(frame * bytesPerFrame >> 1) + 0]; + (((short*)area1.Pointer)!)[0] = ((short*)srcptr)[(frame * bytesPerFrame >> 1) + 0]; // Channel 2 - ((short*)area2.Pointer)[0] = ((short*)srcptr)[(frame * bytesPerFrame >> 1) + 1]; + (((short*)area2.Pointer)!)[0] = ((short*)srcptr)[(frame * bytesPerFrame >> 1) + 1]; // Channel 3 - ((short*)area3.Pointer)[0] = ((short*)srcptr)[(frame * bytesPerFrame >> 1) + 2]; + (((short*)area3.Pointer)!)[0] = ((short*)srcptr)[(frame * bytesPerFrame >> 1) + 2]; // Channel 4 - ((short*)area4.Pointer)[0] = ((short*)srcptr)[(frame * bytesPerFrame >> 1) + 3]; + (((short*)area4.Pointer)!)[0] = ((short*)srcptr)[(frame * bytesPerFrame >> 1) + 3]; // Channel 5 - ((short*)area5.Pointer)[0] = ((short*)srcptr)[(frame * bytesPerFrame >> 1) + 4]; + (((short*)area5.Pointer)!)[0] = ((short*)srcptr)[(frame * bytesPerFrame >> 1) + 4]; // Channel 6 - ((short*)area6.Pointer)[0] = ((short*)srcptr)[(frame * bytesPerFrame >> 1) + 5]; + (((short*)area6.Pointer)!)[0] = ((short*)srcptr)[(frame * bytesPerFrame >> 1) + 5]; area1.Pointer += area1.Step; area2.Pointer += area2.Step; @@ -320,22 +320,22 @@ namespace Ryujinx.Audio.Backends.SoundIo for (int frame = 0; frame < frameCount; frame++) { // Channel 1 - ((int*)area1.Pointer)[0] = ((int*)srcptr)[(frame * bytesPerFrame >> 2) + 0]; + (((int*)area1.Pointer)!)[0] = ((int*)srcptr)[(frame * bytesPerFrame >> 2) + 0]; // Channel 2 - ((int*)area2.Pointer)[0] = ((int*)srcptr)[(frame * bytesPerFrame >> 2) + 1]; + (((int*)area2.Pointer)!)[0] = ((int*)srcptr)[(frame * bytesPerFrame >> 2) + 1]; // Channel 3 - ((int*)area3.Pointer)[0] = ((int*)srcptr)[(frame * bytesPerFrame >> 2) + 2]; + (((int*)area3.Pointer)!)[0] = ((int*)srcptr)[(frame * bytesPerFrame >> 2) + 2]; // Channel 4 - ((int*)area4.Pointer)[0] = ((int*)srcptr)[(frame * bytesPerFrame >> 2) + 3]; + (((int*)area4.Pointer)!)[0] = ((int*)srcptr)[(frame * bytesPerFrame >> 2) + 3]; // Channel 5 - ((int*)area5.Pointer)[0] = ((int*)srcptr)[(frame * bytesPerFrame >> 2) + 4]; + (((int*)area5.Pointer)!)[0] = ((int*)srcptr)[(frame * bytesPerFrame >> 2) + 4]; // Channel 6 - ((int*)area6.Pointer)[0] = ((int*)srcptr)[(frame * bytesPerFrame >> 2) + 5]; + (((int*)area6.Pointer)!)[0] = ((int*)srcptr)[(frame * bytesPerFrame >> 2) + 5]; area1.Pointer += area1.Step; area2.Pointer += area2.Step; diff --git a/src/Ryujinx.Cpu/AppleHv/HvAddressSpaceRange.cs b/src/Ryujinx.Cpu/AppleHv/HvAddressSpaceRange.cs index 7754431fa..44fcaeab7 100644 --- a/src/Ryujinx.Cpu/AppleHv/HvAddressSpaceRange.cs +++ b/src/Ryujinx.Cpu/AppleHv/HvAddressSpaceRange.cs @@ -150,7 +150,7 @@ namespace Ryujinx.Cpu.AppleHv // Entry is a block but is not aligned, we need to turn it into a table. ref ulong pte = ref level.AsSpan()[l]; nextTable = CreateTable(pte, depth + 1); - level.Next[l] = nextTable; + level.Next?[l] = nextTable; // Now that we have a table, we can handle it like the first case. UnmapImpl(nextTable, depth + 1, va, chunckSize); @@ -166,7 +166,7 @@ namespace Ryujinx.Cpu.AppleHv if (nextTable != null) { nextTable.Allocation.Dispose(); - level.Next[l] = null; + level.Next?[l] = null; } level.AsSpan()[l] = 0UL; @@ -215,7 +215,7 @@ namespace Ryujinx.Cpu.AppleHv { // Entry is a block but is not aligned, we need to turn it into a table. nextTable = CreateTable(pte, depth + 1); - level.Next[l] = nextTable; + level.Next?[l] = nextTable; // Now that we have a table, we can handle it like the first case. UpdateAttributes(nextTable, depth + 1, va, chunckSize, newAttr); diff --git a/src/Ryujinx.Graphics.Gpu/Engine/Threed/Blender/AdvancedBlendFunctions.cs b/src/Ryujinx.Graphics.Gpu/Engine/Threed/Blender/AdvancedBlendFunctions.cs index 2c6908851..b5a42349c 100644 --- a/src/Ryujinx.Graphics.Gpu/Engine/Threed/Blender/AdvancedBlendFunctions.cs +++ b/src/Ryujinx.Graphics.Gpu/Engine/Threed/Blender/AdvancedBlendFunctions.cs @@ -225,10 +225,15 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed.Blender { Hash128 hash = XXHash128.ComputeHash(MemoryMarshal.Cast(entry.Code)); - string[] constants = new string[entry.Constants != null ? entry.Constants.Length : 0]; + string[] constants = new string[entry.Constants?.Length ?? 0]; for (int i = 0; i < constants.Length; i++) { + if (entry.Constants == null) + { + continue; + } + RgbFloat rgb = entry.Constants[i]; constants[i] = string.Format(CultureInfo.InvariantCulture, "new " + nameof(RgbFloat) + "({0}f, {1}f, {2}f)", rgb.R, rgb.G, rgb.B); diff --git a/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsArrayCache.cs b/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsArrayCache.cs index fc3b64c03..5244b9b76 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsArrayCache.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsArrayCache.cs @@ -1061,17 +1061,17 @@ namespace Ryujinx.Graphics.Gpu.Image } } - if (entry.CacheNode != null) + if (entry?.CacheNode != null) { _lruCache.Remove(entry.CacheNode); _lruCache.AddLast(entry.CacheNode); } else { - entry.CacheNode = _lruCache.AddLast(entry); + entry?.CacheNode = _lruCache.AddLast(entry); } - entry.CacheTimestamp = ++_currentTimestamp; + entry?.CacheTimestamp = ++_currentTimestamp; RemoveLeastUsedEntries(); diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs b/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs index 4229bb3f8..1aaaac2ff 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs @@ -54,6 +54,11 @@ namespace Ryujinx.Graphics.OpenGL.Effects GL.ActiveTexture(TextureUnit.Texture0); int previousTextureBinding = GL.GetInteger(GetPName.TextureBinding2D); + if (textureView == null) + { + return null; + } + GL.BindImageTexture(0, textureView.Handle, 0, false, 0, TextureAccess.ReadWrite, SizedInternalFormat.Rgba8); GL.UseProgram(_shaderProgram); @@ -76,6 +81,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects GL.ActiveTexture((TextureUnit)previousUnit); return textureView; + } } } diff --git a/src/Ryujinx.HLE/HOS/ModLoader.cs b/src/Ryujinx.HLE/HOS/ModLoader.cs index 1b88c13d7..860b97f70 100644 --- a/src/Ryujinx.HLE/HOS/ModLoader.cs +++ b/src/Ryujinx.HLE/HOS/ModLoader.cs @@ -173,7 +173,7 @@ namespace Ryujinx.HLE.HOS types.Clear(); Mod mod = new("", null, true); - if (StrEquals(RomfsDir, modDir.Name)) + if (StrEquals(RomfsDir, modDir.Name) && modDir.Parent != null) { var modData = modMetadata.Mods.FirstOrDefault(x => modDir.Parent.FullName.Equals(x.Path)); var enabled = modData?.Enabled ?? true; @@ -181,7 +181,7 @@ namespace Ryujinx.HLE.HOS mods.RomfsDirs.Add(mod = new Mod(dir.Name, modDir, enabled)); types.Append('R'); } - else if (StrEquals(ExefsDir, modDir.Name)) + else if (StrEquals(ExefsDir, modDir.Name) && modDir.Parent != null) { var modData = modMetadata.Mods.FirstOrDefault(x => modDir.Parent.FullName.Equals(x.Path)); var enabled = modData?.Enabled ?? true; diff --git a/src/Ryujinx.HLE/HOS/Services/Bluetooth/IBluetoothDriver.cs b/src/Ryujinx.HLE/HOS/Services/Bluetooth/IBluetoothDriver.cs index 8f2642695..a6810d461 100644 --- a/src/Ryujinx.HLE/HOS/Services/Bluetooth/IBluetoothDriver.cs +++ b/src/Ryujinx.HLE/HOS/Services/Bluetooth/IBluetoothDriver.cs @@ -24,7 +24,7 @@ namespace Ryujinx.HLE.HOS.Services.Bluetooth int initializeEventHandle; - if ((bool)debugMode) + if ((bool)debugMode!) { if (BluetoothEventManager.InitializeBleDebugEventHandle == 0) { diff --git a/src/Ryujinx.HLE/HOS/Services/Bluetooth/IBluetoothUser.cs b/src/Ryujinx.HLE/HOS/Services/Bluetooth/IBluetoothUser.cs index ea4a46f92..34af673ed 100644 --- a/src/Ryujinx.HLE/HOS/Services/Bluetooth/IBluetoothUser.cs +++ b/src/Ryujinx.HLE/HOS/Services/Bluetooth/IBluetoothUser.cs @@ -15,7 +15,7 @@ namespace Ryujinx.HLE.HOS.Services.Bluetooth { NxSettings.Settings.TryGetValue("bluetooth_debug!skip_boot", out object debugMode); - if ((bool)debugMode) + if ((bool)debugMode!) { context.Response.HandleDesc = IpcHandleDesc.MakeCopy(BluetoothEventManager.RegisterBleDebugEventHandle); } diff --git a/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/FileSystemProxyHelper.cs b/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/FileSystemProxyHelper.cs index 20ffb996d..e05d5a751 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/FileSystemProxyHelper.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fs/FileSystemProxy/FileSystemProxyHelper.cs @@ -78,9 +78,9 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy DirectoryInfo archivePath = new DirectoryInfo(fullPath).Parent; - while (string.IsNullOrWhiteSpace(archivePath.Extension)) + while (string.IsNullOrWhiteSpace(archivePath?.Extension)) { - archivePath = archivePath.Parent; + archivePath = archivePath?.Parent; } if (archivePath.Extension == ".nsp" && File.Exists(archivePath.FullName)) diff --git a/src/Ryujinx.HLE/HOS/Services/Fs/IFileSystemProxy.cs b/src/Ryujinx.HLE/HOS/Services/Fs/IFileSystemProxy.cs index dcd55d579..46d28c46a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Fs/IFileSystemProxy.cs +++ b/src/Ryujinx.HLE/HOS/Services/Fs/IFileSystemProxy.cs @@ -59,7 +59,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs if (!File.Exists(fullPath)) { - if (fullPath.Contains('.')) + if (fullPath!.Contains('.')) { ResultCode result = FileSystemProxyHelper.OpenFileSystemFromInternalFile(context, fullPath, out FileSystemProxy.IFileSystem fileSystem); diff --git a/src/Ryujinx.HLE/HOS/Services/IpcService.cs b/src/Ryujinx.HLE/HOS/Services/IpcService.cs index d1b210f12..049da17c8 100644 --- a/src/Ryujinx.HLE/HOS/Services/IpcService.cs +++ b/src/Ryujinx.HLE/HOS/Services/IpcService.cs @@ -128,7 +128,7 @@ namespace Ryujinx.HLE.HOS.Services _parameters[0] = context; - result = (ResultCode)processRequest.Invoke(service, _parameters); + result = (ResultCode)processRequest.Invoke(service, _parameters)!; } else { @@ -183,7 +183,7 @@ namespace Ryujinx.HLE.HOS.Services _parameters[0] = context; - result = (ResultCode)processRequest.Invoke(this, _parameters); + result = (ResultCode)processRequest.Invoke(this, _parameters)!; } else { diff --git a/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/LdnRyu/LdnMasterProxyClient.cs b/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/LdnRyu/LdnMasterProxyClient.cs index 616d46b95..bd0b93438 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/LdnRyu/LdnMasterProxyClient.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/LdnRyu/LdnMasterProxyClient.cs @@ -409,7 +409,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu bool openSuccess = i < P2pProxyServer.PrivatePortRange; - if (openSuccess) + if (openSuccess && _hostedProxy != null) { Task natPunchResult = _hostedProxy.NatPunch(); @@ -421,7 +421,10 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu request.ExternalProxyPort = natPunchResult.Result; } } - catch (Exception) { } + catch (Exception) + { + // ignored + } if (request.ExternalProxyPort == 0) { diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs b/src/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs index 2ef994914..91103caa2 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/INvDrvServices.cs @@ -83,9 +83,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv ConstructorInfo constructor = deviceFileClass.GetConstructor([typeof(ServiceCtx), typeof(IVirtualMemoryManager), typeof(ulong) ]); - NvDeviceFile deviceFile = (NvDeviceFile)constructor.Invoke([context, _clientMemory, _owner]); + NvDeviceFile deviceFile = (NvDeviceFile)constructor?.Invoke([context, _clientMemory, _owner]); - deviceFile.Path = path; + deviceFile?.Path = path; fd = DeviceFileIdRegistry.Add(deviceFile); diff --git a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs index 130ed14ae..d2068290f 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nv/NvDrvServices/NvHostAsGpu/NvHostAsGpuDeviceFile.cs @@ -111,7 +111,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu // TODO: Return invalid Fd error. } - channelDeviceFile.Channel.BindMemory(_asContext.Gmm); + channelDeviceFile?.Channel.BindMemory(_asContext.Gmm); return NvInternalResult.Success; } diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs index 01024407e..9e1081675 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs @@ -190,7 +190,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl { Socket.Listen(backlog); - Logger.Info?.PrintMsg(LogClass.ServiceBsd, $"Socket listening: {ProtocolType}/{(Socket.LocalEndPoint as IPEndPoint).Port}"); + Logger.Info?.PrintMsg(LogClass.ServiceBsd, $"Socket listening: {ProtocolType}/{((IPEndPoint)Socket.LocalEndPoint).Port}"); return LinuxError.SUCCESS; } @@ -573,7 +573,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl try { - int receiveSize = (Socket as DefaultSocket).BaseSocket.Receive(ConvertMessagesToBuffer(message), ConvertBsdSocketFlags(flags), out SocketError socketError); + int receiveSize = ((DefaultSocket)Socket).BaseSocket.Receive(ConvertMessagesToBuffer(message), ConvertBsdSocketFlags(flags), out SocketError socketError); if (receiveSize > 0) { @@ -615,7 +615,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl try { - int sendSize = (Socket as DefaultSocket).BaseSocket.Send(ConvertMessagesToBuffer(message), ConvertBsdSocketFlags(flags), out SocketError socketError); + int sendSize = ((DefaultSocket)Socket).BaseSocket.Send(ConvertMessagesToBuffer(message), ConvertBsdSocketFlags(flags), out SocketError socketError); if (sendSize > 0) { diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdMsgHdr.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdMsgHdr.cs index 6b6617e21..da6fa961a 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdMsgHdr.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdMsgHdr.cs @@ -56,6 +56,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Types { for (int index = 0; index < iovCount; index++) { + if (message.Iov == null) continue; ulong iovLength = (ulong)message.Iov[index].Length; if (!MemoryMarshal.TryWrite(rawData, in iovLength)) diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/IManager.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/IManager.cs index 0c1fa3a9f..3232ce9a4 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/IManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Nsd/IManager.cs @@ -44,7 +44,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd NsdSettings = new NsdSettings { Initialized = true, - TestMode = (bool)testMode, + TestMode = (bool)testMode!, Environment = (string)environmentIdentifier, }; } diff --git a/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/SslManagedSocketConnection.cs b/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/SslManagedSocketConnection.cs index dc33dd6a5..e089250ad 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/SslManagedSocketConnection.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ssl/SslService/SslManagedSocketConnection.cs @@ -254,18 +254,23 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService public ResultCode GetServerCertificate(string hostname, Span certificates, out uint storageSize, out uint certificateCount) { - byte[] rawCertData = _stream.RemoteCertificate.GetRawCertData(); - - storageSize = (uint)rawCertData.Length; - certificateCount = 1; - - if (rawCertData.Length > certificates.Length) + if (_stream.RemoteCertificate != null) { - return ResultCode.CertBufferTooSmall; + byte[] rawCertData = _stream.RemoteCertificate.GetRawCertData(); + + storageSize = (uint)rawCertData.Length; + certificateCount = 1; + + if (rawCertData.Length > certificates.Length) + { + return ResultCode.CertBufferTooSmall; + } + + rawCertData.CopyTo(certificates); } - rawCertData.CopyTo(certificates); - + storageSize = 0; + certificateCount = 0; return ResultCode.Success; } diff --git a/src/Ryujinx.HLE/UI/RenderingSurfaceInfo.cs b/src/Ryujinx.HLE/UI/RenderingSurfaceInfo.cs index af0a0d44e..555a3b1cd 100644 --- a/src/Ryujinx.HLE/UI/RenderingSurfaceInfo.cs +++ b/src/Ryujinx.HLE/UI/RenderingSurfaceInfo.cs @@ -25,7 +25,8 @@ namespace Ryujinx.HLE.UI public bool Equals(RenderingSurfaceInfo other) { - return ColorFormat == other.ColorFormat && + return other != null && + ColorFormat == other.ColorFormat && Width == other.Width && Height == other.Height && Pitch == other.Pitch && diff --git a/src/Ryujinx.Horizon/Sdk/Friends/Detail/Ipc/NotificationService.cs b/src/Ryujinx.Horizon/Sdk/Friends/Detail/Ipc/NotificationService.cs index d9ad40c94..3a3d021b9 100644 --- a/src/Ryujinx.Horizon/Sdk/Friends/Detail/Ipc/NotificationService.cs +++ b/src/Ryujinx.Horizon/Sdk/Friends/Detail/Ipc/NotificationService.cs @@ -64,7 +64,7 @@ namespace Ryujinx.Horizon.Sdk.Friends.Detail.Ipc { lock (_lock) { - if (_notifications.Count >= 1) + if (_notifications.Count >= 1 && _notifications.First != null) { sizedNotificationInfo = _notifications.First.Value; _notifications.RemoveFirst(); @@ -97,7 +97,7 @@ namespace Ryujinx.Horizon.Sdk.Friends.Detail.Ipc { SizedNotificationInfo friendListNotification = new(); - if (_notifications.Count != 0) + if (_notifications.Count != 0 && _notifications.First != null) { friendListNotification = _notifications.First.Value; _notifications.RemoveFirst(); @@ -110,7 +110,7 @@ namespace Ryujinx.Horizon.Sdk.Friends.Detail.Ipc { SizedNotificationInfo newFriendRequestNotification = new(); - if (_notifications.Count != 0) + if (_notifications.Count != 0 && _notifications.First != null) { newFriendRequestNotification = _notifications.First.Value; _notifications.RemoveFirst(); diff --git a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerDomainManager.cs b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerDomainManager.cs index 8198efd7c..75b157d91 100644 --- a/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerDomainManager.cs +++ b/src/Ryujinx.Horizon/Sdk/Sf/Cmif/ServerDomainManager.cs @@ -45,7 +45,7 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif return null; } - var entry = _freeList.First.Value; + var entry = _freeList.First?.Value; _freeList.RemoveFirst(); return entry; } @@ -117,11 +117,9 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif public override void RegisterObject(int id, ServiceObjectHolder obj) { var entry = _manager._entryManager.GetEntry(id); - DebugUtil.Assert(entry != null); lock (_manager._entryOwnerLock) { - DebugUtil.Assert(entry.Owner == null); entry.Owner = this; entry.Node = _entries.AddLast(entry); } @@ -188,9 +186,6 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif { var entry = _manager._entryManager.GetEntry(ids[i]); - DebugUtil.Assert(entry != null); - DebugUtil.Assert(entry.Owner == null); - _manager._entryManager.FreeEntry(entry); } } diff --git a/src/Ryujinx.Memory/VirtualMemoryManagerBase.cs b/src/Ryujinx.Memory/VirtualMemoryManagerBase.cs index 44d8ec134..3ed21d010 100644 --- a/src/Ryujinx.Memory/VirtualMemoryManagerBase.cs +++ b/src/Ryujinx.Memory/VirtualMemoryManagerBase.cs @@ -78,7 +78,9 @@ namespace Ryujinx.Memory } } - return new ReadOnlySequence(first, 0, last, (int)(size - last.RunningIndex)); + return first != null + ? new ReadOnlySequence(first, 0, last, (int)(size - last.RunningIndex)) + : default; } } diff --git a/src/Ryujinx.Tests/Common/Extensions/SequenceReaderExtensionsTests.cs b/src/Ryujinx.Tests/Common/Extensions/SequenceReaderExtensionsTests.cs index 2ef49ce7b..0dbefbad1 100644 --- a/src/Ryujinx.Tests/Common/Extensions/SequenceReaderExtensionsTests.cs +++ b/src/Ryujinx.Tests/Common/Extensions/SequenceReaderExtensionsTests.cs @@ -354,7 +354,9 @@ namespace Ryujinx.Tests.Common.Extensions index += nextSegmentLength; } - return new ReadOnlySequence(first, 0, last, (int)(memory.Length - last.RunningIndex)); + return first != null + ? new ReadOnlySequence(first, 0, last, (int)(memory.Length - last.RunningIndex)) + : default; } } } diff --git a/src/Ryujinx/UI/Views/User/UserEditorView.axaml.cs b/src/Ryujinx/UI/Views/User/UserEditorView.axaml.cs index 564c9157b..d80429d5b 100644 --- a/src/Ryujinx/UI/Views/User/UserEditorView.axaml.cs +++ b/src/Ryujinx/UI/Views/User/UserEditorView.axaml.cs @@ -48,8 +48,8 @@ namespace Ryujinx.Ava.UI.Views.User break; } - ((ContentDialog)_parent.Parent).Title = $"{LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle]} - " + - $"{(_isNewUser ? LocaleManager.Instance[LocaleKeys.UserEditorTitleCreate] : LocaleManager.Instance[LocaleKeys.UserEditorTitle])}"; + ((ContentDialog)_parent.Parent)?.Title = $"{LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle]} - " + + $"{(_isNewUser ? LocaleManager.Instance[LocaleKeys.UserEditorTitleCreate] : LocaleManager.Instance[LocaleKeys.UserEditorTitle])}"; DataContext = TempProfile; diff --git a/src/Ryujinx/UI/Views/User/UserProfileImageSelectorView.axaml.cs b/src/Ryujinx/UI/Views/User/UserProfileImageSelectorView.axaml.cs index e798757eb..c10f6a0ab 100644 --- a/src/Ryujinx/UI/Views/User/UserProfileImageSelectorView.axaml.cs +++ b/src/Ryujinx/UI/Views/User/UserProfileImageSelectorView.axaml.cs @@ -42,7 +42,7 @@ namespace Ryujinx.Ava.UI.Views.User (_parent, _profile) = ((NavigationDialogHost, TempProfile))arg.Parameter; _contentManager = _parent.ContentManager; - ((ContentDialog)_parent.Parent).Title = $"{LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle]} - {LocaleManager.Instance[LocaleKeys.ProfileImageSelectionHeader]}"; + ((ContentDialog)_parent.Parent)?.Title = $"{LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle]} - {LocaleManager.Instance[LocaleKeys.ProfileImageSelectionHeader]}"; if (Program.PreviewerDetached) { diff --git a/src/Ryujinx/UI/Views/User/UserRecovererView.axaml.cs b/src/Ryujinx/UI/Views/User/UserRecovererView.axaml.cs index 3e3439a07..dc522c788 100644 --- a/src/Ryujinx/UI/Views/User/UserRecovererView.axaml.cs +++ b/src/Ryujinx/UI/Views/User/UserRecovererView.axaml.cs @@ -31,7 +31,7 @@ namespace Ryujinx.Ava.UI.Views.User _parent = parent; - ((ContentDialog)_parent.Parent).Title = $"{LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle]} - {LocaleManager.Instance[LocaleKeys.UserProfilesRecoverHeading]}"; + ((ContentDialog)_parent.Parent)?.Title = $"{LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle]} - {LocaleManager.Instance[LocaleKeys.UserProfilesRecoverHeading]}"; break; } diff --git a/src/Ryujinx/UI/Views/User/UserSaveManagerView.axaml.cs b/src/Ryujinx/UI/Views/User/UserSaveManagerView.axaml.cs index db0b7b93f..8f7d15dc0 100644 --- a/src/Ryujinx/UI/Views/User/UserSaveManagerView.axaml.cs +++ b/src/Ryujinx/UI/Views/User/UserSaveManagerView.axaml.cs @@ -58,7 +58,7 @@ namespace Ryujinx.Ava.UI.Views.User } DataContext = ViewModel = new UserSaveManagerViewModel(_accountManager); - ((ContentDialog)_parent.Parent).Title = $"{LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle]} - {ViewModel.SaveManagerHeading}"; + ((ContentDialog)_parent.Parent)?.Title = $"{LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle]} - {ViewModel.SaveManagerHeading}"; Task.Run(LoadSaves); } diff --git a/src/Ryujinx/UI/Windows/StyleableWindow.cs b/src/Ryujinx/UI/Windows/StyleableWindow.cs index 59882dd0c..4558008d6 100644 --- a/src/Ryujinx/UI/Windows/StyleableWindow.cs +++ b/src/Ryujinx/UI/Windows/StyleableWindow.cs @@ -19,7 +19,7 @@ namespace Ryujinx.Ava.UI.Windows WindowStartupLocation = WindowStartupLocation.CenterOwner; TransparencyLevelHint = [WindowTransparencyLevel.None]; - using Stream stream = Assembly.GetAssembly(typeof(ConfigurationState)).GetManifestResourceStream("Ryujinx.UI.Common.Resources.Logo_Ryujinx.png"); + using Stream stream = Assembly.GetAssembly(typeof(ConfigurationState))?.GetManifestResourceStream("Ryujinx.UI.Common.Resources.Logo_Ryujinx.png"); Icon = new WindowIcon(stream); stream.Position = 0;