mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-09 11:26:41 +00:00

You can pretty simply reproduce a crash on `main` in `Debug` mode by running `printf "مرحبًا \n"` with your primary font set to one that supports Arabic such as Cascadia Code/Mono or Kawkab Mono, which will cause CoreText to output the shaped glyphs non-monotonically which hits the assert we have in the renderer. In `ReleaseFast` this assert is skipped and because we already moved ahead to the space glyph (which belongs at the end but is emitted first) all of the glyphs up to that point are lost. I believe this is probably the cause of #8280, I tested and this change seems to fix it at least. Included in this PR is a little optimization: we were allocating buffers to copy glyphs etc. from runs to every time, even though CoreText provides `CTRunGet*Ptr` functions which get *pointers* to the internal storage of these values- these aren't guaranteed to return a usable pointer but in that case we can always fall back to allocating again. Also avoided allocation while processing glyphs by ensuring capacity beforehand immediately after creating the `CTLine`. The performance impact of this PR is negligible on my machine and actually seems to be positive, probably due to avoiding allocations if I had to guess.