melonDS-emu / melonDS

DS emulator, sorta
https://melonds.kuribo64.net
GNU General Public License v3.0
3.27k stars 542 forks source link

melonDS 0.9 crashes when switching to OpenGL #747

Open BSJ64 opened 4 years ago

BSJ64 commented 4 years ago

On the newest version of melonDS, the emulator will crash when changing the video settings to either OpenGL renderer or OpenGL display. I've ran the previous version and it still works, so I'm sure it's with ver. 0.9 itself.

Mrlinkwii commented 4 years ago

same here , i get this error in VScode on linux if changing the the video settings to either to OpenGL renderer / OpenGL display,


OpenGL: renderer: Mesa DRI Intel(R) HD Graphics 4000 (IVB GT2)
OpenGL: version: 4.2 (Core Profile) Mesa 20.0.8
melonDS: pcm.c:3207: snd_pcm_area_copy: Assertion `src < dst || src >= dst + bytes' failed.
Aborted (core dumped)
v1993 commented 4 years ago

What's weird is that crash message suggests that it happened inside sound processing module. I wonder if Mesa driver is somehow related?

Mrlinkwii commented 4 years ago

its probably( most likely ) my relatively low end machine causing it

how i can reproduce it :

1.launch though VS code 2.open a game in software

  1. open video config menu 4.check the opengl option and then it crashes ,

it dosent crash when you set to opengl before you boot a game , i can boot in to opengl can change to software (no issues) and when i try to change back to opengl it crashes

v1993 commented 4 years ago

@Mrlinkwii Does it always crash in the same place?

Mrlinkwii commented 4 years ago

@v1993if when going to software to opengl as i described above it always crashes , the second time going from opengl to software back to opengl can crash but not always , im on 20.04.1 and on latest master

gif of it happening Peek 2020-09-16 15-11

PoroCYon commented 4 years ago

I can probably have a look at this in the evening, but by then, could you provide a backtrace? (gdb -ex r path/to/melonDS, do stuff as you would normally, and when it crashes, run the bt command in gdb)

Mrlinkwii commented 4 years ago

@PoroCYon idk if i did it correctly but it crashes even faster using the gdb -ex r path/to/melonDS and i didnt get a chance to even change to opengl

Thread 17 "EmuThread" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffb2ffd700 (LWP 77928)]
0x0000000005762f97 in ARMJIT::CodeMemory ()
(gdb) bt
#0  0x0000000005762f97 in ARMJIT::CodeMemory ()
#1  0x0000000000030000 in  ()
#2  0x0000000002380020 in ARMJIT::FastBlockLookupMainRAM ()
#3  0x0000000000000000 in  ()

image

RSDuck commented 4 years ago

that's not a real crash, with fastmem sigsegvs can happen intentionally, but we handle them and continue with the execution. You need to disable fastmem in the emulator settings.

Mrlinkwii commented 4 years ago
OpenGL: renderer: Mesa DRI Intel(R) HD Graphics 4000 (IVB GT2)
OpenGL: version: 4.2 (Core Profile) Mesa 20.0.8
melonDS: pcm.c:3207: snd_pcm_area_copy: Assertion `src < dst || src >= dst + bytes' failed.

Thread 12 "SDLAudioC3" received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffd27fc700 (LWP 83564)]
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007ffff67f4859 in __GI_abort () at abort.c:79
#2  0x00007ffff67f4729 in __assert_fail_base
    (fmt=0x7ffff698a588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x7ffff6794560 "src < dst || src >= dst + bytes", file=0x7ffff6799285 "pcm.c", line=3207, function=<optimised out>) at assert.c:92
#3  0x00007ffff6805f36 in __GI___assert_fail
    (assertion=0x7ffff6794560 "src < dst || src >= dst + bytes", file=0x7ffff6799285 "pcm.c", line=3207, function=0x7ffff6796750 "snd_pcm_area_copy")
    at assert.c:101
