Skip to content

fix: avoid redundant entity texture loading and VRAM exhaustion - #36

Open
Royikiss wants to merge 1 commit into
BestProjectTeam:mainfrom
Royikiss:fix-entities-vram-leak
Open

Royikiss wants to merge 1 commit into
BestProjectTeam:mainfrom
Royikiss:fix-entities-vram-leak

Conversation

@Royikiss

Copy link
Copy Markdown

Summary

Fixes an issue where opening the Assets settings tab causes an out-of-VRAM crash (GFX_ERROR_TYPE_OUT_OF_MEMORY_IMAGE), particularly when custom high-resolution entity textures (e.g. 2K or 4K) are present in assets/entities.

Details

  1. Deduplicate texture loading for single-file entities:

    • In CMenus::LoadEntities(), when an entity item is a single PNG file rather than a directory, the loop previously called LoadTexture() repeatedly for each of the MAP_IMAGE_MOD_TYPE_COUNT mod types during fallback.
    • For high-resolution (e.g., 4096x4096) textures, this uploaded the exact same image to GPU memory up to 8 times (~500MB+ per asset), easily exhausting VRAM on GPUs like the RTX 3050 Laptop and triggering VK_ERROR_OUT_OF_DEVICE_MEMORY.
    • We now check FolderExists first to avoid spamming file read errors for non-existent subpaths, load the fallback texture only once, and share the texture handle across mod types.
  2. Safe texture unloading:

    • In CMenus::ClearCustomItems(), use AssetsUnloadEntitiesPreview(Entity, Graphics()) (matching RemoveCustomAssetFromList) to cleanly deduplicate and invalidate shared handles before destroying textures.

- Check if the entity path is a directory before trying to load mod-specific sub-textures.
- For single-file entity textures, load the image once and reuse the texture handle across mod types instead of reloading the file up to 8 times into GPU memory.
- In ClearCustomItems, use AssetsUnloadEntitiesPreview to properly unload deduplicated texture handles.
Copilot AI lite review requested due to automatic review settings September 27, 2026 11:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved issues remain, and the changes address redundant loading and safe texture cleanup.

Review effort: Lite
Findings: None

What changed in this PR

Prevents redundant entity texture loading and safely unloads shared handles to avoid VRAM exhaustion.

Changes:

  • Detects entity folders before loading mod-specific textures.
  • Shares fallback textures across mod types.
  • Deduplicates texture cleanup.
File Description
src/​game/​client/​components/​menus_settings_assets.cpp Updates entity texture loading and cleanup logic.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants