Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PPSSPP is not killed properly / hangs / blank when quit certain ways on iOS #9186

Open
jeeeyul opened this issue Dec 26, 2016 · 40 comments
Open

Comments

@jeeeyul
Copy link
Contributor

jeeeyul commented Dec 26, 2016

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.
@unknownbrackets
Copy link
Collaborator

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]

@jeeeyul
Copy link
Contributor Author

jeeeyul commented Jan 15, 2018

@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.

@RoJoHub
Copy link

RoJoHub commented Jan 29, 2018

I have encountered the same problem as yours.

How did you solve this problem?

Thanks!

@cuza
Copy link

cuza commented Mar 1, 2018

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

@hrydgard
Copy link
Owner

hrydgard commented Mar 1, 2018

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

@KentuckyCompass
Copy link
Contributor

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.

@Wowfunhappy
Copy link

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.

@Wowfunhappy
Copy link

Wowfunhappy commented May 15, 2018

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.

@unknownbrackets
Copy link
Collaborator

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

-[Unknown]

@Wowfunhappy
Copy link

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.

@Wowfunhappy
Copy link

Wowfunhappy commented May 20, 2018

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. :)

@unknownbrackets
Copy link
Collaborator

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]

@Wowfunhappy
Copy link

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

@Marskey
Copy link

Marskey commented Oct 23, 2018

the issue is till there.

@unknownbrackets
Copy link
Collaborator

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]

@Wowfunhappy
Copy link

Wowfunhappy commented Oct 25, 2018

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!

@Wh0ba
Copy link

Wh0ba commented Feb 12, 2019

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.

@fecking-sensei
Copy link

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.

@unknownbrackets unknownbrackets changed the title PPSSPP is not killed properly when user killed it from App Switcher PPSSPP is not killed properly / hangs / blank when quit certain ways on iOS Sep 8, 2019
@saagarjha
Copy link
Contributor

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?

@hrydgard
Copy link
Owner

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

@saagarjha
Copy link
Contributor

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

@hrydgard
Copy link
Owner

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

@saagarjha
Copy link
Contributor

Ok, I've created #12641.

@amurgshere
Copy link

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.

@unknownbrackets
Copy link
Collaborator

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]

@amurgshere
Copy link

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.

@saagarjha
Copy link
Contributor

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 :)

@unknownbrackets
Copy link
Collaborator

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

-[Unknown]

@saagarjha
Copy link
Contributor

No, that sends an immediate SIGKILL :(

@amurgshere
Copy link

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...

@saagarjha
Copy link
Contributor

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?

@Wowfunhappy
Copy link

Wowfunhappy commented May 31, 2020

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.

@amurgshere
Copy link

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.

@saagarjha
Copy link
Contributor

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

@saagarjha
Copy link
Contributor

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

@hrydgard
Copy link
Owner

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.

@unknownbrackets
Copy link
Collaborator

According to this it may actually be possible on iOS 14.2 to use jit again, and it seems it's possible to detect that version:
utmapp/UTM@07d7511

-[Unknown]

@hrydgard
Copy link
Owner

hrydgard commented Jan 2, 2021

Not sure exactly how, but JIT "just works" for me as-is when I deploy on an iOS 14 device from XCode on an M1 Air.

@unknownbrackets
Copy link
Collaborator

Well, does it still hang if you quit PPSSPP from outside PPSSPP? If we can detect it, maybe we can fix this (hang) issue for iOS 14.2+ users.

-[Unknown]

@saagarjha
Copy link
Contributor

The JIT should essentially work without doing anything special on A12+ devices. Anything older than that is going to be out of luck. This means the hang isn’t really an issue anymore, although we may want to turn off the exception server code for those cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests