-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Fix issue with converting surfaces to 8 bit surfaces with palettes #2031
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there are chance you are leaking memory here for the all white palette? The SDL functions for setting the surface palette are careful to destroy/free (the functions have recently been renamed) any existing palettes before assigning a new one.
It looks like here you might potentially be just replacing the all white palette with the default palette leaving a dangling allocation for the old white palette.
On a wider scale it might be cool if this conversion function actually generated an appropriate 8 bit palette for the image being converted using something like the Median cut algorithm. See here for one example. This would be beyond the scope of this PR though.
Thanks for catching that, it does indeed look as if there is a memory leak, I'll work on fixing that. |
This should get a unit test to make sure the issue doesn't regress in the future. |
Added a unit test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This resolves issue pygame/pygame#2477 by checking if the new surface needs a palette and creating the default one for it if it does.