Skip to content

Commit

Permalink
Add a command line switch to enable debugging options like running th…
Browse files Browse the repository at this point in the history
…e GC more frequently

Bug: 2047920
  • Loading branch information
cameronwhite committed Jan 5, 2024
1 parent 262305a commit 13ebeda
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions Pinta/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,24 @@ public static int Main (string[] args)
name: "files",
description: Translations.GetString ("Files to open"));

var debug_option = new Option<bool> (
name: "--debug",
description: Translations.GetString ("Enable additional logging or behavior changes for debugging"));

// Note the implicit '--version' argument uses the InformationalVersion from the assembly.
var root_command = new RootCommand (Translations.GetString ("Pinta"));
root_command.AddOption (threads_option);
root_command.AddArgument (files_arg);
root_command.AddOption (debug_option);

root_command.SetHandler ((threads, files) => {
OpenMainWindow (threads, files);
}, threads_option, files_arg);
root_command.SetHandler ((threads, files, debug) => {
OpenMainWindow (threads, files, debug);
}, threads_option, files_arg, debug_option);

return root_command.Invoke (args);
}

private static void OpenMainWindow (int threads, IEnumerable<string> files)
private static void OpenMainWindow (int threads, IEnumerable<string> files, bool debug)
{
GLib.UnhandledException.SetHandler (OnUnhandledException);

Expand All @@ -99,13 +104,13 @@ private static void OpenMainWindow (int threads, IEnumerable<string> files)
// For debugging, run the garbage collector much more frequently.
// This can be useful to detect certain memory management issues in the GTK bindings.
#if false
GLib.Functions.TimeoutAddFull (0, 100, (_) => {
GC.Collect ();
GC.WaitForPendingFinalizers ();
return true;
});
#endif
if (debug) {
GLib.Functions.TimeoutAdd (0, 100, () => {
GC.Collect ();
GC.WaitForPendingFinalizers ();
return true;
});
}
};

// Run with a SynchronizationContext to integrate async methods with GLib.MainLoop.
Expand Down

0 comments on commit 13ebeda

Please sign in to comment.