Skip to content

Conversation

yunline
Copy link
Contributor

@yunline yunline commented Jun 16, 2023

Fixes: #1506
Test code:

import pygame

pygame.init()
font = pygame.font.Font(None, 40)

pygame.quit()
pygame.init()

font.render("hello", True, "white")
#font.size("hello")
#font.metrics("hello")

Now it will raise an error instead of segfault

pygame-ce 2.3.1.dev1 (SDL 2.26.4, Python 3.10.6)
Traceback (most recent call last):
  File "x:\python\pygame_test\segfault.py", line 10, in <module>
    font.render("hello", True, "white")
pygame.error: Invalid font.

@yunline yunline added font pygame.font bugfix PR that fixes bug labels Jun 16, 2023
@yunline yunline requested a review from a team as a code owner June 16, 2023 01:31
@yunline yunline changed the title Fix segfault when rendering a font Fix segfault when rendering fonts Jun 16, 2023
Copy link
Member

@andrewhong04 andrewhong04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see nothing out of the ordinary. LGTM!

@Starbuck5
Copy link
Member

This looks great!

I'm wondering if we can be more clear with the "invalid font" error message. "Invalid font (font module quit since font created)" ?

It would also be good to add some documentation about this whole generation constraint. I think it would go well as another line in pygame.font.quit, mentioning that previously created font objects become invalid after the font module is quit.

Copy link
Member

@Starbuck5 Starbuck5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Starbuck5 Starbuck5 merged commit 8805b16 into pygame-community:main Jun 18, 2023
@yunline yunline deleted the font-render-segfault branch June 18, 2023 08:25
@MightyJosip MightyJosip added this to the 2.3.1 milestone Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix PR that fixes bug font pygame.font
Projects
None yet
Development

Successfully merging this pull request may close these issues.

segfault while using Font object from a different init generation (2971)
4 participants