mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-20 20:54: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:
@@ -745,13 +745,21 @@ class editor_mode : public application_mode, private editor_track::observer, pri
|
||||
char filter[64]{};
|
||||
float size{96.f}; // of the images, pixels
|
||||
std::string selected;
|
||||
std::map<std::string, int> thumbnails; // texture shown for the item of the name, 0: none
|
||||
struct thumbnail
|
||||
{
|
||||
int texture{0}; // 0: none
|
||||
double shown{0.0}; // when it was last asked for, ImGui time
|
||||
};
|
||||
std::map<std::string, thumbnail> thumbnails; // texture shown for the item of the name
|
||||
int loads{0}; // textures read in the frame, a few at most so the browser doesn't stall the editor
|
||||
int loadsframe{-1};
|
||||
} m_textures;
|
||||
void render_texture_browser();
|
||||
// texture of the image of the item of the browser, 0 while there's none
|
||||
std::uint64_t texture_thumbnail(texture_browser::item const &Item);
|
||||
// the textures of the images out of sight for a while taken out of the memory: a picker of thousands of them scrolled
|
||||
// through would keep them all, full size, until the memory ran out
|
||||
void thumbnails_trim();
|
||||
// takes a material dragged from the texture browser onto the item drawn last. returns: true if one was dropped, its name in Name
|
||||
static bool material_drop(std::string &Name);
|
||||
// the same, for a text field
|
||||
|
||||
Reference in New Issue
Block a user