AZO234 / NP2kai

Neko Project II kai
http://domisan.sakura.ne.jp/article/np2kai/np2kai.html
MIT License
254 stars 62 forks source link

(libretro) Fix crash when loaded with no content. #57

Closed orbea closed 6 years ago

orbea commented 6 years ago

When the libretro core is loaded without content.

retroarch -L /path/to/np2kai_libretro.so

It will crash when it tries to get the content directory which does not exist.

This can be avoided by checking if the content exists and then not extracting the directory when it doesn't exist. It will then proceed to init np2kai and then show a black screen with several ??????. This matches the behavior when loaded with incorrect content (i.e. a text file).

Also see this PR which is discussing similar issues for other libretro cores.

https://github.com/libretro/RetroArch/pull/7102

orbea commented 6 years ago

Here is the backtrace for reference.

Thread 1 "retroarch" received signal SIGSEGV, Segmentation fault.
0x00007fffefd7d057 in retro_load_game (game=0x0)
    at ../sdl2/libretro/libretro.c:1389
1389       extract_directory(base_dir, game->path, sizeof(base_dir));
(gdb) bt
#0  0x00007fffefd7d057 in retro_load_game (game=0x0)
    at ../sdl2/libretro/libretro.c:1389
#1  0x0000000000411118 in core_load_game (load_info=0x7fffffffd770)
    at core_impl.c:308
#2  0x000000000042ba4f in content_file_load (info=0xa024b0, content=0xa02260, 
    content_ctx=0x7fffffffd840, error_string=0x7fffffffd838, special=0x0, 
    additional_path_allocs=0xa024e0) at tasks/task_content.c:626
#3  0x000000000042bfb5 in content_file_init (content_ctx=0x7fffffffd840, 
    content=0xa02260, error_string=0x7fffffffd838) at tasks/task_content.c:808
#4  0x000000000042df89 in content_init () at tasks/task_content.c:1938
#5  0x0000000000419c60 in event_init_content () at command.c:1260
#6  0x0000000000419db1 in command_event_init_core (data=
    0x907408 <current_core_type>) at command.c:1318
#7  0x000000000041b6f0 in command_event (cmd=CMD_EVENT_CORE_INIT, 
    data=0x907408 <current_core_type>) at command.c:2300
#8  0x00000000004134fa in retroarch_main_init (argc=3, argv=0x7fffffffe1e8)
    at retroarch.c:1371
#9  0x000000000042b0a1 in content_load (info=0x7fffffffe0b0)
    at tasks/task_content.c:279
#10 0x000000000042c1f1 in task_load_content (content_info=0x7fffffffe0b0, 
    content_ctx=0x7fffffffdfc0, launched_from_menu=true, launched_from_cli=true, 
    error_string=0x7fffffffdfb8) at tasks/task_content.c:880
#11 0x000000000042d654 in task_load_content_callback (
    content_info=0x7fffffffe0b0, loading_from_menu=true, loading_from_cli=true)
    at tasks/task_content.c:1565
#12 0x000000000042d7ff in task_push_load_content_from_cli (core_path=0x0, 
    fullpath=0x0, content_info=0x7fffffffe0b0, type=CORE_TYPE_PLAIN, cb=0x0, 
    user_data=0x0) at tasks/task_content.c:1633
#13 0x000000000040fe41 in rarch_main (argc=3, argv=0x7fffffffe1e8, data=0x0)
    at frontend/frontend.c:125
#14 0x000000000040fec4 in main (argc=3, argv=0x7fffffffe1e8)
    at frontend/frontend.c:169
AZO234 commented 6 years ago

Thanks to your betterment!