-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX macos: Use the agg buffer_rgba rather than private attribute #28964
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
Conversation
The _renderer attribute has changed with the pybind11 update and we aren't able to access it as a buffer anymore. We can use the buffer_rgba method to get the direct memoryview of the buffer instead.
(Seems close enough to #18993 which did the same for tk.) |
@@ -1236,7 +1236,7 @@ -(void)drawRect:(NSRect)rect | |||
CGContextRef cr = [[NSGraphicsContext currentContext] CGContext]; | |||
|
|||
if (!(renderer = PyObject_CallMethod(canvas, "get_renderer", "")) | |||
|| !(renderer_buffer = PyObject_GetAttrString(renderer, "_renderer"))) { | |||
|| !(renderer_buffer = PyObject_CallMethod(renderer, "buffer_rgba", ""))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the implementation of RendererAgg
, it's:
def buffer_rgba(self):
return memoryview(self._renderer)
so this looks like a reasonable change. I'm a bit uncertain why PyObject_GetBuffer
is not sufficient with pybind11's version of buffers, but we can investigate that for later.
So in the original implementation: matplotlib/src/_backend_agg_wrapper.cpp Lines 415 to 437 in ac268ec
we always filled out all fields regardless of flags . The macosx backend asks for a contiguous read-only buffer:Line 1167 in fbf1611
which is an alias for PyBUF_ND .
In pybind11 however, it does attempt to respect Line 1172 in fbf1611
I've opened pybind/pybind11#5407 to fix pybind11. |
PR summary
I'm getting
copy_agg_buffer failed
and no plots to show up with the macosx backend.The
_renderer
attribute has changed with the pybind11 update and we aren't able to access it as a buffer anymore. We can use the buffer_rgba method to get the direct memoryview of the buffer instead.git bisect shows me it is this commit: 96dd843
ping @QuLogic