Skip to content

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

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

Closed
FoamyGuy opened this issue Dec 10, 2021 · 0 comments · Fixed by #29
Closed

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

FoamyGuy opened this issue Dec 10, 2021 · 0 comments · Fixed by #29

Comments

@FoamyGuy
Copy link
Contributor

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.

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

Successfully merging a pull request may close this issue.

1 participant