Skip to content

Commit 4a576d3

Browse files
authored
Merge pull request #697 from dorodnic/fixes
Fixing crashes in the viewer when switching between cameras
2 parents 58518b3 + 3317adc commit 4a576d3

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

src/ds5/ds5-color.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,16 @@ namespace librealsense
145145

146146
auto video = dynamic_cast<video_stream_profile_interface*>(p.get());
147147
auto profile = to_profile(p.get());
148-
video->set_intrinsics([profile, this]()
148+
149+
std::weak_ptr<ds5_color_sensor> wp =
150+
std::dynamic_pointer_cast<ds5_color_sensor>(this->shared_from_this());
151+
video->set_intrinsics([profile, wp]()
149152
{
150-
return get_intrinsics(profile);
153+
auto sp = wp.lock();
154+
if (sp)
155+
return sp->get_intrinsics(profile);
156+
else
157+
return rs2_intrinsics{};
151158
});
152159

153160
if (video->get_width() == 640 && video->get_height() == 480 && video->get_format() == RS2_FORMAT_RGB8 && video->get_framerate() == 30)

src/ds5/ds5-device.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,15 @@ namespace librealsense
129129
if (p->get_format() != RS2_FORMAT_Y16) // Y16 format indicate unrectified images, no intrinsics are available for these
130130
{
131131
auto profile = to_profile(p.get());
132-
video->set_intrinsics([profile, this]()
132+
std::weak_ptr<ds5_depth_sensor> wp =
133+
std::dynamic_pointer_cast<ds5_depth_sensor>(this->shared_from_this());
134+
video->set_intrinsics([profile, wp]()
133135
{
134-
return get_intrinsics(profile);
136+
auto sp = wp.lock();
137+
if (sp)
138+
return sp->get_intrinsics(profile);
139+
else
140+
return rs2_intrinsics{};
135141
});
136142
}
137143
}

src/ds5/ds5-motion.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,16 @@ namespace librealsense
120120
if (video->get_width() == 640 && video->get_height() == 480 && video->get_format() == RS2_FORMAT_RAW8 && video->get_framerate() == 30)
121121
video->make_default();
122122

123-
// Register intrinsics
124123
auto profile = to_profile(p.get());
125-
video->set_intrinsics([profile, this]()
124+
std::weak_ptr<ds5_fisheye_sensor> wp =
125+
std::dynamic_pointer_cast<ds5_fisheye_sensor>(this->shared_from_this());
126+
video->set_intrinsics([profile, wp]()
126127
{
127-
return get_intrinsics(profile);
128+
auto sp = wp.lock();
129+
if (sp)
130+
return sp->get_intrinsics(profile);
131+
else
132+
return rs2_intrinsics{};
128133
});
129134
}
130135

src/ivcam/sr300.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,15 @@ namespace librealsense
233233
video->make_default();
234234

235235
auto profile = to_profile(p.get());
236-
video->set_intrinsics([profile, this]()
236+
std::weak_ptr<sr300_color_sensor> wp =
237+
std::dynamic_pointer_cast<sr300_color_sensor>(this->shared_from_this());
238+
video->set_intrinsics([profile, wp]()
237239
{
238-
return get_intrinsics(profile);
240+
auto sp = wp.lock();
241+
if (sp)
242+
return sp->get_intrinsics(profile);
243+
else
244+
return rs2_intrinsics{};
239245
});
240246
}
241247

@@ -285,9 +291,16 @@ namespace librealsense
285291
video->make_default();
286292

287293
auto profile = to_profile(p.get());
288-
video->set_intrinsics([profile, this]()
294+
std::weak_ptr<sr300_depth_sensor> wp =
295+
std::dynamic_pointer_cast<sr300_depth_sensor>(this->shared_from_this());
296+
297+
video->set_intrinsics([profile, wp]()
289298
{
290-
return get_intrinsics(profile);
299+
auto sp = wp.lock();
300+
if (sp)
301+
return sp->get_intrinsics(profile);
302+
else
303+
return rs2_intrinsics{};
291304
});
292305
}
293306

0 commit comments

Comments
 (0)