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

Crash on draw_text #517

Closed
catcombo opened this issue Nov 20, 2019 · 6 comments
Closed

Crash on draw_text #517

catcombo opened this issue Nov 20, 2019 · 6 comments
Labels

Comments

@catcombo
Copy link
Contributor

Bug Report

I'm trying to add scoring to my game, but sometimes program just crashed. I found out that the problem is with arcade.draw_text. I localized the problem to a minimal example below. This code will crash very fast (for me from 30 to 500 score points) with 2 different errors:

munmap_chunk(): invalid pointer
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

OR

corrupted size vs. prev_size
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

What I'm doing wrong?

P.S. Of course in my game score doesn't change so fast, but application crash sooner or later which is very disappointing behaviour.

Steps to reproduce/example code:

import arcade


class GameWindow(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)
        self.score = 0

    def on_update(self, delta_time: float):
        self.score += 1

    def on_draw(self):
        arcade.start_render()
        arcade.draw_text(str(self.score), 200, 200, color=arcade.color.WHITE_SMOKE)


def main():
    GameWindow(400, 400)
    arcade.run()


if __name__ == "__main__":
    main()

OS Fedora 30
Python 3.7.5
arcade==2.1.7
numpy==1.17.4
Pillow==6.2.1
pyglet==1.4.7
pyglet-ffmpeg2==0.1.15

@pvcraven
Copy link
Member

Interesting. How easy is it for you to modify the draw_text function? I'm wondering if the following lines:

# If the cache gets too large, dump it and start over.
if len(draw_text.cache) > 5000:  # type: ignore # dynamic attribute on function obj
    draw_text.cache = {}  # type: ignore # dynamic attribute on function obj

...if changing 5000 to 10 would fix it.

@catcombo
Copy link
Contributor Author

I changed it to 10, but still crashing. I ran the sample code under gdb and here is a stack trace. Maybe it will help somehow.

gdb.log

@catcombo
Copy link
Contributor Author

catcombo commented Nov 21, 2019

@pvcraven It seems the problem is in the line
text_image_size = draw.multiline_textsize(text, font=font)

Crashing code example (munmap_chunk(): invalid pointer):

import PIL.Image
import PIL.ImageDraw
import PIL.ImageFont


while True:
    image = PIL.Image.new("RGBA", (10, 10))
    draw = PIL.ImageDraw.Draw(image)
    font = PIL.ImageFont.truetype("Arial.ttf", 12)
    print(draw.multiline_textsize("Sample", font=font))

Works without any problem:

import PIL.Image
import PIL.ImageDraw
import PIL.ImageFont


font = PIL.ImageFont.truetype("Arial.ttf", 12)

while True:
    image = PIL.Image.new("RGBA", (10, 10))
    draw = PIL.ImageDraw.Draw(image)
    
    print(draw.multiline_textsize("Sample", font=font))

What should I do next? Should I post it as a bug in Pillow repository or should we think how to change signature of draw_text/render_text to accept preloaded fonts?

@pvcraven
Copy link
Member

pvcraven commented Nov 27, 2019

Interesting. Your sample code doesn't error out for me. Fonts could be cached though to help with performance.

I spent all morning trying to work the text to use Pyglet's text commands, but I'm not sure if that is the right track to take.

@catcombo
Copy link
Contributor Author

Though I use official Fedora build it seems the error to be specific to my OS. I can handle it by implementing my own version of draw_text to work with preloaded fonts for now. But it will be better to figure out how it can be fixed. I've opened an issue in Pillow but there is no activity yet.

@pvcraven pvcraven added the bug label Jan 20, 2020
@pvcraven
Copy link
Member

This seems to be pillow-depended, so closing here.

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

No branches or pull requests

2 participants