diff --git a/Dotnet/Overlay/OffScreenBrowser.cs b/Dotnet/Overlay/OffScreenBrowser.cs index 374f22e0..9dbd5f70 100644 --- a/Dotnet/Overlay/OffScreenBrowser.cs +++ b/Dotnet/Overlay/OffScreenBrowser.cs @@ -62,6 +62,10 @@ namespace VRCX public void RenderToTexture(Texture2D texture) { + // Safeguard against uninitialized texture + if (texture == null) + return; + _paintBufferLock.EnterReadLock(); try { diff --git a/Dotnet/Overlay/VRCXVR.cs b/Dotnet/Overlay/VRCXVR.cs index 34a4a004..53c6b0dd 100644 --- a/Dotnet/Overlay/VRCXVR.cs +++ b/Dotnet/Overlay/VRCXVR.cs @@ -12,7 +12,6 @@ using System.Text; using System.Threading; using CefSharp; using SharpDX; -using SharpDX.Direct3D; using SharpDX.Direct3D11; using SharpDX.DXGI; using Valve.VR; @@ -82,30 +81,13 @@ namespace VRCX MainForm.Instance.Browser.ExecuteScriptAsync("console.log('VRCXVR Restarted');"); } - private void ThreadLoop() + private void SetupTextures() { - var active = false; - var e = new VREvent_t(); - var nextInit = DateTime.MinValue; - var nextDeviceUpdate = DateTime.MinValue; - var nextOverlay = DateTime.MinValue; - var overlayIndex = OpenVR.k_unTrackedDeviceIndexInvalid; - var overlayVisible1 = false; - var overlayVisible2 = false; - var dashboardHandle = 0UL; - var overlayHandle1 = 0UL; - var overlayHandle2 = 0UL; - - // REMOVE THIS - // nextOverlay = DateTime.MaxValue; - // https://stackoverflow.com/questions/38312597/how-to-choose-a-specific-graphics-device-in-sharpdx-directx-11/38596725#38596725 Factory f = new Factory1(); - var a = f.GetAdapter(1); - - var flags = DeviceCreationFlags.BgraSupport; - - _device = Program.GPUFix ? new Device(a, flags) : new Device(DriverType.Hardware, DeviceCreationFlags.SingleThreaded | DeviceCreationFlags.BgraSupport); + _device = new Device(f.GetAdapter(OpenVR.System.GetD3D9AdapterIndex()), + DeviceCreationFlags.SingleThreaded | DeviceCreationFlags.BgraSupport); + _texture1?.Dispose(); _texture1 = new Texture2D( _device, new Texture2DDescription @@ -121,7 +103,8 @@ namespace VRCX CpuAccessFlags = CpuAccessFlags.Write } ); - + + _texture2?.Dispose(); _texture2 = new Texture2D( _device, new Texture2DDescription @@ -137,7 +120,22 @@ namespace VRCX CpuAccessFlags = CpuAccessFlags.Write } ); + } + private void ThreadLoop() + { + var active = false; + var e = new VREvent_t(); + var nextInit = DateTime.MinValue; + var nextDeviceUpdate = DateTime.MinValue; + var nextOverlay = DateTime.MinValue; + var overlayIndex = OpenVR.k_unTrackedDeviceIndexInvalid; + var overlayVisible1 = false; + var overlayVisible2 = false; + var dashboardHandle = 0UL; + var overlayHandle1 = 0UL; + var overlayHandle2 = 0UL; + _browser1 = new OffScreenBrowser( "file://vrcx/vr.html?1", 512, @@ -183,6 +181,7 @@ namespace VRCX } active = true; + SetupTextures(); } while (system.PollNextEvent(ref e, (uint)Marshal.SizeOf(e))) diff --git a/Dotnet/Program.cs b/Dotnet/Program.cs index ce333ffa..d4fc0f01 100644 --- a/Dotnet/Program.cs +++ b/Dotnet/Program.cs @@ -20,7 +20,6 @@ namespace VRCX public static string ConfigLocation; public static string Version { get; private set; } public static bool LaunchDebug; - public static bool GPUFix; private static readonly NLog.Logger logger = NLog.LogManager.GetLogger("VRCX"); static Program() { @@ -143,7 +142,6 @@ namespace VRCX ProcessMonitor.Instance.Init(); SQLiteLegacy.Instance.Init(); VRCXStorage.Load(); - LoadFromConfig(); CpuMonitor.Instance.Init(); Discord.Instance.Init(); WebApi.Instance.Init(); @@ -170,14 +168,5 @@ namespace VRCX SQLiteLegacy.Instance.Exit(); ProcessMonitor.Instance.Exit(); } - - /// - /// Sets GPUFix to true if it is not already set and the VRCX_GPUFix key in the database is true. - /// - private static void LoadFromConfig() - { - if (!GPUFix) - GPUFix = VRCXStorage.Instance.Get("VRCX_GPUFix") == "true"; - } } } \ No newline at end of file diff --git a/Dotnet/StartupArgs.cs b/Dotnet/StartupArgs.cs index 658cf35c..25a561f5 100644 --- a/Dotnet/StartupArgs.cs +++ b/Dotnet/StartupArgs.cs @@ -27,9 +27,6 @@ namespace VRCX foreach (var arg in args) { - if (arg.Contains("--gpufix")) - Program.GPUFix = true; - if (arg.Length > 12 && arg.Substring(0, 12) == "/uri=vrcx://") LaunchCommand = arg.Substring(12);