#4  0x00007ffff6726acf in snd_pcm_area_copy () at /lib/x86_64-linux-gnu/libasound.so.2
#5  0x00007ffff6726cdc in snd_pcm_areas_copy () at /lib/x86_64-linux-gnu/libasound.so.2
#6  0x00007ffff676daff in  () at /lib/x86_64-linux-gnu/libasound.so.2
#7  0x00007ffff673a1dd in  () at /lib/x86_64-linux-gnu/libasound.so.2

image

this should be whats looking for

PoroCYon commented 4 years ago

I can't seem to reproduce it (even though I'm also using ALSA, which is what's causing the assertion failures), so, not sure how.

And it's a separate thread created by SDL, not melonDS code, so I'm starting to fear this is a memory corruption or threading race condition issue, which will be lots of fun to debug.

Mrlinkwii commented 4 years ago

I can't seem to reproduce it (even though I'm also using ALSA, which is what's causing the assertion failures), so, not sure how.

And it's a separate thread created by SDL, not melonDS code, so I'm starting to fear this is a memory corruption or threading race condition issue, which will be lots of fun to debug.

@PoroCYon thanks for having a look as i said , its probably due to my low end hardware , the laptop is a few years old ( im surprised most of the time the emulators i can get running )

RSDuck commented 4 years ago

@PoroCYon thanks for having a look as i said , its probably due to my low end hardware , the laptop is a few years old ( im surprised most of the time the emulators i can get running )

I doubt it. I'm running an Ivy Bridge i5 and don't have this issue neither on Windows or Linux (~forgot which distro I'm using~ it's Manjaro).

PoroCYon commented 4 years ago

the laptop is a few years old ( im surprised most of the time the emulators i can get running )

Mine's 10yo

EDIT: and now, for some actual interesting stuff:

