Cleanup: use ScopeGuard.
authorCarl Hetherington <cth@carlh.net>
Sun, 5 Feb 2023 12:50:26 +0000 (13:50 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 5 Feb 2023 12:50:26 +0000 (13:50 +0100)
src/wx/timeline.cc

index 2a8555e7ce0b3fd8abcedd14dc369e2c7e43712d..604a00f39cd60ed482719c789af534c11bc2aadc 100644 (file)
@@ -35,6 +35,7 @@
 #include "lib/film.h"
 #include "lib/image_content.h"
 #include "lib/playlist.h"
+#include "lib/scope_guard.h"
 #include "lib/text_content.h"
 #include "lib/timer.h"
 #include "lib/video_content.h"
@@ -155,13 +156,13 @@ Timeline::paint_labels ()
                return;
        }
 
+       ScopeGuard sg = [gc]() { delete gc; };
+
        int vsx, vsy;
        _labels_canvas->GetViewStart (&vsx, &vsy);
        gc->Translate (-vsx * _x_scroll_rate, -vsy * _y_scroll_rate + tracks_y_offset());
 
        _labels_view->paint (gc, {});
-
-       delete gc;
 }
 
 
@@ -176,6 +177,8 @@ Timeline::paint_main ()
                return;
        }
 
+       ScopeGuard sg = [gc]() { delete gc; };
+
        int vsx, vsy;
        _main_canvas->GetViewStart (&vsx, &vsy);
        gc->Translate (-vsx * _x_scroll_rate, -vsy * _y_scroll_rate);
@@ -225,8 +228,6 @@ Timeline::paint_main ()
        path.MoveToPoint (ph, 0);
        path.AddLineToPoint (ph, pixels_per_track() * _tracks + 32);
        gc->StrokePath (path);
-
-       delete gc;
 }