mgba-emu / mgba

mGBA Game Boy Advance Emulator
https://mgba.io/
Mozilla Public License 2.0
5.72k stars 790 forks source link

Program crashes when controller plugged in #3070

Open spamzilla opened 12 months ago

spamzilla commented 12 months ago

Just what the title says...

endrift commented 12 months ago

You're going to need to give me more information. Like, a lot more information. If this happened for everyone with every controller on every OS, you can be sure it'd have been fixed by now.

Jaizu commented 11 months ago

Having the same issue here. It doesnt crash with my 8 Bit ultimate C controller but it does happen with my official switch pro controller when connected wired. mGBA Version: 0.10.2 Windows info: Edition Windows 11 Pro Version 23H2 Installed on ‎04/‎10/‎2023 OS build 22631.2715 Experience Windows Feature Experience Pack 1000.22677.1000.0 Computer info: Device name Porygon Processor AMD Ryzen 5 5600 6-Core Processor 3.50 GHz Installed RAM 32,0 GB Device ID B50EF6F1-7BE1-40FB-9BBC-B2EB6AF1EFB6 Product ID 00331-10000-00001-AA584 System type 64-bit operating system, x64-based processor Pen and touch No pen or touch input is available for this display

Edit: I also tested with stuff like Steam not opened to make sure nothing external was messing around with the controllers of my computer, same results. I wanted to test the pro controller wireless but I failed to find my bluetooth dongle lol

spamzilla commented 11 months ago

Sorry about the vague post. I believe my controller is this one: http://www.pc210.com/products/product_view.aspx?proid=430

FireSpike0 commented 11 months ago

Steps to reproduce: The bug (or a similar one) also occurs on Linux (NixOS in my case, using the package from Nixpkgs). In my case, it happens in the following situation:

  1. Controller is plugged in, mGBA is started.
  2. A game is started and running (which could be an important part of information).
  3. The controller is disconnected during the game.
  4. The game continues to run.
  5. The controller is reconnected and the player LEDs are blinking.
  6. The game immediately freezes and mGBA becomes unresponsive.
  7. mGBA crashes.

The bug does not immediately appear, but rather requires (when reproducing in a games title screen) a variable amount (un-)plugs of the controller to occur (but sometimes a single (un-)plug is enough).

And before somebody asks: No, I'm disconnecting my controller on purpose during the game, rather my controller is old and has a loose contact which results in short disconnects during the usage. In one case, it seemed (not entirely sure though) that mGBA crashed instantly after disconnecting the controller.

Additional information: Before crashing, mGBA is unresponsive for a moment. After about 5 seconds, it crashes without any error message at all and just disappears. Starting it from the commandline and looking at the output after the crash hints, that mGBA has a segfault in this case:

QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined
QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined
QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined
[1]    19405 segmentation fault (core dumped)  mgba-qt

Information about my setup / system: mGBA version: 0.10.2 OS: NixOS Unstable, 64 Bit AMD64 / x86_64 CPU: Intel(R) Core(TM) i3 CPU M370, 4 cores with 2.40GHz each

If this seems to be another issue, I'll create a new issue. But at the moment it looks like it could probably be the same issue.

FireSpike0 commented 10 months ago

@spamzilla @Jaizu Was a game already running when mGBA crashed? If yes, it could probably prove my theory...

I just took another look into it and threw gdb on it; I guess (in my case) the problem occurs through the invalidated reference when disconnecting the controller / the incompletely initialized reference when newly connecting a controller while the inputs are polled. At least thats's what I think could be the problem:

#0  0x0000000000000000 in ?? ()
#1  0x00000000005428e5 in QGBA::InputController::pollEvents (this=0xa288a8)
    at /home/user/Repositories/mgba/src/platform/qt/InputController.cpp:350
#2  0x00000000004f1503 in QGBA::CoreController::updateKeys (this=this@entry=0xbe2ea0)
    at /home/user/Repositories/mgba/src/platform/qt/CoreController.cpp:1207
#3  0x00000000004f48b5 in QGBA::CoreController::finishFrame (this=0xbe2ea0)
    at /home/user/Repositories/mgba/src/platform/qt/CoreController.cpp:1254
#4  0x00007ffff79072ac in GBAFrameEnded (gba=0x7fffbc002000)
    at /home/user/Repositories/mgba/src/gba/gba.c:974
#5  0x00007ffff792ac8f in _startHdraw (timing=<optimized out>, context=0x7fffbc002c90, 
    cyclesLate=0) at /home/user/Repositories/mgba/src/gba/video.c:181
#6  0x00007ffff78a02e2 in mTimingTick (timing=timing@entry=0x7fffbc003960, 
    cycles=cycles@entry=215) at /home/user/Repositories/mgba/src/core/timing.c:106
#7  0x00007ffff7905a7a in GBAProcessEvents (cpu=0x7fffbc69d000)
    at /home/user/Repositories/mgba/src/gba/gba.c:316
#8  0x00007ffff789f179 in _mCoreThreadRun (context=0xbe2eb0)
    at /home/user/Repositories/mgba/src/core/thread.c:339
#9  0x00007ffff3ca3084 in start_thread ()
   from /nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-glibc-2.38-27/lib/libc.so.6
#10 0x00007ffff3d2560c in clone3 ()
   from /nix/store/9y8pmvk8gdwwznmkzxa6pwyah52xy3nk-glibc-2.38-27/lib/libc.so.6

And even if my guess is incorrect, there's probably additional useful information about the bug.

endrift commented 10 months ago

Pulling this into 0.10.3 since it seems more widespread than I'd originally expected.

endrift commented 10 months ago

I am unable to reproduce a crash on 0.10.2, at least on Linux. I can, however, reproduce a crash on disconnect on master that I'm looking into now.

endrift commented 10 months ago

I have fixed the crash on master. I'll look at 0.10.2 on Windows soon.

endrift commented 10 months ago

Try as I might, I can't reproduce this on Windows 10 with 0.10.2. Can I get precise reproduction steps?

FireSpike0 commented 8 months ago

Is the fix for the crash incorporated in the current 0.10.3 release? If yes, the bug is not fixed on version 0.10.3 on NixOS. If not, I would compile the master branch on my machine and test it. In any case: Thanks for looking into it so far :)

endrift commented 8 months ago

If it were, this bug would have been closed. I don't have a repro case for the 0.10.2 crash. The fix on master is for a different crash that only existed on master. That said, the backtrace you posted doesn't seem to be for 0.10.2--that line isn't in that function on that version.