Would you be able to compile melonDS with AddressSanitizer or ThreadSanitizer? Add the following lines to the near-top of the CMakeLists.txt file (make sure it's not in an indented part):

set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
Mrlinkwii commented 4 years ago

@PoroCYon like this ? image

Mrlinkwii commented 4 years ago
OpenGL: renderer: Mesa DRI Intel(R) HD Graphics 4000 (IVB GT2)
OpenGL: version: 4.2 (Core Profile) Mesa 20.0.8
ALSA lib pcm.c:8526:(snd_pcm_recover) overrun occurred
[Thread 0x7fffe00c9700 (LWP 262484) exited]
[New Thread 0x7fffe00c9700 (LWP 262678)]
OpenGL: renderer: Mesa DRI Intel(R) HD Graphics 4000 (IVB GT2)
OpenGL: version: 4.2 (Core Profile) Mesa 20.0.8
melonDS: pcm.c:3207: snd_pcm_area_copy: Assertion `src < dst || src >= dst + bytes' failed.
--Type <RET> for more, q to quit, c to continue without paging--c

Thread 12 "SDLAudioC3" received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffe3b1a700 (LWP 262478)]
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007ffff5dc2859 in __GI_abort () at abort.c:79
#2  0x00007ffff5dc2729 in __assert_fail_base
    (fmt=0x7ffff5f58588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x7ffff5c00560 "src < dst || src >= dst + bytes", file=0x7ffff5c05285 "pcm.c", line=3207, function=<optimised out>) at assert.c:92
#3  0x00007ffff5dd3f36 in __GI___assert_fail
    (assertion=0x7ffff5c00560 "src < dst || src >= dst + bytes", file=0x7ffff5c05285 "pcm.c", line=3207, function=0x7ffff5c02750 "snd_pcm_area_copy")
    at assert.c:101
#4  0x00007ffff5b92acf in snd_pcm_area_copy () at /lib/x86_64-linux-gnu/libasound.so.2
#5  0x00007ffff5b92cdc in snd_pcm_areas_copy () at /lib/x86_64-linux-gnu/libasound.so.2
#6  0x00007ffff5bd9aff in  () at /lib/x86_64-linux-gnu/libasound.so.2
#7  0x00007ffff5ba61dd in  () at /lib/x86_64-linux-gnu/libasound.so.2
#8  0x00007ffff5b91f2e in snd_pcm_avail_update () at /lib/x86_64-linux-gnu/libasound.so.2
#9  0x00007ffff5ba5fdc in  () at /lib/x86_64-linux-gnu/libasound.so.2
#10 0x00007ffff5b91f2e in snd_pcm_avail_update () at /lib/x86_64-linux-gnu/libasound.so.2
#11 0x00007ffff5bb23c5 in  () at /lib/x86_64-linux-gnu/libasound.so.2
#12 0x00007ffff5b96e92 in  () at /lib/x86_64-linux-gnu/libasound.so.2
#13 0x00007ffff5ba38d0 in snd_pcm_mmap_readi () at /lib/x86_64-linux-gnu/libasound.so.2
#14 0x00007ffff74d6326 in  () at /lib/x86_64-linux-gnu/libSDL2-2.0.so.0
#15 0x00007ffff742a8fd in  () at /lib/x86_64-linux-gnu/libSDL2-2.0.so.0
#16 0x00007ffff7479720 in  () at /lib/x86_64-linux-gnu/libSDL2-2.0.so.0
#17 0x00007ffff74f213d in  () at /lib/x86_64-linux-gnu/libSDL2-2.0.so.0
#18 0x00007ffff7562609 in start_thread (arg=<optimised out>) at pthread_create.c:477
#19 0x00007ffff5ebf103 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
(gdb) 

image

PoroCYon commented 4 years ago

I see no difference... did you pass -DCMAKE_BUILD_TYPE=Debug to the CMake command as well? You probably need to set this.

v1993 commented 4 years ago

@PoroCYon btw you can pass those flags as -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS_DEBUG='-fno-omit-frame-pointer -fsanitize=address' -DCMAKE_LINKER_FLAGS='-fno-omit-frame-pointer -fsanitize=address' instead of editing CMakeLists by hand.

v1993 commented 4 years ago

By the way, does issue still happen with JIT turned off?

PoroCYon commented 4 years ago

Yes

Mrlinkwii commented 4 years ago

how do i pass the the -DCMAKE_BUILD_TYPE=Debug into the cmake.txt

PoroCYon commented 4 years ago

You don't, you do that when running hte cmake command you used to generate the project files you use to compile melonDS with

Mrlinkwii commented 4 years ago

im sorry for not knowing this , is think ok or have i done it wrong image

edit : its after 1am for me , so ill probably continue this stuff tomorrow

PoroCYon commented 4 years ago

No, it's

mkdir cmake-build && cd cmake-build && cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS_DEBUG='-fno-omit-frame-pointer -fsanitize=address' -DCMAKE_LINKER_FLAGS='-fno-omit-frame-pointer -fsanitize=address' && make -j$(nproc)

(and fair enough, it's past 2 AM here)

Mrlinkwii commented 4 years ago

No, it's

mkdir cmake-build && cd cmake-build && cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS_DEBUG='-fno-omit-frame-pointer -fsanitize=address' -DCMAKE_LINKER_FLAGS='-fno-omit-frame-pointer -fsanitize=address' && make -j$(nproc)

(and fair enough, it's past 2 AM here)

@PoroCYon

i can compaile using that , but when it crashes it dosnet give me any new output , only when i close it myself , i do get LeakSanitizer: detected memory leaks

PoroCYon commented 4 years ago

Welp, then it's magic caused by space radiation. (meaning, I have no clue and this is going to be hard to debug)

ghost commented 3 years ago

I don't know if this is related as of current, but I have the same Assertion Failed error from alsa which is causing saving or loading states to crash melonDS (most of the time)