18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-20 10:24:58 +01:00

fix(editor): the texture pickers let go of the images scrolled past, the memory no longer runs out

The picker of the textures of a track offers every texture of the textures folder, and each tile that came into sight read its texture full size, into the graphics card and the memory, and kept it there for good. Scrolling through the list for a trackbed texture took about 2.5 MB a tile: some 900 tiles made 3.5 GB, the whole folder 28 GB, and the game went down once the memory ran out.

An image out of sight for 3 seconds is now taken out of both again (texture_manager::unload, Unload_Texture of the renderers) and read anew when it's shown once more, a few a frame as before. Only a texture the scene has never drawn is let go; those of the scene stay to the resource sweep. The texture browser lets go of its images on Refresh too. The picker no longer lists textures/previews: the 4100 previews of the node bank are images of models, not textures of anything.

Checked on td.scn by a scripted run: 8000 images of the picker read one batch a few frames after another held the game at 2-3 GB, where it went to 28 GB and fell before; images shown again after they were let go come back; a trackbed texture picked from the folder is drawn on the track after its image was let go.
This commit is contained in:
maj00r
2026-11-16 01:54:40 +01:00
parent e413675c02
commit 4525023777
11 changed files with 89 additions and 6 deletions

View File

@@ -1886,6 +1886,34 @@ texture_manager::mark_as_needed( texture_handle const Texture, bool const Near )
}
}
void
texture_manager::unload( texture_handle const Texture ) {
if( ( Texture <= 0 )
|| ( Texture >= static_cast<texture_handle>( m_textures.size() ) ) ) {
return;
}
auto const &record { m_textures[ Texture ] };
auto &texture { *record.first };
if( ( record.second != resource_timestamp() )
|| ( texture.id == opengl_texture::invalid_id )
|| ( texture.id == 0 )
|| ( true == texture.is_static )
|| ( true == texture.is_rendertarget )
|| ( texture.type == "make:" )
|| ( texture.type == "internalsrc:" ) ) {
return;
}
texture.release();
texture.data = std::vector<unsigned char>();
texture.data_state = resource_state::none;
texture.reload_on_use = true;
// the released gl name can be given to a new texture, the unit cache can't trust it
for( auto &unit : opengl_texture::units ) {
unit = -1;
}
}
// releases gl textures of vehicles not needed nor drawn for a while
void
texture_manager::release_unneeded() {