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

fix(editor): the images of the materials let go of with all their textures, the browser's Refresh a frame later

An image of a material read the material with all its textures, the normal and specular maps and the variants, and only the first one was let go of: those stayed in the memory for every material scrolled past. They are let go of together now (Unload_Material). texture_manager::unload also takes the textures read and not made yet, waiting for a worker still reading one, and deletes the gl texture itself: release() would read it back from the card with gfx.resource.move only for it to be dropped.

The Refresh of the texture browser let go of the images in the middle of the frame, while panels drawn before it could still refer to them; it now marks them, and they go at the start of the next frame.

Checked on td.scn by a scripted run: 8040 images of the picker read a batch every few frames end at 2.0 GB, against 2.3-2.6 GB before this and 1.1 GB at the start; a trackbed material picked from the folder is drawn on the track after its image was let go.
This commit is contained in:
maj00r
2026-11-16 02:10:59 +01:00
parent 4525023777
commit 0bbf07bf11
9 changed files with 82 additions and 22 deletions

View File

@@ -1896,22 +1896,40 @@ texture_manager::unload( texture_handle const Texture ) {
auto const &record { m_textures[ Texture ] };
auto &texture { *record.first };
if( ( record.second != resource_timestamp() )
|| ( texture.id == opengl_texture::invalid_id )
|| ( texture.id == 0 )
|| ( texture.id == 0 ) // failed to load
|| ( true == texture.is_static )
|| ( true == texture.is_rendertarget )
|| ( texture.type == "make:" )
|| ( texture.type == "internalsrc:" ) ) {
return;
}
texture.release();
if( ( texture.data_state == resource_state::loading )
&& ( texture.request != nullptr ) ) {
// read by a worker thread: taken over first, to be dropped with the rest
texture.complete_data();
if( texture.data_state == resource_state::failed ) {
return;
}
}
auto const created { texture.id != opengl_texture::invalid_id };
if( ( false == created )
&& ( texture.data_state != resource_state::good ) ) {
// nothing read nor made, e.g. the textures of a material asked for without loading
return;
}
if( true == created ) {
// deleted outright: release() would read the texture back from the card with gfx.resource.move, only for it to be dropped
::glDeleteTextures( 1, &texture.id );
texture.id = opengl_texture::invalid_id;
texture.is_ready = false;
// 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;
}
}
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