Skip to content
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

[Crash]: Textbuf caret movements with non-trivial scripts (CJK, etc) can trigger NOT_REACHED #11203

Closed
JGRennison opened this issue Aug 16, 2023 · 2 comments · Fixed by #11204

Comments

@JGRennison
Copy link
Contributor

Version of OpenTTD

master (Linux)

Steps to reproduce

  1. Change the font configuration and/or language so that you can insert CJK text
  2. Paste some CJK text into a sign or other textbuf
  3. Press the left arrow key
  4. Press another key to insert a character

Upload crash files

#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=140737275484928) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=140737275484928) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=140737275484928, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007ffff6f9b476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007ffff6f817f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x0000555555ede259 in FatalErrorI(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (str="NOT_REACHED triggered at line 267 of /home/jgr/openttd/trunk/src/gfx_layout.cpp")
    at /home/jgr/openttd/trunk/src/openttd.cpp:141
#6  0x0000555555d58cfd in NotReachedError(int, char const*) (line=line@entry=267, file=file@entry=0x555556132650 "/home/jgr/openttd/trunk/src/gfx_layout.cpp") at /home/jgr/openttd/trunk/src/error.cpp:15
#7  0x0000555555d9132a in Layouter::GetCharPosition(char const*) const (this=this@entry=0x7fffffffd1a0, ch=ch@entry=0x555559d0eb24 "은") at /home/jgr/openttd/trunk/src/gfx_layout.cpp:267
#8  0x0000555555d8b3c1 in GetCharPosInString(std::basic_string_view<char, std::char_traits<char> >, char const*, FontSize)Python Exception <class 'gdb.error'>: value has been optimised out
 (str=, ch=ch@entry=0x555559d0eb24 "은", start_fontsize=start_fontsize@entry=FS_NORMAL)
    at /home/jgr/openttd/trunk/src/gfx.cpp:887
#9  0x0000555555ffea98 in Textbuf::UpdateCaretPosition() (this=0x5555596d25c8) at /home/jgr/openttd/trunk/src/textbuf.cpp:295
#10 Textbuf::InsertString(char const*, bool, char const*, char const*, char const*)
    (this=0x5555596d25c8, str=0x7fffffffd2cc "a", marked=marked@entry=false, caret=0x0, insert_location=insert_location@entry=0x0, replacement_end=replacement_end@entry=0x0) at /home/jgr/openttd/trunk/src/textbuf.cpp:210
#11 0x00005555560aa163 in Window::InsertTextString(int, char const*, bool, char const*, char const*, char const*)
    (this=0x5555596d2480, wid=2, str=<optimised out>, marked=<optimised out>, caret=<optimised out>, insert_location=0x0, replacement_end=0x0) at /home/jgr/openttd/trunk/src/window.cpp:2714
#12 0x00005555560ace5d in HandleTextInput(char const*, bool, char const*, char const*, char const*)
    (str=str@entry=0x7fffffffd2cc "a", marked=marked@entry=false, caret=caret@entry=0x0, insert_location=insert_location@entry=0x0, replacement_end=replacement_end@entry=0x0) at /home/jgr/openttd/trunk/src/window.cpp:2730
#13 0x0000555555c7bdcc in VideoDriver_SDL_Base::PollEvent() (this=<optimised out>) at /home/jgr/openttd/trunk/src/video/sdl2_v.cpp:477
#14 0x0000555555c858e5 in VideoDriver::Tick() (this=this@entry=0x555557b3a020) at /home/jgr/openttd/trunk/src/video/video_driver.cpp:135
#15 0x0000555555c7978e in VideoDriver_SDL_Base::LoopOnce() (this=0x555557b3a020) at /home/jgr/openttd/trunk/src/video/sdl2_v.cpp:621
#16 VideoDriver_SDL_Base::LoopOnce() (this=0x555557b3a020) at /home/jgr/openttd/trunk/src/video/sdl2_v.cpp:600
#17 VideoDriver_SDL_Base::MainLoop() (this=0x555557b3a020) at /home/jgr/openttd/trunk/src/video/sdl2_v.cpp:639
#18 0x0000555555ee5afa in openttd_main(int, char**) (argc=<optimised out>, argv=<optimised out>) at /home/jgr/openttd/trunk/src/openttd.cpp:786
#19 0x00007ffff6f82d90 in __libc_start_call_main (main=main@entry=0x5555557befe0 <main(int, char**)>, argc=argc@entry=2, argv=argv@entry=0x7fffffffdba8) at ../sysdeps/nptl/libc_start_call_main.h:58
#20 0x00007ffff6f82e40 in __libc_start_main_impl (main=0x5555557befe0 <main(int, char**)>, argc=2, argv=0x7fffffffdba8, init=<optimised out>, fini=<optimised out>, rtld_fini=<optimised out>, stack_end=0x7fffffffdb98)
    at ../csu/libc-start.c:392
#21 0x0000555555861865 in _start ()
@JGRennison
Copy link
Contributor Author

It seems that in the ICU implementation ICUVisualRun::GetGlyphToCharMap always starts from 0, instead of being relative to the overall string

@JGRennison
Copy link
Contributor Author

It seems that the bug is introduced by aed36a6.
Reverting that fixes the problem, but that commit claims to fix something else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant