devkitPro / libctru

Homebrew development library for Nintendo 3DS/Horizon OS user mode (Arm11)

Home Page:https://libctru.devkitpro.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Latest libctru makes app crash on exit

Core-2-Extreme opened this issue · comments

After upgrading to the libctru 2.2.2 (devkitarm r62-1), I found a strange crash on exit.
It never happened on libctru 2.2.1 (devkitarm r60-9). (I'm not sure if root cause it libctru or gcc compiler)
(Unfortunately, I don't have devkitarm r61, so it is unknown if this issues happens on r61)

After investigating it, I found that if I assign more than 16 bytes (without null terminator) string to std::string variable, it will crash on exit.
If it less than 16 bytes, it closes fine.

Here is minimal code to reproduce the problem : Crash_on_exit.zip
Use precompiled _R62/Crash_on_exit_A.3dsx and _R62/Crash_on_exit_B.3dsx to reproduce the problem.

gdb output on crash (_R62/Crash_on_exit_A.3dsx, full output is in _R62/gdb.txt) :

Thread 1 received signal SIGSEGV, Segmentation fault.
0x0010a178 in _free_r ()
(gdb) bt
#0  0x0010a178 in _free_r ()
#1  0x00106184 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() ()
#2  0x00100908 in __static_initialization_and_destruction_1 () at source/main.cpp:5
#3  0x00100928 in _GLOBAL__sub_D__Z4textB5cxx11 () at source/main.cpp:30
#4  0x0010b7d8 in __libc_fini_array ()
#5  0x00100c50 in __ctru_exit () at /home/davem/projects/devkitpro/pacman-packages/libctru/src/libctru-2.2.2/libctru/source/system/stack_adjust.s:29
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Here is my environment for _R62 folder (full output is in _R62/env.txt) :

$ pacman -Ss 3ds-dev
dkp-libs/libctru 2.2.2-1 (3ds-dev) [installed]
    Nintendo 3DS userland library.
dkp-windows/devkitARM r62-1 (gp32-dev gp2x-dev gba-dev nds-dev 3ds-dev) [installed]
    Toolchain for gp2x, gp32, Nintendo gba, nds, dsi, (3)ds & switch homebrew development
arm-none-eabi-gcc.exe -v
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (devkitARM release 62)

Here is my environment for _R60 folder (full output is in _R60/env.txt) :

dkp-libs/libctru 2.2.1-1 (3ds-dev) [installed]
    Nintendo 3DS userland library.
dkp-windows/devkitARM r60-9 (gp32-dev gp2x-dev gba-dev nds-dev 3ds-dev) [installed]
    Toolchain for gp2x, gp32, Nintendo gba, nds, dsi, (3)ds & switch homebrew development
arm-none-eabi-gcc.exe -v
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (devkitARM release 60)

Fixed with 4de90c3 & libctru 2.2.2-2 hotfix package.