Skip to content

ImageObject use results in "Context leak detected, msgtracer returned -1" with loops when run as script #596

@kontur

Description

@kontur

Hello,

I have a Q&A script in which I am outputting stuff with Drawbot installed via pip.

Essentially, running the basic ImageObject sample code inside a loop, in a terminal script, results in multiple "Context leak detected, msgtracer returned -1" errors. This omits drawing images, but at times has even crashed my Mac.

The script: context-leak-debug-2.py

from drawBot import (
    image,
    fontSize,
    saveImage,
    fill,
    text,
    rect,
    size,
    ImageObject,
)


size(550, 300)

for i in range(100):
    print(i)
    # initiate a new image object
    im = ImageObject()

    # draw in the image
    # the 'with' statement will create a custom context
    # only drawing in the image object
    with im:
        # set a size for the image
        size(200, 200)
        # draw something
        fill(1, 0, 0)
        rect(0, 0, 400, 200)
        fill(1)
        fontSize(30)
        text("Hello World", (10, 10))

    # draw in the image in the main context
    image(im, (10, 50))
    # apply some filters
    im.gaussianBlur()

    # get the offset (with a blur this will be negative)
    x, y = im.offset()
    # draw in the image in the main context
    image(im, (300 + x, 50 + y))

saveImage("test.pdf")

When I run the same code without the imports in the Drawbot app I see the 1...99 traces, but never an error message (not sure if the error does not happen, or if the app hides the error message, from stderr I suppose — I think the latter). When running this in Terminal as python script I see the 1...99 traces, and eventually one or several "Context leak detected, msgtracer returned -1" — I suppose when the script hits the saveImage bit in the end, not during the loops themselves. It's somehow todo with the loop, so with range(10) I don't ever get the error, with range(1000) I see several such error message at the end. The longer the loop, the more errors, and dropped images in my actual use case.

I'm on an M1 MacBook 15.6.1 (24G90).

Attached the pip environment for my fresh install of pip install drawbot@git+https://github.com/typemytype/drawbot.git, Python 3.11.2.

requirements-debug.txt

My original use case is drawing a glyph (of two different font versions) into two ImageObjects, then comparing them, and adding some color filter, and drawing them to the pages just like in the example above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions