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

Bugfix in pure python aui: Early return from method if underlying C++ object has been destroyed #2473

Closed

Conversation

jmoraleda
Copy link
Contributor

When the application is in the process of changing the aui layout programmatically (e.g. by loading a perspective) it is possible to click on a notebook pane that is in the process of being destroyed. This results in the error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/dist-packages/wx/core.py", line 2346, in Notify
    self.notify()
  File "/usr/local/lib/python3.11/dist-packages/wx/core.py", line 3552, in Notify
    self.result = self.callable(*self.args, **self.kwargs)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/wx/lib/agw/aui/auibook.py", line 2504, in ShowTooltip
    wnd = self.GetPointedToTab()
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/wx/lib/agw/aui/auibook.py", line 2462, in GetPointedToTab
    client_pt = self.ScreenToClient(screen_pt)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: wrapped C/C++ object of type AuiTabCtrl has been deleted

This PR fixes the bug in the conventional way: By testing for self truthiness. and returning early without invoking any member methods if it is False.

@jmoraleda
Copy link
Contributor Author

jmoraleda commented Nov 9, 2023

I think we should wait before merging this PR. As I do intensive testing I am finding that the pure python AUI seems to have several race conditions leading to similar errors. I am going to try to produce a comprehensive solution and I will update this PR when I have something that I think is stable.

These are two of the errors, but there are more

2023-11-08 19:21:00 ERROR [wx.lib.agw.aui.framemanager]: An unexpected error occurred in wx.lib.agw.aui.framemanager.
Traceback (most recent call last):
  File "C:\Program Files\Prog 1.0\WPy64-31120b3\python-3.11.2.amd64\Lib\site-packages\wx\lib\agw\aui\framemanager.py", line 8967, in OnMotion
    self.OnMotion_Resize(event)
  File "C:\Program Files\Prog 1.0\WPy64-31120b3\python-3.11.2.amd64\Lib\site-packages\wx\lib\agw\aui\framemanager.py", line 9180, in OnMotion_Resize
    self._currentDragItem = self._uiparts.index(self._action_part)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: None is not in list
RuntimeError: wrapped C/C++ object of type AuiNotebook has been deleted
2023-11-08 10:43:28 ERROR [wx.lib.agw.aui.framemanager]: An unexpected error occurred in wx.lib.agw.aui.framemanager.
Traceback (most recent call last):
  File "C:\Program Files\Prog 1.0\WPy64-31120b3\python-3.11.2.amd64\Lib\site-packages\wx\lib\agw\aui\framemanager.py", line 8443, in OnRender
    art.DrawCaption(dc, self._frame, part.pane.caption, part.rect, part.pane)
  File "C:\Program Files\Prog 1.0\WPy64-31120b3\python-3.11.2.amd64\Lib\site-packages\wx\lib\agw\aui\dockart.py", line 593, in DrawCaption
    btns = pane.CountButtons()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Prog 1.0\WPy64-31120b3\python-3.11.2.amd64\Lib\site-packages\wx\lib\agw\aui\framemanager.py", line 1715, in CountButtons
    if isinstance(wx.GetTopLevelParent(self.window), AuiFloatingFrame):
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In retrospect, I realize I should have just opened an issue rather than a PR. But I am cautiously optimistic that I'll be able to turn this into a bona fide PR.

@jmoraleda
Copy link
Contributor Author

jmoraleda commented Nov 15, 2023

I am going to close this PR until I have done sufficient testing an the patch set to believe that the assorted "wrapped C/C++ object has been deleted" and related race conditions have been eradicated, or at least are very significantly reduced from the current level.

@jmoraleda jmoraleda closed this Nov 15, 2023
jmoraleda referenced this pull request Feb 17, 2024
… reduces flicker, reduces number of code lines by removing platform exception.
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

1 participant