-
-
Notifications
You must be signed in to change notification settings - Fork 23.1k
Closed
Description
Tested versions
- Reproducible in: 4.5 beta 6 official, 4.5 beta 7 official
- Not Reproducible in: 4.4.1 official
System information
MacOS Sequoia 15.6.1 (24G90), Windows 10
Issue description
If you
- load a font dynamically
- use it to override a theme font on a Text Edit
- do not keep a reference to it,
- remove the font override
Godot will generate a number of 'Parameter "fd" is null' errors proportional to the number of characters in the TextEdit. If there are no characters in the TextEdit no errors are generated.
E 0:00:00:334 main.gd:23 @ swap_font(): Parameter "fd" is null.
<C++ Source> modules/text_server_adv/text_server_adv.cpp:2844 @ _font_get_ascent()
<Stack Trace> main.gd:23 @ swap_font()
main.gd:12 @ _ready()
You can workaround this by keeping a reference to the font yourself. This might be the intended behavior but it did not work this way in Godot 4.4.1 so I thought I'd report it.
Steps to reproduce
Here's the source for the project below.
extends Node2D
@onready var text_edit = $TextEdit
var keep_reference = false
var _font_ref = null
func _ready():
text_edit.text = "hello world"
swap_font('custom')
swap_font('default')
func swap_font(which):
if(which == 'custom'):
var dynamic_font = FontFile.new()
dynamic_font.load_dynamic_font("res://CourierPrime-Regular.ttf")
text_edit.add_theme_font_override('font', dynamic_font)
if(keep_reference):
_font_ref = dynamic_font
else:
text_edit.remove_theme_font_override('font')
If you open the project and run the main scene it will generate 44 errors.
- You can change the text and rerun to see how the errors scale with characters in the TextEdit.
- If you change the text to an empty string then no errors are generated.
- If you set
keep_reference
totrue
and have text in the TextEdit then no errors are generated. This is the workaround/what-you-should-actually-do mentioned above.
Minimal reproduction project (MRP)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Bad