Memory leak in draw_string example
Your Godot version: 3.stable
Issue description: The code example creates an orphan node.
The below is the corrected example which does not leak memory.
var control = Control.new()
var default_font = control.get_font("font")
control.queue_free()
draw_string(default_font, Vector2(64, 64), "Hello world")
URL to the documentation page: https://docs.godotengine.org/en/stable/classes/class_canvasitem.html#class-canvasitem-method-draw-string
To avoid this kind of Control node creation (which I always found uncanny), I wonder if we should expose the default project font as a SceneTree property or getter method.
Yeah. It's definitely relevant. I am working on a bunch of tool enabled nodes with editor only drawing, and my only option is this hack for every single, potentially hundreds of nodes. Or include a copy of my own font. There is no means to elegantly hook into the default theme / font for the engine for custom drawing.
Perhaps instead of a SceneTree property, the ProjectSettings.custom_font could point to the default one? https://docs.godotengine.org/en/stable/classes/class_projectsettings.html#class-projectsettings-property-gui-theme-custom-font
Perhaps instead of a SceneTree property, the ProjectSettings.custom_font could point to the default one? docs.godotengine.org/en/stable/classes/class_projectsettings.html#class-projectsettings-property-gui-theme-custom-font
The project setting is only a String containing a path to a font, not an actual Font resource. Even though you can use load(), we preferably should have an actual Font resource here.
In Godot 4, Window and Control's get_theme_default_font() and ThemeDB's fallback_font exist. The linked example brought in the report has also been updated not to use the leak-prone example.
Issue still persists in 3.x, though.