Ppsspp: PPSSPP is not killed properly / hangs / blank when quit certain ways on iOS

Created on 26 Dec 2016  Â·  36Comments  Â·  Source: hrydgard/ppsspp

Symptoms:

When kills the PPSSPP from iOS App Switcher, It is not terminated properly. After this happens, Launching again PPSSPP from SpringBoard causes making iPhone unresponsive until reboot. When I sent Kill Signal by Xcode(when the app is launched without debug executable option), PPSSPP on my iPhone just freeze, not terminated.

Environment:

  • PPSSPP 1.3 to master(15 Jan, 2018)
  • iOS 10.2 to 11.2.5b, iPhone7 (No JB)

Steps to Reproduce:

  1. Launch PPSSPP. (What if you launch this with Xcode, "Debug executable option" form Scheme must be turned off to reproduce real usage scenario)
  2. Tap Home Button to exit to Spring Board.
  3. Double Tap Home Button to enter the App Switcher.
  4. Kill the PPSSPP.
  5. In this phase, PPSSPP is actually not killed properly. (User can't figure out what happened in this phase since there is no successful termination feedback on iOS).
  6. Launch PPSSPP again.
  7. iPhone gets unresponsive.

Small clues that I found:

  • When terminate PPSSPP from PPSSPP main menu, the problem never happens.
  • When I commented out syscall(SYS_ptrace, 0 /*PTRACE_TRACEME*/, 0, 0, 0); that simulates debug so enable JIT at Main.mm, the problem is not happens also. I think that this problem could be related with JIT.
Platform-specific (iOS)

Most helpful comment

We could also add location tracking to keep running in the background.

All 36 comments

Did #10489 help this?

Note: the build bot is not working right now and the version of PPSSPP for iOS on there does not include those changes. Currently it's necessary to build it yourself.

-[Unknown]

@unknownbrackets I just did build it with latest commit and test it. But there was no luck.

I just wrote custom version of PPSSPP to avoid this problem for my own use:

  1. Disabled multi task capability of PPSSPP.
  2. I did implement Auto Save on termination. And I triggered safe exit. exit(0)
  3. And I using builtin load last saved state automatically option.

What if somebody can prove that there is no way to fix this problem, I will contribute my code.

I have encountered the same problem as yours.

How did you solve this problem?

Thanks!

@jeeeyul I got the latest one in my iOS 11 JB device and had same issue. Can you share your fix??

@KentuckyCompass didn't you make a fix for this?

No, actually my fix was for shutting down when the exit button is tapped in the app. Hanging when killed while in the background is a known bug that I haven't found a good fix for yet.

The two options I know would work so far are:

  1. Stop using ptrace to simulate a debugger to allow JIT on iOS. This means no more JIT, but the app responds well to being killed in the background.
  2. jeeyul's solution: stop supporting background and instead shutdown completely whenever closed and restore state when reopened.

I'm still not sure why this happens. I haven't had time to investigate it fully.

jeeyul's solution: stop supporting background and instead shutdown completely whenever closed and restore state when reopened.

This would absolutely be my preference. Much better than having to reboot my phone in order to use PPSSPP again, because I forgot to exit cleanly last time and the app was killed in the background.

This has gotten even worse in the latest version! Manually pressing "exit" in the UI _also_ causes the app to freeze, which means you basically have to reboot your phone every time you want to use PPSSPP.

@jeeeyul If you still have code for that workaround, this would be a great time to submit it, as it has ben six months and no better solution has presented itself.

Is it possible to identify which version made it worse? If we know what made it worse maybe we can make it better.

-[Unknown]

I don't know of a good way to bisect versions on Jailbroken iOS.

However, I think it almost doesn't matter? We know the solution, jeeeyul even says he coded it: the app needs to save its state and then exit safely whenever it leaves the foreground.

The old "solution" of manually hitting the exit button was better than what we have now, but still far less than ideal, as it doesn't conform to the way we've been trained to use our phones. And if you accidentally multitask and PPSSPP gets killed in the background, it's too late—you need to reboot your phone to start up the app again.

I was too quick to label this a regression. The exit button works properly sometimes, maybe every two out of three tries. That still means that one third of the time, I have to reboot my phone before I can play PPSSPP again, but it's better than nothing.

I'm still hoping this can be looked into further at some point, especially since we largely know how to resolve the problem. :)

jacksonpan reported seeing a graphicsContext shutdown crash on IRC. Could be there's a bug (we had several on Android) causing that. If it doesn't crash every time, but only some of the time, that may explain why you're seeing Exit not work consistently as a workaround for this issue.

It'd really help to have / see a stack trace of the crash.

-[Unknown]

If you can provide instructions on how to obtain a stack trace, I'd be happy to help. It's very easy to reproduce.

the issue is till there.

Apparently iOS 12 fixes the iOS bug that allowed jit to work, so there's probably no longer a reason (at least on iOS 12, not sure if it can be detected) to do the syscall that causes this behavior anymore.

So, the solace to the poor battery life and occasional FPS drops will at least be quitting PPSSPP will work fine...

-[Unknown]

Apparently iOS 12 fixes the iOS bug that allowed jit to work, so there's probably no longer a reason (at least on iOS 12, not sure if it can be detected) to do the syscall that causes this behavior anymore.

So, the solace to the poor battery life and occasional FPS drops will at least be quitting PPSSPP will work fine...

-[Unknown]

With no iOS 12 Jailbreak on the Horizon, a lot of people are still on iOS 11. Please don't kill JIT!

@jeeeyul If you're still alive I would still really like your fix!

Did anyone find a solution ?
I cannot use PPSSPP on ios becuse of this
I have to reboot everytime i try to open it
Can someone build it with the fix reported by @jeeeyul ?
Which is stop supporting background and instead shutdown completely whenever closed and restore state when reopened.

I’m running jailbroken iOS 12.4 (unc0ver) on an iPhone X, and this issue is still happening with both stable and experimental builds. Sometimes, tapping the “exit” button safely kills the app, other times, it doesn’t. Rebooting and re-jailbreaking the phone makes PPSSPP work again.
If anyone could suggest a fix, I’d appreciate it.

Hi, sorry for butting in but I think I have a slightly better solution for this problem than what PPSSPP is doing right now, which I have made available in my fork. I'd like to file a pull request but I'm unsure how to build or test the app; should I just be running cmake -DCMAKE_TOOLCHAIN_FILE=./cmake/Toolchains/ios.cmake -DIOS_PLATFORM=OS -DCMAKE_IOS_SDK_ROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -H. -Bbuild.ios -GXcode from the root directory of the project?

./b.sh --ios (or similar, look in the script) doesn't work for you?

I'm stupid, it does of course. I forgot to grab the submodules :(

Okay. Happy to accept a PR with those changes :)

