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

Segmentation fault debugging aggdraw.Pen #58

Open
eduardomezencio opened this issue May 20, 2019 · 5 comments
Open

Segmentation fault debugging aggdraw.Pen #58

eduardomezencio opened this issue May 20, 2019 · 5 comments

Comments

@eduardomezencio
Copy link

eduardomezencio commented May 20, 2019

Using aggdraw 1.3.10 in arch linux with cpython 3.7, I get a segmentation fault every time my debugger tries to inspect an aggdraw.Pen object. I tried it debugging with pudb3, with vscode python extension and with pycharm. Here's a minimal code:

from PIL import Image
import aggdraw


def main():
    image = create_image()
    image.show()


def create_image():
    image = Image.new('RGBA', (1024, 1024))
    draw = aggdraw.Draw(image)
    pen = aggdraw.Pen('red', 20)
    draw.line((0, 0, 100, 100), pen)
    draw.flush()
    return image


if __name__ == '__main__':
    main()

Put a breakpoint in the line draw.line((0, 0, 100, 100), pen) and try to inspect pen in your debugger to see if you can reproduce it.

I checked some issues here, and found #22 that also mentions segmentation faults related to Pen, but it seems to be a different issue, and already solved.

And less important, but just to mention it, I don't really want to inspect this object. It's just that debuggers usually show all local variables when you break, so every time I put a breakpoint with a local Pen object, my session crashes and this is the real problem

@djhoese
Copy link
Member

djhoese commented May 20, 2019

How did you install aggdraw? PyPI via pip or from conda-forge via conda? I'm guessing it was a wheel? Can you try installing directly from the source code and see if this re-building of the C/C++ code fixes things?

@eduardomezencio
Copy link
Author

Yes, it was installed from PyPI via pip. I have just uninstalled it, cloned this repository and compiled then installed it, but the same segmentation fault still happens.

@djhoese
Copy link
Member

djhoese commented May 20, 2019

To clarify, you don't get a segmentation fault with normal operations? You only get it when using the debugger?

If that is true, my guess is that your debugger is trying to use the __repr__ or __str__ or some other dunder-method that isn't implemented on the aggdraw objects. Given how low-level they are, they may not implement every interface that your debugger wants to use and your debugger isn't smart enough to be ok with that. If this is the problem, this won't be fixed any time soon until we migrate to using cython where it would be easier for us to define these objects as full python objects.

@eduardomezencio
Copy link
Author

Yes, there is no problem in normal program execution. I tried, during normal execution, printing str, repr, hash and dir of the object to see if anything fails, but they all work with no problems.

@djhoese
Copy link
Member

djhoese commented May 20, 2019

So good news (?) is that I can reproduce this in pycharm. If I run it with the debugger enabled but without the breakpoint then it succeeds. If I use pdb import pdb; pdb.set_trace() the line before the specified breakpoint and print out pen it still works fine. I'm not sure there is much I can do about this. I would normally run a command with strace to get some kind of idea what is causing the segfault but I'm not sure how I can do that with a visual debugger.

A fix for this may have to wait until a large rewrite of aggdraw happens where these objects are more fully realized python objects.

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

No branches or pull requests

2 participants