godotengine / godotengine/godot
Invalid or empty glyph font texture causes mipmap check to segfault
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
- Reproducible on: v4.4.1.stable.mono.official [49a5bc7b6], v4.5.rc.mono.custom_build [3c7f9b937](directly cloned from master branch)
### System information
Godot v4.4.1.stable.mono - Artix Linux #1 SMP PREEMPT_DYNAMIC Mon, 01 Sep 2025 16:44:13 +0000 on X11 - X11 display driver, Multi-window, 1 monitor - Vulkan (Forward+) - dedicated AMD Radeon RX 580 2048SP (RADV POLARIS10) - Intel(R) Xeon(R) CPU E3-1220 v3 @ 3.10GHz (4 threads)
### Issue description
When working on my game, I have noticed that under quite flacky conditions, Godot would segfault when I added a button onto the scene.
After some investigation, I hooked Godot to GDB and came across this backtrace on crash:
```
0x000055555defa7e2 in Image::has_mipmaps (this=0x0) at core/io/image.cpp:459
459 return mipmaps;
(gdb) backtrace
#0 0x000055555defa7e2 in Image::has_mipmaps (this=0x0) at core/io/image.cpp:459
#1 0x0000555558c2b3d2 in TextServerAdvanced::_font_draw_glyph (this=0x5555636a4670, p_font_rid=..., p_canvas=..., p_size=14, p_pos=...,
p_index=52, p_color=..., p_oversampling=0) at modules/text_server_adv/text_server_adv.cpp:4004
#2 0x0000555558c4cbd9 in TextServerAdvanced::font_draw_glyph (this=0x5555636a4670, arg1=..., arg2=..., arg3=14, arg4=..., arg5=52,
arg6=..., arg7=0) at modules/text_server_adv/text_server_adv.h:930
#3 0x000055555d3042b7 in TextServer::shaped_text_draw (this=0x5555636a4670, p_shaped=..., p_canvas=..., p_pos=..., p_clip_l=0,
p_clip_r=118, p_color=..., p_oversampling=0) at servers/text_server.cpp:1797
#4 0x000055555d97b6ed in TextServerExtension::shaped_text_draw (this=0x5555636a4670, p_shaped=..., p_canvas=..., p_pos=..., p_clip_l=0,
p_clip_r=118, p_color=..., p_oversampling=0) at servers/text/text_server_extension.cpp:1570
#5 0x000055555cce783c in TextParagraph::draw (this=0x55556727de20, p_canvas=..., p_pos=..., p_color=..., p_dc_color=...,
p_oversampling=0) at scene/resources/text_paragraph.cpp:929
TextParagraph::draw -> TextServerExtension::shaped_text_draw -> TextServerAdvanced::font_draw_glyph -> TextServerAdvanced::_font_draw_glyph -> Image::has_mipmaps
```
Checking the offending code, it seems to code from [`modules/text_server_adv/text_server_adv.cpp`, around line 3999](https://github.com/godotengine/godot/blob/3c7f9b937214068bc892be0d2bd9a8a7026edae1/modules/text_server_adv/text_server_adv.cpp#L3999)
The `Ref img = tex.image;` references the image from `ShelfPackTexture &tex = ffsd->textures.write[fgl.texture_idx];`. For some reason, seems that `fgl.texture_idx` inside the `ffsd->textures.write` array is null.
Adding `ERR_FAIL_NULL(img);` at the line after the `Ref img = tex.image;` seems to mitigate the issue, yet console now prints errors on the console about a null reference.
There doesn't seem to be any sort of visual bug with this patch?
### Steps to reproduce
1. Open the reproducible project mentioned at the MRP
2. Run it
3. Click on the only button
4. Click once on the dialogue to advance it once
I'm not sure if the code being in C# has any sort of relation to it, or if GDScript would achieve the same behavior
Going on step-by-step with the debugger seems to get into a `DialogueService.Generated.cs` before the segfault takes place, could be related?
### Minimal reproduction project (MRP)
Reproducible project is available at: https://github.com/akatsukilevi/godot-bugreport-font-segfault
Contributor guide
Assessment
This issue has not been assessed yet.