Skip to content

[Bug]: Unhandled _get_renderer.Done exception in wxagg backend #21798

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

Closed
epmojo opened this issue Nov 29, 2021 · 1 comment · Fixed by #22572
Closed

[Bug]: Unhandled _get_renderer.Done exception in wxagg backend #21798

epmojo opened this issue Nov 29, 2021 · 1 comment · Fixed by #22572
Labels
Milestone

Comments

@epmojo
Copy link

epmojo commented Nov 29, 2021

Bug summary

An unhandled Done exception can occur in the wxagg backend. In the example below, the code can continue running, although some additional action is required to draw the figure as the plot is initially blank.

Code for reproduction

from matplotlib.backends.backend_wxagg import FigureFrameWxAgg
import matplotlib.figure as mfigure
import wx


def main():
    app = wx.App()

    figure = mfigure.Figure()
    ax = figure.subplots()
    ax.plot((0, 1))
    frame = FigureFrameWxAgg(0, figure)
    frame.Show()
    figure.tight_layout() # triggers error in wxpython event handler

    app.MainLoop()

if __name__ == '__main__':
    main()

Actual outcome

Traceback (most recent call last):
File "C:\Python39-64\lib\site-packages\matplotlib\backends\backend_wx.py", line 653, in _onPaint
self.draw(drawDC=drawDC)
File "C:\Python39-64\lib\site-packages\matplotlib\backends\backend_wxagg.py", line 29, in draw
FigureCanvasAgg.draw(self)
File "C:\Python39-64\lib\site-packages\matplotlib\backends\backend_agg.py", line 436, in draw
self.figure.draw(self.renderer)
File "C:\Python39-64\lib\site-packages\matplotlib\backend_bases.py", line 1533, in _draw
def _draw(renderer): raise Done(renderer)
matplotlib.backend_bases._get_renderer..Done: <matplotlib.backends.backend_agg.RendererAgg object at 0x000002022EF5D250>

Expected outcome

The exception is caught somewhere or does not occur.

Additional information

I believe this only occurs in matplotlib version 3.5.0. This is with wxPython version 4.1.1.

It looks like figure.tight_layout() calls _get_renderer() which, in this example, subsequently calls _FigureCanvasWxBase.set_cursor(). Changing the self.Update() call in set_cursor() to self.Refresh() will allow the cbook._setattr_cm from _get_renderer() to exit prior to the paint event and avoid the exception. However, I'm not sure what the intended behavior is. Should a function call to get the renderer trigger a cursor change?

Operating system

Windows 10, 64-bit

Matplotlib Version

3.5.0

Matplotlib Backend

wxagg

Python version

3.9.9

Jupyter version

N/A

Installation

pip

@jklymak jklymak added this to the v3.5.1 milestone Nov 29, 2021
@QuLogic QuLogic modified the milestones: v3.5.1, v3.5.2 Dec 10, 2021
@anntzer
Copy link
Contributor

anntzer commented Jan 6, 2022

I can confirm the issue and your interpretation. The bug only occurs on Windows, which may be why the bug was previously missed. Switch Update() to Refresh() also seems reasonable.

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

Successfully merging a pull request may close this issue.

4 participants