Skip to content

Commit 5c58563

Browse files
authored
VR Fixes 2 (#3458)
Improved error logging, crash fixes, and light menu tweaks
1 parent 132f75f commit 5c58563

File tree

3 files changed

+1074
-364
lines changed

3 files changed

+1074
-364
lines changed

engine/Definitions/engine/VR/fpxr.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ native class fpxr::ApplicationConfig as Facepunch.XR.ApplicationConfig
2828
{
2929
fpxr::ApplicationConfig::GetInstance().m_debugCallback = (fpxr::PFN_DebugCallback)dbgCallback;
3030
}
31+
32+
inline static void SetErrorCallback( IntPtr errCallback )
33+
{
34+
fpxr::ApplicationConfig::GetInstance().m_errorCallback = (fpxr::PFN_ErrorCallback)errCallback;
35+
}
3136
}
3237

3338
native class fpxr::EventManager as Facepunch.XR.EventManager

engine/Sandbox.Engine/Platform/VR/VRNative.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,15 @@ private static string BufferToString( byte* buffer, uint maxLength )
9999
}
100100

101101
public delegate void DebugUtilsMessengerCallback( string message, DebugCallbackType type );
102+
public delegate void DebugUtilsErrorCallback( string message );
102103

103-
private static Logger Log = new( "VR" );
104+
private static Logger Log = new( "OpenXR" );
105+
106+
private static void XrErrorCallback( string message )
107+
{
108+
Log.Error( $"{message}" );
109+
Application.Exit(); // For now
110+
}
104111

105112
private static void XrDebugCallback( string message, DebugCallbackType type )
106113
{
@@ -143,11 +150,17 @@ internal static void CreateInstance()
143150
if ( !VRSystem.HasHeadset )
144151
return;
145152

146-
if ( VRSystem.WantsDebug )
153+
// Initialize app config callbacks
147154
{
148-
// Set up a debug callback for logging Facepunch.XR messages
149-
var pDebugCallback = Marshal.GetFunctionPointerForDelegate<DebugUtilsMessengerCallback>( XrDebugCallback );
150-
ApplicationConfig.SetDebugCallback( pDebugCallback );
155+
if ( VRSystem.WantsDebug )
156+
{
157+
// Set up a debug callback for logging Facepunch.XR messages
158+
var pDebugCallback = Marshal.GetFunctionPointerForDelegate<DebugUtilsMessengerCallback>( XrDebugCallback );
159+
ApplicationConfig.SetDebugCallback( pDebugCallback );
160+
}
161+
162+
var pErrorCallback = Marshal.GetFunctionPointerForDelegate<DebugUtilsErrorCallback>( XrErrorCallback );
163+
ApplicationConfig.SetErrorCallback( pErrorCallback );
151164
}
152165

153166
// Create the OpenXR instance

0 commit comments

Comments
 (0)