From 3857b8b178d94873a6ffc6f51cdb4c241fd54f90 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 19 Jul 2013 13:54:18 +0100 Subject: [PATCH] Fix unnecessary shared_ptr; add missing checked_set()s. --- src/wx/timecode.cc | 8 ++++---- src/wx/timeline.cc | 24 +++++++++++------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/wx/timecode.cc b/src/wx/timecode.cc index 82c27c5b5..36a01f90d 100644 --- a/src/wx/timecode.cc +++ b/src/wx/timecode.cc @@ -84,10 +84,10 @@ Timecode::set (Time t, int fps) t -= s * TIME_HZ; int const f = t * fps / TIME_HZ; - _hours->SetValue (wxString::Format (wxT ("%d"), h)); - _minutes->SetValue (wxString::Format (wxT ("%d"), m)); - _seconds->SetValue (wxString::Format (wxT ("%d"), s)); - _frames->SetValue (wxString::Format (wxT ("%d"), f)); + checked_set (_hours, lexical_cast (h)); + checked_set (_minutes, lexical_cast (m)); + checked_set (_seconds, lexical_cast (s)); + checked_set (_frames, lexical_cast (f)); } Time diff --git a/src/wx/timeline.cc b/src/wx/timeline.cc index f9205fc5d..7d0ce660c 100644 --- a/src/wx/timeline.cc +++ b/src/wx/timeline.cc @@ -87,14 +87,15 @@ public: dcpomatic::Rect bbox () const { shared_ptr film = _timeline.film (); - if (!film) { + shared_ptr content = _content.lock (); + if (!film || !content) { return dcpomatic::Rect (); } return dcpomatic::Rect ( - time_x (_content->start ()) - 8, + time_x (content->start ()) - 8, y_pos (_track) - 8, - _content->length () * _timeline.pixels_per_time_unit() + 16, + content->length () * _timeline.pixels_per_time_unit() + 16, _timeline.track_height() + 16 ); } @@ -109,7 +110,7 @@ public: } shared_ptr content () const { - return _content; + return _content.lock (); } void set_track (int t) { @@ -128,12 +129,13 @@ private: void do_paint (wxGraphicsContext* gc) { shared_ptr film = _timeline.film (); - if (!film) { + shared_ptr cont = content (); + if (!film || !cont) { return; } - Time const start = _content->start (); - Time const len = _content->length (); + Time const start = cont->start (); + Time const len = cont->length (); wxColour selected (colour().Red() / 2, colour().Green() / 2, colour().Blue() / 2); @@ -155,7 +157,7 @@ private: gc->StrokePath (path); gc->FillPath (path); - wxString name = wxString::Format (wxT ("%s [%s]"), std_to_wx (_content->file().filename().string()).data(), type().data()); + wxString name = wxString::Format (wxT ("%s [%s]"), std_to_wx (cont->file().filename().string()).data(), type().data()); wxDouble name_width; wxDouble name_height; wxDouble name_descent; @@ -179,11 +181,7 @@ private: } } - /* This must be a shared_ptr, not a weak_ptr, as in the looped case this - will be the only remaining pointer to the looped content that we get - from the playlist. - */ - boost::shared_ptr _content; + boost::weak_ptr _content; int _track; bool _selected; -- 2.30.2