Fix crash from previous commit; clear viewer image when its size changes (#12).
[dcpomatic.git] / src / wx / film_viewer.cc
index 3e0e678cf217ddf84d3e264462cd00913e1a41fc..73ed13e50aa0d9c7ba9281d636c85a4785822cb0 100644 (file)
@@ -55,6 +55,7 @@ FilmViewer::FilmViewer (shared_ptr<Film> f, wxWindow* p)
        , _out_height (0)
        , _panel_width (0)
        , _panel_height (0)
+       , _clear_required (false)
 {
        _panel->SetDoubleBuffered (true);
 #if wxMAJOR_VERSION == 2 && wxMINOR_VERSION >= 9       
@@ -189,6 +190,11 @@ FilmViewer::paint_panel (wxPaintEvent& ev)
 {
        wxPaintDC dc (_panel);
 
+       if (_clear_required) {
+               dc.Clear ();
+               _clear_required = false;
+       }
+
        if (!_display_frame || !_film || !_out_width || !_out_height) {
                dc.Clear ();
                return;
@@ -251,9 +257,18 @@ FilmViewer::raw_to_display ()
                return;
        }
 
+       Size old_size;
+       if (_display_frame) {
+               old_size = _display_frame->size();
+       }
+
        /* Get a compacted image as we have to feed it to wxWidgets */
        _display_frame = _raw_frame->scale_and_convert_to_rgb (Size (_out_width, _out_height), 0, _film->scaler(), false);
 
+       if (old_size != _display_frame->size()) {
+               _clear_required = true;
+       }
+
        if (_raw_sub) {
                Rect tx = subtitle_transformed_area (
                        float (_out_width) / _film->size().width,