Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmm crash fix #478

Merged
merged 2 commits into from
May 29, 2024
Merged

Cmm crash fix #478

merged 2 commits into from
May 29, 2024

Conversation

chmorgan
Copy link
Collaborator

No description provided.

…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.

Note that due to the try/except it is likely that this issue was latent in the plugin for months
or years, at least since the addHandler() was called without removeHandler().

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.
@KnightHill
Copy link

Installed the fix and downloaded all jclpbc parts. Everything seems to be back to normal now (kicad 8.0.2 under Manjaro). Thank you so much for fixing the issue!

@chmorgan chmorgan requested a review from Bouni May 29, 2024 13:02
@chmorgan
Copy link
Collaborator Author

@Bouni can you review and merge if this looks good? Would like to get this out and released since it's affecting most users.

@chmorgan chmorgan requested a review from whmountains May 29, 2024 13:02
@Bouni Bouni merged commit 8845133 into Bouni:main May 29, 2024
2 checks passed
@Bouni
Copy link
Owner

Bouni commented May 29, 2024

Thanks @chmorgan for digging into this.

The log function needs an overhaul anyway. I've stolen it from KiBuzzard plugin and it has sometimes strange behavior. I would really like it if we could write to a log file as well (maybe that can be enabled in the settings!?)
What do you think?

@chmorgan
Copy link
Collaborator Author

chmorgan commented May 29, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants