Skip to content

Problem with the with context processor used for the OnDiskBitmap backgrounds #28

Closed
@FoamyGuy

Description

@FoamyGuy

This library was recently updated as part of the sweep to use with context processors where pylint suggested. But the current way it's implemented does not work properly for this library.

The code here:

with open(
self._gamedirectory + "/" + filename, "rb"
) as self._background_file:
background = displayio.OnDiskBitmap(self._background_file)

Essentially "releases" or closes the bmp file as soon as the with block ends which means that it is no longer around when the TileGrid is made and added to the display.

Current behavior causes background images not to be shown at all. It will either need to be refactored to have a larger with block that covers the entire time the image is shown. Or go back to the old way of opening the file and managing the closing of it without the with context block and adding the exception for pylint. I lean toward the latter because the file needs to remain open until the next time that set_background() is called again and I don't know if / how a with block can span across multiple function calls like that.

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