-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AddFontFromMemoryTTF transferring ownership #220
Comments
I am a little hesitant to add another parameter... thinking about it.
I'll change "pass" to "transfer". Evidently you can't really see the comment in github with that width but I'd assume you would see it in a code editor. |
Cosmetic change for now I made the declaration a little shorter to increase odds of reading the comment, reworded comment and made the comment in the implementation the same.
If there was an extra flag already do you think you would have seen it ? That flag would be the last parameter and therefore just next to the comment. |
Well, I don't read comments unless something goes terribly wrong :) I think extra parameter would make it more noticeable, but it's not a big deal if you'd rather not add it. |
Can't blame you for not reading the comments, at least they are here when you come and look again. ImGui only needs the data until Build is called, generally via one of the GetTexData**() function is called. So it could also hold on the pointer without deleting it without making a copy of the data. Which is a third possibility. Will probably add a flag. |
The AA branch now support this with the new ImFontConfig* settings. Alter with: ImFontConfig font_cfg;
font_cfg.FontDataOwnedByAtlas = false;
io.AddFontFromMemoryTTF(data, data_size, 20.0f, &font_cfg); Alternatively you can call the lower-level AddFont() function as well. AddFontFromMemoryTTF() doesn't do much anymore. |
This is now merged in master along with the entire new AA-branch. Note that it is a rather big update and you'll need to update your render function to use indexed vertex rendering. |
I was also just stumbling over this. I'm doing an AddFontFromMemoryTTF() from static data, embedded as C array, and was a bit surprised that imgui tried to free the data on shutdown. I'll use the way described above to pass a ImFontConfig struct :) |
Same thing - Imgi crashes. |
It took me a while to figure out why loading a font with AddFontFromMemoryTTF crashed but AddFontFromFileTTF worked ok with the same data. Turns out AddFontFromMemoryTTF transfers the ownership of the data to imgui, which is a little surprising. I suggest that you add a flag transfer_ownership: if the flag is off, AddFontFromMemoryTTF should copy the data.
The text was updated successfully, but these errors were encountered: