Skip to content

Not possible to create a font with caller-owned memory #9086

Closed

Description

@TellowKrinkle

Version/Branch of Dear ImGui:

v1.92.5

Back-ends:

Custom (PCSX2)

Compiler, OS:

macOS + Apple Clang 17

Full config/build information:

No response

Details:

While many latin fonts are just kilobytes, other fonts can get pretty big. CJK fonts are often a few megabytes, Noto Color Emoji is 25MB, and Apple Color Emoji (which doesn't work yet, but might in the future) is 150MB. With those kinds of sizes, it would be ideal to mmap the font to avoid loading the parts that don't get used, but at the very least you don't want multiple copies getting loaded even if you want to e.g. add an emoji font to the fallback path of multiple ImFonts.

ImGui currently has ImFontConfig::FontDataOwnedByAtlas to allow you to select whether ImGui manages the memory of the font so you just set that to false and...

imgui/imgui_draw.cpp

Lines 3055 to 3059 in 6d910d5

if (font_cfg->FontDataOwnedByAtlas == false)
{
font_cfg->FontDataOwnedByAtlas = true;
font_cfg->FontData = ImMemdup(font_cfg->FontData, (size_t)font_cfg->FontDataSize);
}

Is there some other way to add a TTF to a font that trusts the caller to keep the memory alive until fonts are cleared/removed?

Screenshots/Video:

N/A unless you want a picture of my application's memory usage

Minimal, Complete and Verifiable Example code:

No response

Activity

  1. ocornut commented on Nov 21, 2025

    @ocornut
    Owner

    ImGui currently has ImFontConfig::FontDataOwnedByAtlas to allow you to select whether ImGui manages the memory of the font so you just set that to false and..

    Argh. I don’t remember/know why I added this code. I will investigate this later but I agree it defeats the purpose.

  2. added this to the v1.93 milestone on Nov 21, 2025
  3. ocornut commented on Nov 24, 2025

    @ocornut
    Owner

    Congratulation, you seem to have uncovered the oldest fuckup in Dear ImGui history 🥇
    815168c#diff-cee9beb740469eb5192dfe94aaee7320932590adade9d9b1d2ee392ac2e1e88cR9836

  4. ocornut commented on Nov 24, 2025

    @ocornut
    Owner

    I cannot find a reason for this and removed the duplication: 98636f4
    Thank you for spotting this!

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址