Skip to content
Snippets Groups Projects
Commit 5a0f29af authored by Sebastian Hahta's avatar Sebastian Hahta
Browse files

fix gui segfault (VR used before initialization)

parent 2109778f
No related branches found
No related tags found
No related merge requests found
Pipeline #16593 failed
......@@ -268,7 +268,6 @@ bool ftl::gui::Camera::setVR(bool on) {
src_->set("focal", intrinsic(0, 0));
src_->set("centre_x", intrinsic(0, 2));
src_->set("centre_y", intrinsic(1, 2));
LOG(INFO) << intrinsic;
intrinsic = getCameraMatrix(screen_->getVR(), vr::Eye_Right);
CHECK(intrinsic(0, 2) < 0 && intrinsic(1, 2) < 0);
......@@ -376,8 +375,9 @@ const GLTexture &ftl::gui::Camera::captureFrame() {
if (src_ && src_->isReady()) {
UNIQUE_LOCK(mutex_, lk);
if (isVR()) {
if (screen_->isVR()) {
#ifdef HAVE_OPENVR
vr::VRCompositor()->WaitGetPoses(rTrackedDevicePose_, vr::k_unMaxTrackedDeviceCount, NULL, 0 );
if ((channel_ == Channel::Right) && rTrackedDevicePose_[vr::k_unTrackedDeviceIndex_Hmd].bPoseIsValid )
......
......@@ -149,7 +149,7 @@ MediaPanel::MediaPanel(ftl::gui::Screen *screen) : nanogui::Window(screen, ""),
auto button_vr = new Button(this, "VR");
button_vr->setFlags(Button::ToggleButton);
button_vr->setChangeCallback([this, button_vr](bool state) {
if (!screen_->useVR()) {
if (!screen_->isVR()) {
if (screen_->switchVR(true) == true) {
button_vr->setTextColor(nanogui::Color(0.5f,0.5f,1.0f,1.0f));
this->button_channels_->setEnabled(false);
......
......@@ -319,14 +319,14 @@ bool ftl::gui::Screen::initVR() {
return true;
}
bool ftl::gui::Screen::useVR() {
bool ftl::gui::Screen::isVR() {
auto *cam = activeCamera();
if (HMD_ == nullptr || cam == nullptr) { return false; }
return cam->isVR();
}
bool ftl::gui::Screen::switchVR(bool on) {
if (useVR() == on) { return on; }
if (isVR() == on) { return on; }
if (on && (HMD_ == nullptr) && !initVR()) {
return false;
......@@ -338,7 +338,7 @@ bool ftl::gui::Screen::switchVR(bool on) {
activeCamera()->setVR(false);
}
return useVR();
return isVR();
}
#endif
......@@ -466,7 +466,7 @@ void ftl::gui::Screen::draw(NVGcontext *ctx) {
if (camera_->getChannel() != ftl::codecs::Channel::Left) { mImageID = rightEye_; }
#ifdef HAVE_OPENVR
if (useVR() && imageSize[0] > 0 && camera_->getLeft().isValid() && camera_->getRight().isValid()) {
if (isVR() && imageSize[0] > 0 && camera_->getLeft().isValid() && camera_->getRight().isValid()) {
vr::Texture_t leftEyeTexture = {(void*)(uintptr_t)leftEye_, vr::TextureType_OpenGL, vr::ColorSpace_Gamma };
vr::VRCompositor()->Submit(vr::Eye_Left, &leftEyeTexture );
......
......@@ -52,7 +52,7 @@ class Screen : public nanogui::Screen {
bool hasVR() const { return has_vr_; }
// is VR mode on/off
bool useVR();
bool isVR();
// toggle VR on/off
bool switchVR(bool mode);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment