Move OpenVR init function out of Overlaycontroller
This prevents the issue of OpenVR not being initialized in constructors of other objects, and there's really no reason not to do it.
This commit is contained in:
@@ -37,6 +37,9 @@ int main( int argc, char* argv[] )
|
||||
commandLineArgs.forceRemoveManifest );
|
||||
}
|
||||
|
||||
openvr_init::OpenVR_Init openvr_init(
|
||||
openvr_init::OpenVrInitializationType::Overlay );
|
||||
|
||||
try
|
||||
{
|
||||
// QSettings contains a platform independant way of storing settings in
|
||||
|
||||
@@ -31,8 +31,7 @@ QSettings* OverlayController::_appSettings = nullptr;
|
||||
OverlayController::OverlayController( bool desktopMode,
|
||||
bool noSound,
|
||||
QQmlEngine& qmlEngine )
|
||||
: QObject(), m_desktopMode( desktopMode ), m_noSound( noSound ),
|
||||
m_openVrInit(), m_actions()
|
||||
: QObject(), m_desktopMode( desktopMode ), m_noSound( noSound ), m_actions()
|
||||
{
|
||||
// Despite arguably being OpenVR init code, the call is still here because
|
||||
// the TabController uses this directly. Offering it through OpenVR_Init
|
||||
|
||||
@@ -106,11 +106,6 @@ private:
|
||||
uint64_t m_lastFrame = 0;
|
||||
int m_vsyncTooLateCounter = 0;
|
||||
|
||||
// OpenVR_Init must be declared before any other class that uses OpenVR
|
||||
// function calls since objects are initialized in order of declaration in
|
||||
// the class.
|
||||
openvr_init::OpenVR_Init m_openVrInit;
|
||||
|
||||
input::SteamIVRInput m_actions;
|
||||
|
||||
public: // I know it's an ugly hack to make them public to enable external
|
||||
|
||||
@@ -7,10 +7,20 @@
|
||||
|
||||
namespace openvr_init
|
||||
{
|
||||
void initializeProperly()
|
||||
void initializeProperly( const OpenVrInitializationType initType )
|
||||
{
|
||||
auto initializationType = vr::EVRApplicationType::VRApplication_Other;
|
||||
if ( initType == OpenVrInitializationType::Overlay )
|
||||
{
|
||||
initializationType = vr::EVRApplicationType::VRApplication_Overlay;
|
||||
}
|
||||
else if ( initType == OpenVrInitializationType::Utility )
|
||||
{
|
||||
initializationType = vr::EVRApplicationType::VRApplication_Utility;
|
||||
}
|
||||
|
||||
auto initError = vr::VRInitError_None;
|
||||
vr::VR_Init( &initError, vr::VRApplication_Overlay );
|
||||
vr::VR_Init( &initError, initializationType );
|
||||
if ( initError != vr::VRInitError_None )
|
||||
{
|
||||
if ( initError == vr::VRInitError_Init_HmdNotFound
|
||||
@@ -20,10 +30,11 @@ void initializeProperly()
|
||||
"OpenVR Advanced Settings Overlay",
|
||||
"Could not find HMD!" );
|
||||
}
|
||||
throw std::runtime_error(
|
||||
std::string( "Failed to initialize OpenVR: " )
|
||||
+ std::string(
|
||||
vr::VR_GetVRInitErrorAsEnglishDescription( initError ) ) );
|
||||
LOG( ERROR ) << "Failed to initialize OpenVR: "
|
||||
+ std::string(
|
||||
vr::VR_GetVRInitErrorAsEnglishDescription(
|
||||
initError ) );
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -31,9 +42,9 @@ void initializeProperly()
|
||||
}
|
||||
}
|
||||
|
||||
OpenVR_Init::OpenVR_Init()
|
||||
OpenVR_Init::OpenVR_Init( const OpenVrInitializationType initType )
|
||||
{
|
||||
initializeProperly();
|
||||
initializeProperly( initType );
|
||||
|
||||
// The function call and error message was the same for all version checks.
|
||||
// Specific error messages are unlikely to be necessary since both the type
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
|
||||
namespace openvr_init
|
||||
{
|
||||
enum class OpenVrInitializationType
|
||||
{
|
||||
Overlay,
|
||||
Utility,
|
||||
};
|
||||
|
||||
/*!
|
||||
Initializes OpenVR and checks validity of interface versions. Shuts down OpenVR
|
||||
when destroyed.
|
||||
@@ -17,7 +23,7 @@ implementation.
|
||||
class OpenVR_Init
|
||||
{
|
||||
public:
|
||||
OpenVR_Init();
|
||||
OpenVR_Init( const OpenVrInitializationType initType );
|
||||
~OpenVR_Init();
|
||||
|
||||
// As per the Rule of Five, the following constructors and assignments can
|
||||
|
||||
+22
-31
@@ -10,6 +10,7 @@
|
||||
#include <openvr.h>
|
||||
#include <iostream>
|
||||
#include <easylogging++.h>
|
||||
#include "../overlaycontroller/openvr_init.h"
|
||||
|
||||
enum ReturnErrorCode
|
||||
{
|
||||
@@ -294,42 +295,32 @@ void reinstallApplicationManifest( const QString manifestPath )
|
||||
[[noreturn]] void handleManifests( const bool installManifest,
|
||||
const bool removeManifest )
|
||||
{
|
||||
int exit_code = ReturnErrorCode::SUCCESS;
|
||||
auto openvr_init_status = vr::VRInitError_None;
|
||||
vr::VR_Init( &openvr_init_status, vr::VRApplication_Utility );
|
||||
if ( openvr_init_status == vr::VRInitError_None )
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto manifestPath = QDir::cleanPath(
|
||||
QDir( QCoreApplication::applicationDirPath() )
|
||||
.absoluteFilePath( kVRManifestName ) );
|
||||
openvr_init::OpenVR_Init openvr_init(
|
||||
openvr_init::OpenVrInitializationType::Utility );
|
||||
|
||||
if ( installManifest )
|
||||
{
|
||||
reinstallApplicationManifest( manifestPath );
|
||||
enableApplicationAutostart();
|
||||
LOG( INFO ) << "Manifest reinstalled.";
|
||||
}
|
||||
else if ( removeManifest )
|
||||
{
|
||||
removeApplicationManifest( manifestPath );
|
||||
LOG( INFO ) << "Manifest removed.";
|
||||
}
|
||||
}
|
||||
catch ( std::exception& e )
|
||||
int exit_code = ReturnErrorCode::SUCCESS;
|
||||
try
|
||||
{
|
||||
const auto manifestPath
|
||||
= QDir::cleanPath( QDir( QCoreApplication::applicationDirPath() )
|
||||
.absoluteFilePath( kVRManifestName ) );
|
||||
|
||||
if ( installManifest )
|
||||
{
|
||||
exit_code = ReturnErrorCode::GENERAL_FAILURE;
|
||||
LOG( ERROR ) << e.what();
|
||||
reinstallApplicationManifest( manifestPath );
|
||||
enableApplicationAutostart();
|
||||
LOG( INFO ) << "Manifest reinstalled.";
|
||||
}
|
||||
else if ( removeManifest )
|
||||
{
|
||||
removeApplicationManifest( manifestPath );
|
||||
LOG( INFO ) << "Manifest removed.";
|
||||
}
|
||||
}
|
||||
else
|
||||
catch ( std::exception& e )
|
||||
{
|
||||
exit_code = ReturnErrorCode::OPENVR_INIT_ERROR;
|
||||
LOG( ERROR ) << std::string(
|
||||
"Failed to initialize OpenVR: "
|
||||
+ std::string( vr::VR_GetVRInitErrorAsEnglishDescription(
|
||||
openvr_init_status ) ) );
|
||||
exit_code = ReturnErrorCode::GENERAL_FAILURE;
|
||||
LOG( ERROR ) << e.what();
|
||||
}
|
||||
|
||||
vr::VR_Shutdown();
|
||||
|
||||
Reference in New Issue
Block a user