Skip to content

RenderWindow initializes Pygame but offers no teardown #16

Description

@dmccoystephenson

Observation

RenderWindow.__init__ calls pygame.init(), but the class exposes no corresponding teardown. Every caller is therefore left to call pygame.quit() itself, which is what all three examples in render_window_example.py do:

while window.should_continue():
    ...
pygame.quit()

This makes the API asymmetric: setup is encapsulated, cleanup is not.

Suggested change

A close() (or quit()) method should be added that calls pygame.quit() and marks the window as no longer running. Support for the context-manager protocol (__enter__ / __exit__) would additionally allow the following, which removes the possibility of a caller forgetting the teardown:

with RenderWindow("Title", 800, 600) as window:
    while window.should_continue():
        ...

Once such a method exists, the examples in render_window_example.py and the snippet in README.md should be updated to use it rather than calling pygame.quit() directly.

Notes

This gap was identified while PR #10 was reviewed, and was deliberately not addressed there in order to keep that PR scoped to the API named in issue #6. It is covered by mocked unit tests, so no live Viron server is needed to validate a fix.

This issue body was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions