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:
Vasily
2019-03-10 23:12:26 +01:00
committed by username223
parent 9f24099a93
commit 37e0366e9d
6 changed files with 52 additions and 47 deletions
+22 -31
View File
@@ -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();