18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-20 23:14:59 +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

@@ -2570,6 +2570,11 @@ ITexture const &opengl33_renderer::Texture(texture_handle const Texture) const
return m_textures.texture(Texture);
}
void opengl33_renderer::Unload_Texture(texture_handle const Texture)
{
m_textures.unload(Texture);
}
void opengl33_renderer::Update_AnimModel(TAnimModel *model)
{
model->RaAnimate(m_framestamp);

View File

@@ -110,6 +110,8 @@ class opengl33_renderer : public gfx_renderer {
Texture( texture_handle const Texture ) override;
ITexture const &
Texture( texture_handle const Texture ) const override;
void
Unload_Texture( texture_handle const Texture ) override;
// utility methods
void
Pick_Control_Callback( std::function<void( TSubModel const *, const glm::vec2 )> Callback ) override;

View File

@@ -1922,6 +1922,12 @@ opengl_renderer::Texture( texture_handle const Texture ) const {
return m_textures.texture( Texture );
}
void
opengl_renderer::Unload_Texture( texture_handle const Texture ) {
m_textures.unload( Texture );
}
void
opengl_renderer::Pick_Control_Callback( std::function<void( TSubModel const *, const glm::vec2 )> Callback ) {

View File

@@ -95,6 +95,8 @@ public:
Texture( texture_handle const Texture ) override;
ITexture const &
Texture( texture_handle const Texture ) const override;
void
Unload_Texture( texture_handle const Texture ) override;
// utility methods
void
Pick_Control_Callback( std::function<void( TSubModel const *, const glm::vec2 )> Callback ) override;

View File

@@ -102,6 +102,9 @@ public:
virtual void Bind_Texture( std::size_t const Unit, texture_handle const Texture ) = 0;
virtual auto Texture( texture_handle const Texture ) -> ITexture & = 0;
virtual auto Texture( texture_handle const Texture ) const -> ITexture const & = 0;
// a texture the scene has never drawn taken out of the gfx card and the memory, read again when it's used: the image of a
// texture picker scrolled past. backends which keep their textures otherwise leave it
virtual void Unload_Texture( texture_handle const Texture ) {}
// utility methods
virtual void Pick_Control_Callback( std::function<void( TSubModel const *, const glm::vec2 )> Callback ) = 0;
virtual void Pick_Node_Callback( std::function<void( scene::basic_node * )> Callback ) = 0;