Quick answer: Use buffer_grow type for dynamic data. For shrinking, copy wanted bytes to a fresh buffer rather than resize in place.
Save game uses buffer_resize to trim. Re-load shows garbage. Resize past current size is destructive; data past the new boundary is lost.
The Fix
// Use buffer_grow type
var _buf = buffer_create(1024, buffer_grow, 1);
// Or copy preserving wanted data
function shrink_buffer(_src, _new_size) {
var _new = buffer_create(_new_size, buffer_fixed, 1);
buffer_copy(_src, 0, _new_size, _new, 0);
buffer_delete(_src);
return _new;
}
buffer_grow auto-extends on write so you never need an explicit resize. For shrinking, copy bytes you want into a new buffer.
Verifying
Save and reload after shrink: data intact for the kept range. Without copy: corrupt bytes past the new size.
“Grow buffers. Or copy on shrink. Data preserved.”
Related Issues
For tilemap cache, see tilemap cache. For draw text color, see draw color.
Grow type. Or copy on shrink.