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

Merge pull request #386 from MaSzyna-EU07/fix/editor-trackbed-texture-crash

fix(editor): the texture pickers let go of the images scrolled past, the memory no longer runs out
This commit is contained in:
2026-11-16 16:01:30 +00:00
committed by GitHub
14 changed files with 147 additions and 12 deletions

View File

@@ -1886,6 +1886,52 @@ 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 == 0 ) // failed to load
|| ( true == texture.is_static )
|| ( true == texture.is_rendertarget )
|| ( texture.type == "make:" )
|| ( texture.type == "internalsrc:" ) ) {
return;
}
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;
}
// releases gl textures of vehicles not needed nor drawn for a while
void
texture_manager::release_unneeded() {

View File

@@ -181,6 +181,10 @@ public:
// releases gl textures of vehicles not needed nor drawn for a while
void
release_unneeded();
// takes a texture the scene has never drawn out of both the gfx card and the memory, e.g. the image of a picker scrolled
// past, or one read and not made yet; it's read again when it's used. textures the scene draws are left to the resource sweep
void
unload( texture_handle const Texture );
// debug performance string
std::string
info() const;

View File

@@ -66,6 +66,13 @@ struct opengl_material : public IMaterial {
{
return textures[slot];
}
virtual std::vector<texture_handle> GetAllTextures() const override
{
std::vector<texture_handle> all(textures.begin(), textures.end());
for (auto const &variant : texture_variants)
all.insert(all.end(), variant.begin(), variant.end());
return all;
}
// returns texture set to use for model instance identified by provided variant id
texture_set const &GetTextures(std::uint32_t const Variant) const
{