Skip to content

Commit

Permalink
PR #12554 from OhadMeir: Fix exceptions when closing the viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Nir-Az authored Jan 7, 2024
2 parents e16f1bd + f811560 commit 12f5a7e
Show file tree
Hide file tree
Showing 31 changed files with 276 additions and 255 deletions.
30 changes: 15 additions & 15 deletions common/subdevice-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,23 @@ namespace rs2
return ss.str();
}

void subdevice_model::populate_options(std::map<int, option_model>& opt_container,
const std::string& opt_base_label,
subdevice_model* model,
std::shared_ptr<options> options,
bool* options_invalidated,
std::string& error_message)
void subdevice_model::populate_options( const std::string & opt_base_label,
bool * options_invalidated,
std::string & error_message )
{
for (auto&& i : options->get_supported_options())
for (auto&& i : s->get_supported_options())
{
auto opt = static_cast<rs2_option>(i);

opt_container[opt] = create_option_model(opt, opt_base_label, model, options, options_invalidated, error_message);
options_metadata[opt] = create_option_model(opt, opt_base_label, this, s, options_invalidated, error_message);
try
{
model->s->on_options_changed( [model]( const options_list & list )
s->on_options_changed( [this]( const options_list & list )
{
for( auto opt_id : list )
{
auto it = model->options_metadata.find( opt_id );
if( it != model->options_metadata.end() )
auto it = options_metadata.find( opt_id );
if( it != options_metadata.end() && ! _destructing ) // Callback runs in different context, check options_metadata still valid
{
it->second.value = it->second.endpoint->get_option( opt_id );
}
Expand All @@ -97,8 +94,8 @@ namespace rs2
}
catch( const std::exception & e )
{
if( model->viewer.not_model )
model->viewer.not_model->add_log( e.what(), RS2_LOG_SEVERITY_WARN );
if( viewer.not_model )
viewer.not_model->add_log( e.what(), RS2_LOG_SEVERITY_WARN );
}
}
}
Expand Down Expand Up @@ -150,7 +147,8 @@ namespace rs2
yuy2rgb(std::make_shared<rs2::gl::yuy_decoder>()),
y411(std::make_shared<rs2::gl::y411_decoder>()),
viewer(viewer),
detected_objects(device_detected_objects)
detected_objects(device_detected_objects),
_destructing( false )
{
supported_options = s->get_supported_options();
restore_processing_block("colorizer", depth_colorizer);
Expand Down Expand Up @@ -484,12 +482,14 @@ namespace rs2
{
error_message = error_to_string(e);
}
populate_options(options_metadata, ss.str().c_str(), this, s, &_options_invalidated, error_message);
populate_options(ss.str().c_str(), &_options_invalidated, error_message);

}

subdevice_model::~subdevice_model()
{
_destructing = true;
s->on_options_changed( []( const options_list & list ) {} );
}

void subdevice_model::sort_resolutions(std::vector<std::pair<int, int>>& resolutions) const
Expand Down
8 changes: 2 additions & 6 deletions common/subdevice-model.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ namespace rs2
class subdevice_model
{
public:
static void populate_options(std::map<int, option_model>& opt_container,
const std::string& opt_base_label,
subdevice_model* model,
std::shared_ptr<options> options,
bool* options_invalidated,
std::string& error_message);
void populate_options( const std::string & opt_base_label, bool * options_invalidated, std::string & error_message );

subdevice_model(device& dev, std::shared_ptr<sensor> s, std::shared_ptr< atomic_objects_in_frame > objects, std::string& error_message, viewer_model& viewer, bool new_device_connected = true);
~subdevice_model();
Expand Down Expand Up @@ -231,5 +226,6 @@ namespace rs2

const float SHORT_RANGE_MIN_DISTANCE = 0.05f; // 5 cm
const float SHORT_RANGE_MAX_DISTANCE = 4.0f; // 4 meters
std::atomic_bool _destructing;
};
}
6 changes: 3 additions & 3 deletions include/librealsense2/h/rs_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ extern "C" {
RS2_OPTION_ASIC_TEMPERATURE, /**< Current Asic Temperature */
RS2_OPTION_ERROR_POLLING_ENABLED, /**< disable error handling */
RS2_OPTION_PROJECTOR_TEMPERATURE, /**< Current Projector Temperature */
RS2_OPTION_OUTPUT_TRIGGER_ENABLED, /**< Enable / disable trigger to be outputed from the camera to any external device on every depth frame */
RS2_OPTION_OUTPUT_TRIGGER_ENABLED, /**< Enable / disable trigger to be outputted from the camera to any external device on every depth frame */
RS2_OPTION_MOTION_MODULE_TEMPERATURE, /**< Current Motion-Module Temperature */
RS2_OPTION_DEPTH_UNITS, /**< Number of meters represented by a single depth unit */
RS2_OPTION_ENABLE_MOTION_CORRECTION, /**< Enable/Disable automatic correction of the motion data */
RS2_OPTION_AUTO_EXPOSURE_PRIORITY, /**< Allows sensor to dynamically ajust the frame rate depending on lighting conditions */
RS2_OPTION_AUTO_EXPOSURE_PRIORITY, /**< Allows sensor to dynamically adjust the frame rate depending on lighting conditions */
RS2_OPTION_COLOR_SCHEME, /**< Color scheme for data visualization */
RS2_OPTION_HISTOGRAM_EQUALIZATION_ENABLED, /**< Perform histogram equalization post-processing on the depth data */
RS2_OPTION_MIN_DISTANCE, /**< Minimal distance to the target */
Expand All @@ -62,7 +62,7 @@ extern "C" {
RS2_OPTION_FILTER_SMOOTH_DELTA, /**< 2D-filter range/validity threshold*/
RS2_OPTION_HOLES_FILL, /**< Enhance depth data post-processing with holes filling where appropriate*/
RS2_OPTION_STEREO_BASELINE, /**< The distance in mm between the first and the second imagers in stereo-based depth cameras*/
RS2_OPTION_AUTO_EXPOSURE_CONVERGE_STEP, /**< Allows dynamically ajust the converge step value of the target exposure in Auto-Exposure algorithm*/
RS2_OPTION_AUTO_EXPOSURE_CONVERGE_STEP, /**< Allows dynamically adjust the converge step value of the target exposure in Auto-Exposure algorithm*/
RS2_OPTION_INTER_CAM_SYNC_MODE, /**< Impose Inter-camera HW synchronization mode. Applicable for D400/L500/Rolling Shutter SKUs */
RS2_OPTION_STREAM_FILTER, /**< Select a stream to process */
RS2_OPTION_STREAM_FORMAT_FILTER, /**< Select a stream format to process */
Expand Down
8 changes: 1 addition & 7 deletions src/ds/d400/d400-active.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ namespace librealsense
//PROJECTOR TEMPERATURE OPTION
auto pid = this->_pid;
auto& depth_ep = get_depth_sensor();
auto &raw_depth_ep = get_raw_depth_sensor();

if( pid == ds::RS457_PID )
{
Expand All @@ -44,13 +43,8 @@ namespace librealsense
}
else
{
auto uvc_s = std::dynamic_pointer_cast< uvc_sensor >( raw_depth_ep.shared_from_this() );
if( ! uvc_s )
throw std::runtime_error( "Sensor base is not a uvc sensor" );

depth_ep.register_option( RS2_OPTION_PROJECTOR_TEMPERATURE,
std::make_shared< asic_and_projector_temperature_options >(
std::move( uvc_s ),
std::make_shared< asic_and_projector_temperature_options >( get_raw_depth_sensor(),
RS2_OPTION_PROJECTOR_TEMPERATURE ) );
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/ds/d400/d400-color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace librealsense
void d400_color::init()
{
auto& color_ep = get_color_sensor();
auto& raw_color_ep = get_raw_color_sensor();
auto raw_color_ep = get_raw_color_sensor();

_ds_color_common = std::make_shared<ds_color_common>(raw_color_ep, color_ep, _fw_version, _hw_monitor, this);

Expand All @@ -151,7 +151,6 @@ namespace librealsense
void d400_color::register_options()
{
auto& color_ep = get_color_sensor();
auto& raw_color_ep = get_raw_color_sensor();

if (!val_in_range(_pid, { ds::RS457_PID }))
{
Expand Down Expand Up @@ -222,7 +221,7 @@ namespace librealsense
// attributes of md_capture_stats
auto& color_ep = get_color_sensor();
// attributes of md_rgb_control
auto& raw_color_ep = get_raw_color_sensor();
auto raw_color_ep = get_raw_color_sensor();

if (_pid != ds::RS457_PID)
{
Expand All @@ -231,7 +230,7 @@ namespace librealsense
}
else
{
auto uvc_dev = raw_color_ep.get_uvc_device();
auto uvc_dev = raw_color_ep->get_uvc_device();
if (uvc_dev->is_platform_jetson())
{
// Work-around for discrepancy between the RGB YUYV descriptor and the parser . Use UYUV parser instead
Expand Down
6 changes: 3 additions & 3 deletions src/ds/d400/d400-color.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ namespace librealsense
return dynamic_cast<synthetic_sensor&>(get_sensor(_color_device_idx));
}

uvc_sensor& get_raw_color_sensor()
std::shared_ptr< uvc_sensor > get_raw_color_sensor()
{
synthetic_sensor& color_sensor = get_color_sensor();
return dynamic_cast<uvc_sensor&>(*color_sensor.get_raw_sensor());
synthetic_sensor & color_sensor = get_color_sensor();
return std::dynamic_pointer_cast< uvc_sensor >( color_sensor.get_raw_sensor() );
}

protected:
Expand Down
Loading

0 comments on commit 12f5a7e

Please sign in to comment.