Ok, I've created #12641.

This issue still occurs for me on iPadOS 13.4.1 on iPad Pro (not jail broken), if I kill PPSSP using task switcher, if it goes to the background and gets killed for any other reason, or if the emulator crashes (getting some crashes when playing Killzone Liberation) And I have to kill it for that reason. I then have to reboot the iPad otherwise all I get when loading PPSSPP is a black screen. Is there anything we can do to try and help you fix this issue? Thanks.

For any looking for a fix to this bug:

The root problem is that Apple forbids jit and we're using an iOS bug to make jit work anyway. That bug has other downsides, and it seems like they may be unavoidable.

The easiest way to "fix" this bug would obviously be to remove the code that triggers the iOS bug, and prevent iOS users from using jit at all. Quitting would then work just fine. But some games would run slower, and games would probably use up battery power faster.

Currently, the iOS bug is triggered early in PPSSPP's startup. Maybe it's possible to make this happen later, after settings have been loaded. Then a user could at least choose if they want the "fast and longer battery life" mode that triggers iOS bugs in app quit, or the "slow and battery consuming" mode that quits fine. Not that it's a great choice, but neither option is ideal.

Maybe there's also some way to intercept swipes and do something to prevent the bug, although I think people have already tried to look into this.

Just so people don't spam me personally to do the above: I don't have an iOS device, and fighting Apple doesn't sound as interesting as making PPSSPP run better on platforms where it's welcome (every other platform.) If Apple wants to sell me a device, they should change their policies on what apps are allowed.

But if anyone has code questions about where PPSSPP decides to use jit or what happens normally on shutdown, I'm happy to answer them.

-[Unknown]

Thanks for this info, it would be great if you could add an option in the future for the IOS version to please disable JIT, at least then we have the option to turn it off if this problem comes up too often, realising that if it is turned on at any point since that device booted you would still run into the same problem occurring if I am understanding the problem correctly... thanks.

FWIW, you don't have to enable the JIT at startup; you can do it at any point right before you actually try to JIT, so making this a setting where you can choose before playing a game should be possible. Do note that once you have enabled the JIT and PPSSPP is killed by the OS for any reason you will hit this bug and not be able to fix it without rebooting. This includes iOS deciding to SIGKILL the app while it's in the background or if you swipe up on it to do the same thing. (For the latter one: you have full control over this; I don't see why you would keep doing it unless you don't want to be able to use the app anymore. It is a 100% guaranteed way to get the app to become nonfunctional. If you really want it gone from your app switcher, IIRC there's a button that lets you quit the app; use that.)

Ideally you should not hit this bug if you are using the app and it just crashes; if this happens to you I would love to hear about it :)

Are we able to know that the user swiped and intentionally crash?

-[Unknown]

No, that sends an immediate SIGKILL :(

The main problem for me is that PPSSPP is hanging a lot in Killzone and occasionally in other games (not crashing but actually locking up) and the only option I have is to kill PPSSPP which then requires me to reboot the device to reopen PPSSPP again...

Oh, if it is hanging then yes there is nothing that will catch that. I wonder if it would be feasible to try to not hang the main thread so the exit UI is still responsive, or add some sort of watchdog to kill the app when a hang is detected?

Another really helpful workaround would be to cleanly close PPSSPP whenever it receives an applicationDidEnterBackground event (possibly alongside making a save state).

This means you can't multitask—but you can't do that safely anyway, since you can never be sure when iOS will close PPSSPP.

Another really helpful workaround would be to cleanly close PPSSPP whenever it receives an applicationDidEnterBackground event (possibly alongside making a save state).

This means you can't multi-task—but you can't do that safely anyway, since you can never be sure when iOS will close PPSSPP.

Probably wouldn’t help my situation as the emulator is actually locking up, but saagarjha’s solution of ensuring you can still close the application or close the emulation when the emulator code locks would definitely solve my problems as I wouldn’t need to kill PPSSPP in the first place then.

We could also add location tracking to keep running in the background.

Apple seems to have solved this problem for us in iOS 14 by making the W^X JIT technique no longer work :/

Alright, so at some point we should just remove all of the workarounds and stick to the IR JIT.. newer devices are pretty much fast enough for that anyway. Still, disappointing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Saramagrean picture Saramagrean  Â·  6Comments

joelolopez picture joelolopez  Â·  3Comments

ultrasuper19 picture ultrasuper19  Â·  4Comments

fahadfoyjur picture fahadfoyjur  Â·  5Comments

oatmeal picture oatmeal  Â·  6Comments