Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mainwindow - Fix ‘RuntimeError: wrapped C/C++ object of type JLCPCBTo…
…ols has been deleted’ To reproduce: - Open kicad-jlcpcb-tools dialog - Close dialog - Re-open kicad-jlcpcb-tools dialog - Attempt to download the database (this causes log messages to be generated), see RuntimeError dialog pop up. Each time the mainwindow dialog is opened, init_logger() is called. init_logger() retrieves the root logger via a call to logging.getLogger(). Handlers are then attached to the root logger, one to log to stderr and one to log via the LogBoxHandler class to the wxWidgets textctrl log box at the bottom of the mainwindow dialog. Recently there was a change to use wxPython events to log messages, to fix an issue that was believed to be due to manipulation of the log output textctrl widget from the backgound thread that was downloading the database. This change removed a try/except that was discarding exceptions, as it was believed that this change fixed the cause of the exceptions by marshalling, via wx.queueEvent(), the log text to the main thread for addition to the log output textctrl widget. Root cause is that the Python instance persists for the duration of Kicad's execution. Thus calls to addHandler() to the root logger are cumulative. Each time you re-open the mainwindow the logging handlers are added. The previous handlers, which now refer to deleted instances of the mainwindow (class JLCPCBTools, see the error message in the commit subject), persist. Each subsequent call to Python's logging functions results in all of these loggers being called. Previously the try/except in each of these loggers was discarding the wxPython/wxWidgets errors but removing the try/except meant they were now unhandled. Fix the crash by calling removeHandler() in quit_dialog() so there are no old logger handlers with references to now deleted dialogs. Special thanks to Aleksandr Shvartzkop took time to look at the code and almost immediately spotted the logger addHandler() calls without corresponding removeHandler() calls. This was the first step that led to debugging the issue.
- Loading branch information