Fix WGPU out-of-memory crash by caching overlay textures (closes #3611) #3614
+20
−9
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.
Fixes #3611
Problem
Graphite could crash with a WGPU out-of-memory error during normal usage.
The root cause was repeated allocation of overlay textures instead of reusing existing ones.
Each frame or update created new GPU textures, causing GPU memory usage to grow continuously until WGPU failed.
This resulted in:
GPU out-of-memory crashes
Increasing memory usage over time
Unstable rendering behavior during longer sessions
Solution
Overlay textures are now cached and reused instead of being recreated repeatedly.
By reusing existing GPU textures, unnecessary allocations are avoided and GPU memory usage remains stable.
The save behavior and rendering logic remain unchanged — only texture lifecycle management is corrected.
Changes
Introduced caching for overlay textures
Prevented repeated GPU texture allocations
Ensured existing textures are reused where appropriate
Testing
Built the project locally
Reproduced the out-of-memory crash before the fix
Verified GPU memory usage remains stable after the change
Confirmed no regressions in rendering behavior