Skip to content
Snippets Groups Projects
Commit 0a78e5ba authored by Iiro Rastas's avatar Iiro Rastas Committed by Nicolas Pope
Browse files

Fix record button callback segmentation fault

Setting the callback inside the callback was causing segmentation faults
in some cases. The record button now has a single top-level callback
that gets the necessary information through members added to the
MediaPanel class.
parent 39149bc2
No related branches found
No related tags found
No related merge requests found
#include "media_panel.hpp"
#include "screen.hpp"
#include "camera.hpp"
#include <nanogui/layout.h>
#include <nanogui/button.h>
......@@ -34,6 +33,9 @@ MediaPanel::MediaPanel(ftl::gui::Screen *screen) : nanogui::Window(screen, ""),
if (cam) cam->showPoseWindow();
});
virtualCameraRecording_ = std::optional<ftl::gui::Camera*>();
sceneRecording_ = std::optional<ftl::Configurable*>();
auto recordbutton = new PopupButton(this, "", ENTYPO_ICON_CONTROLLER_RECORD);
recordbutton->setTooltip("Record");
recordbutton->setSide(Popup::Side::Right);
......@@ -49,20 +51,11 @@ MediaPanel::MediaPanel(ftl::gui::Screen *screen) : nanogui::Window(screen, ""),
});
itembutton = new Button(recordpopup, "Virtual camera recording (.ftl)");
itembutton->setCallback([this,recordbutton]() {
std::cout << "Toggling video recording in itembutton callback." << '\n';
screen_->activeCamera()->toggleVideoRecording();
recordbutton->setCallback([this,recordbutton]() {
std::cout << "Toggling video recording in recordbutton callback." << '\n';
screen_->activeCamera()->toggleVideoRecording();
recordbutton->setCallback([]() {});
recordbutton->setTextColor(nanogui::Color(1.0f,1.0f,1.0f,1.0f));
// Prevents the popup from being opened, though it is shown while the button
// is being pressed.
recordbutton->setPushed(false);
});
auto activeCamera = screen_->activeCamera();
activeCamera->toggleVideoRecording();
recordbutton->setTextColor(nanogui::Color(1.0f,0.1f,0.1f,1.0f));
recordbutton->setPushed(false);
virtualCameraRecording_ = std::optional<ftl::gui::Camera*>(activeCamera);
});
itembutton = new Button(recordpopup, "3D scene recording (.ftl)");
itembutton->setCallback([this,recordbutton]() {
......@@ -74,18 +67,30 @@ MediaPanel::MediaPanel(ftl::gui::Screen *screen) : nanogui::Window(screen, ""),
ftl::Configurable *configurable = configurables[0];
configurable->set("record", true);
recordbutton->setTextColor(nanogui::Color(1.0f,0.1f,0.1f,1.0f));
recordbutton->setCallback([this,recordbutton,configurable]() {
configurable->set("record", false);
recordbutton->setCallback([]() {});
recordbutton->setTextColor(nanogui::Color(1.0f,1.0f,1.0f,1.0f));
recordbutton->setPushed(false);
});
sceneRecording_ = std::optional<ftl::Configurable*>(configurable);
}
}
recordbutton->setPushed(false);
});
itembutton = new Button(recordpopup, "Detailed recording options");
recordbutton->setCallback([this,recordbutton](){
if (virtualCameraRecording_) {
virtualCameraRecording_.value()->toggleVideoRecording();
recordbutton->setTextColor(nanogui::Color(1.0f,1.0f,1.0f,1.0f));
// Prevents the popup from being opened, though it is shown while the button
// is being pressed.
recordbutton->setPushed(false);
virtualCameraRecording_ = std::nullopt;
} else if (sceneRecording_) {
sceneRecording_.value()->set("record", false);
recordbutton->setTextColor(nanogui::Color(1.0f,1.0f,1.0f,1.0f));
recordbutton->setPushed(false);
sceneRecording_ = std::nullopt;
}
});
button = new Button(this, "", ENTYPO_ICON_CONTROLLER_STOP);
button->setCallback([this]() {
screen_->setActiveCamera(nullptr);
......
#ifndef _FTL_GUI_MEDIAPANEL_HPP_
#define _FTL_GUI_MEDIAPANEL_HPP_
#include "camera.hpp"
#include <nanogui/window.h>
namespace ftl {
......@@ -30,6 +32,15 @@ class MediaPanel : public nanogui::Window {
nanogui::PopupButton *button_channels_;
nanogui::Button *right_button_;
nanogui::Button *depth_button_;
/**
* These members indicate which type of recording is active, if any.
* They also include a pointer to an object which is used
* to end the recording. Only one of these members should have a value
* at any given time.
*/
std::optional<ftl::gui::Camera*> virtualCameraRecording_;
std::optional<ftl::Configurable*> sceneRecording_;
};
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment