Skip to content

Commit

Permalink
Fix segfault (lambda reference capture) of VisualizerWithCustomAnimat…
Browse files Browse the repository at this point in the history
…ion::Play (#6804)

* Make ProgressBar dtor virtual.
---------
Co-authored-by: Sameer Sheorey <41028320+ssheorey@users.noreply.github.com>
  • Loading branch information
nicolaloi authored Jun 14, 2024
1 parent 0bdedd3 commit f7161f4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- Fix RANSAC early stop if no inliers in a specific iteration (PR #6789)
- Fix segmentation fault (infinite recursion) of DetectPlanarPatches if multiple points have same coordinates (PR #6794)
- Fix build with fmt v10.2.0 (#6783)
- Fix segmentation fault (lambda reference capture) of VisualizerWithCustomAnimation::Play (PR #6804)

## 0.13

Expand Down
1 change: 1 addition & 0 deletions cpp/open3d/utility/ProgressBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ProgressBar {
virtual ProgressBar &operator++();
void SetCurrentCount(size_t n);
size_t GetCurrentCount() const;
virtual ~ProgressBar() = default;

protected:
const size_t resolution_ = 40;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ void VisualizerWithCustomAnimation::Play(
is_redraw_required_ = true;
UpdateWindowTitle();
recording_file_index_ = 0;
utility::ProgressBar progress_bar(view_control.NumOfFrames(),
"Play animation: ");
auto progress_bar_ptr = std::make_shared<utility::ProgressBar>(
view_control.NumOfFrames(), "Play animation: ");
auto trajectory_ptr = std::make_shared<camera::PinholeCameraTrajectory>();
bool recording_trajectory = view_control.IsValidPinholeCameraTrajectory();
if (recording) {
Expand All @@ -94,7 +94,7 @@ void VisualizerWithCustomAnimation::Play(
RegisterAnimationCallback([this, recording, recording_depth,
close_window_when_animation_ends,
recording_trajectory, trajectory_ptr,
&progress_bar](Visualizer *vis) {
progress_bar_ptr](Visualizer *vis) {
// The lambda function captures no references to avoid dangling
// references
auto &view_control =
Expand All @@ -121,7 +121,7 @@ void VisualizerWithCustomAnimation::Play(
}
}
view_control.Step(1.0);
++progress_bar;
++(*progress_bar_ptr);
if (view_control.IsPlayingEnd(recording_file_index_)) {
view_control.SetAnimationMode(
ViewControlWithCustomAnimation::AnimationMode::FreeMode);
Expand Down

0 comments on commit f7161f4

Please sign in to comment.