Fix bundle freeing: Bitmap resources not being freed #153
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Background
SplashKit bundles allow sets of resources to be loaded and freed as a group. For more information, see the documentation. The
free_resource_bundlefunction is supposed to free every resource in the bundle at once.Problem
The
free_resource_bundlefunction currently does not free bitmaps. This was shown in the "Bundles" test results - every other resource was freed successfully, except the bitmaps.Cause
When a bundle is loaded, each line of the bundle text file is analysed and run through a
SWITCHin theload_resource_bundlefunction, loading the resource based on its type. Then the resources are added to a list (vector), which is stored as a field in the bundle. Meaning each bundle in memory has a list of corresponding resources. However, after the resources are loaded, their existence is checked to ensure the loading was successful. If it wasn't, the function returns early and the resource isn't added to the list.In the case of a bitmap, we have:
Which means the condition checks for the bundle, not a bitmap. So the bitmap is loaded, but not added to the bundle's list of resources, and therefore not freed by
free_resource_bundle.Fix
This is a very small and simple fix, changing the
IMAGE_RESOURCEcase so it checkshas_bitmaprather thanhas_resource_bundle.Type of change
How Has This Been Tested?
Ran the "Bundles" test in
sktestin WSL and MSYS2. Also ranskunit_tests.Results of Bundles test
Testing Checklist
Checklist