@@ -3234,9 +3234,8 @@ const rs2_raw_data_buffer* rs2_run_tare_calibration_cpp(rs2_device* device, floa
32343234
32353235 auto auto_calib = VALIDATE_INTERFACE (device->device , librealsense::auto_calibrated_interface);
32363236
3237- std::vector<uint8_t > buffer;
32383237 std::string json ((char *)json_content, (char *)json_content + content_size);
3239- buffer = auto_calib->run_tare_calibration (timeout_ms, ground_truth_mm, json, health, callback_ptr);
3238+ std::vector< uint8_t > buffer = auto_calib->run_tare_calibration ( timeout_ms, ground_truth_mm, json, callback_ptr );
32403239
32413240 return new rs2_raw_data_buffer{ buffer };
32423241}
@@ -3779,6 +3778,12 @@ NOEXCEPT_RETURN(, to_pixel)
37793778const rs2_raw_data_buffer* rs2_run_focal_length_calibration_cpp(rs2_device* device, rs2_frame_queue* left, rs2_frame_queue* right, float target_w, float target_h,
37803779 int adjust_both_sides, float * ratio, float * angle, rs2_update_progress_callback * progress_callback, rs2_error** error) BEGIN_API_CALL
37813780{
3781+ // Take ownership of the callback ASAP or else memory leaks could result if we throw! (the caller usually does a
3782+ // 'new' when calling us)
3783+ update_progress_callback_ptr callback_ptr;
3784+ if ( progress_callback )
3785+ callback_ptr.reset ( progress_callback, []( rs2_update_progress_callback * p ) { p->release (); } );
3786+
37823787 VALIDATE_NOT_NULL (device);
37833788 VALIDATE_NOT_NULL (left);
37843789 VALIDATE_NOT_NULL (right);
@@ -3791,11 +3796,8 @@ const rs2_raw_data_buffer* rs2_run_focal_length_calibration_cpp(rs2_device* devi
37913796 VALIDATE_RANGE (adjust_both_sides, 0 , 1 );
37923797
37933798 auto auto_calib = VALIDATE_INTERFACE (device->device , librealsense::auto_calibrated_interface);
3794- std::vector<uint8_t > buffer;
3795- if (progress_callback == nullptr )
3796- buffer = auto_calib->run_focal_length_calibration (left, right, target_w, target_h, adjust_both_sides, ratio, angle, nullptr );
3797- else
3798- buffer = auto_calib->run_focal_length_calibration (left, right, target_w, target_h, adjust_both_sides, ratio, angle, { progress_callback, [](rs2_update_progress_callback* p) { p->release (); } });
3799+ std::vector< uint8_t > buffer =
3800+ auto_calib->run_focal_length_calibration ( left, right, target_w, target_h, adjust_both_sides, ratio, angle, callback_ptr );
37993801
38003802 return new rs2_raw_data_buffer{ buffer };
38013803}
@@ -3832,6 +3834,12 @@ HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device, left, right, ratio, angle)
38323834const rs2_raw_data_buffer* rs2_run_uv_map_calibration_cpp(rs2_device* device, rs2_frame_queue* left, rs2_frame_queue* color, rs2_frame_queue* depth, int py_px_only,
38333835 float * health, int health_size, rs2_update_progress_callback* progress_callback, rs2_error** error) BEGIN_API_CALL
38343836{
3837+ // Take ownership of the callback ASAP or else memory leaks could result if we throw! (the caller usually does a
3838+ // 'new' when calling us)
3839+ update_progress_callback_ptr callback_ptr;
3840+ if ( progress_callback )
3841+ callback_ptr.reset ( progress_callback, []( rs2_update_progress_callback * p ) { p->release (); } );
3842+
38353843 VALIDATE_NOT_NULL (device);
38363844 VALIDATE_NOT_NULL (left);
38373845 VALIDATE_NOT_NULL (color);
@@ -3844,11 +3852,8 @@ const rs2_raw_data_buffer* rs2_run_uv_map_calibration_cpp(rs2_device* device, rs
38443852 VALIDATE_RANGE (py_px_only, 0 , 1 );
38453853
38463854 auto auto_calib = VALIDATE_INTERFACE (device->device , librealsense::auto_calibrated_interface);
3847- std::vector<uint8_t > buffer;
3848- if (progress_callback == nullptr )
3849- buffer = auto_calib->run_uv_map_calibration (left, color, depth, py_px_only, health, health_size, nullptr );
3850- else
3851- buffer = auto_calib->run_uv_map_calibration (left, color, depth, py_px_only, health, health_size, { progress_callback, [](rs2_update_progress_callback* p) { p->release (); } });
3855+ std::vector< uint8_t > buffer
3856+ = auto_calib->run_uv_map_calibration ( left, color, depth, py_px_only, health, health_size, callback_ptr );
38523857
38533858 return new rs2_raw_data_buffer{ buffer };
38543859}
@@ -3886,20 +3891,20 @@ HANDLE_EXCEPTIONS_AND_RETURN(nullptr, device, left, color, depth, health)
38863891float rs2_calculate_target_z_cpp(rs2_device* device, rs2_frame_queue* queue, float target_width, float target_height,
38873892 rs2_update_progress_callback* progress_callback, rs2_error** error) BEGIN_API_CALL
38883893{
3894+ // Take ownership of the callback ASAP or else memory leaks could result if we throw! (the caller usually does a
3895+ // 'new' when calling us)
3896+ update_progress_callback_ptr callback_ptr;
3897+ if ( progress_callback )
3898+ callback_ptr.reset ( progress_callback, []( rs2_update_progress_callback * p ) { p->release (); } );
3899+
38893900 VALIDATE_NOT_NULL (device);
38903901 VALIDATE_NOT_NULL (queue);
38913902 VALIDATE_GT (target_width, 0 .f );
38923903 VALIDATE_GT (target_height, 0 .f );
38933904 VALIDATE_GT (rs2_frame_queue_size (queue, error), 0 );
38943905
38953906 auto auto_calib = VALIDATE_INTERFACE (device->device , librealsense::auto_calibrated_interface);
3896-
3897- if (progress_callback == NULL )
3898- return auto_calib->calculate_target_z (queue, target_width, target_height, nullptr );
3899- else
3900- {
3901- return auto_calib->calculate_target_z (queue, target_width, target_height, { progress_callback, [](rs2_update_progress_callback* p) { p->release (); } });
3902- }
3907+ return auto_calib->calculate_target_z ( queue, target_width, target_height, callback_ptr );
39033908}
39043909HANDLE_EXCEPTIONS_AND_RETURN (-1 .f, device, queue, target_width, target_height)
39053910
0 commit comments