xatupal / KeeTheme

KeePass Plugin
MIT License
449 stars 36 forks source link

"Out of memory" crash when switching System theme from Dark to Light (Auto-sync enabled) #92

Closed strarsis closed 8 months ago

strarsis commented 1 year ago

When switching the system theme (here on a Windows 10 system) from dark to light, with "Auto-sync with Windows 10 theme" enabled, an application error occurs ("not enough memory").

Using "Continue" KeePass theme successfully toggles to light theme and continues running. Using "Exit", after starting KeePass again, everything works fine with new theme mode.

This error is only happening when switching system theme from Light to Dark, not from Dark to Light.

This occurs only with KeeTheme plugin installed and KeeAgent main UI window being visible (unlocked), and the KeeTheme option "Auto-sync with Windows 10 theme" enabled. This error occurs with both dark themes, "Dark Theme" and "Dark Theme Windows 11".

Manually toggling "Dark Theme [...]" does not cause the error (notably when toggling from enabled (= Dark System Theme) to disabled (= Light System Theme).

Application error details:

************** Ausnahmetext **************
System.OutOfMemoryException: Nicht genügend Arbeitsspeicher. ("Not enough memory.")
   bei System.Drawing.Graphics.FromHdcInternal(IntPtr hdc)
   bei System.Drawing.Font.ToLogFont(Object logFont)
   bei System.Drawing.Font.ToHfont()
   bei System.Windows.Forms.Control.FontHandleWrapper..ctor(Font font)
   bei System.Windows.Forms.OwnerDrawPropertyBag.get_FontHandle()
   bei System.Windows.Forms.TreeView.CustomDraw(Message& m)
   bei System.Windows.Forms.TreeView.WmNotify(Message& m)
   bei System.Windows.Forms.TreeView.WndProc(Message& m)
   bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
xatupal commented 8 months ago

Hey! Thanks for info. I've fixed a few possible memory leaks. Please let me know if the error occurs again.