-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Android app restarts after capturing an image #73
Comments
I've checked some logs and peeked at all occurrences of 'crash' but didn't see anything useful. This issue with A10 devices has been brought to my attention a couple of times and my assumption hasn't changed since then:
You said that the app sometimes restarts after 2 shots but sometimes after only a single shot. If the issue was related to a code I wrote, the app would always restart after the first shot. I don't think you can resolve this OS-related problem. You will have to use a solution that renders the camera inside Unity (i.e. one that doesn't launch native camera apps). One example is NatDevice (I haven't used it myself). |
Thanks for the reply @yasirkula ! That's really unfortunate. Thanks for the NatDevice recommendation, we were already using it but upgraded to this addin because we needed to be able to use the device flash. This issue is so frustrating, I've been stuck on it for many days now, and it makes no sense to me that the app is being forced closed by the OS even when there are no other apps running and I'm testing on the most basic of Unity apps. The camera intent should never be this intensive on the OS. |
I unfortunately can't think of any other reasons. I find it unlikely that it is something else because otherwise the app would always restart after the first shot, IMHO. |
Hello, first of all thank you for the great plugin. 2021-11-16 14:39:00.057 791-791/? E/lowmemorykiller: Error writing /proc/2543/oom_score_adj; errno=22 Is there any help you could provide? I saw the oom_score_adj is the value to determine if the process should be killed when low on memory, is there anywhere I could set this value? |
In my previous investigations, I didn't find a way to change that value (oom_score_adj) but can't say with full certainty that there isn't a way. The only reliable way to resolve your issue would be to use a different plugin which renders camera controls inside Unity so that you won't be leaving Unity at all. I don't know if there is such a plugin which is free. |
Hello Mr. Yasirkula. Same here on take a photo: 11-25 11:58:05.641 6556 6654 I Unity : Just in case... Thank's for all your plugins :) |
If you can't reproduce this issue at every attempt or after restarting the phone, it is also likely memory issue. |
Yeah when it's completely random, it's a good indication that it's a memory issue. Either device has low RAM or the game is consuming too much RAM already. |
Although your device has 4 GB RAM, it might be consumed by a lot of other apps and the OS itself. OS might also be preserving some of this 4 GB RAM for high priority OS tasks. If this issue isn't related to memory, then I have absolutely no idea what the cause of the issue is :D Native logs give no insight about the issue. I don't know the crop function you've mentioned. |
This "crop function" |
I'm assuming this is my Image Cropper plugin (nice UI retouch BTW). After cropping the Texture retrieved via NativeCamera, you can |
:) .. yes indeed. I'm big fan of yours plugins. Ok. the thing is.. for some weird situation, this "Image Cropper" is called after a NativeCamera.TakePicture event. So I tested deleting the pluging of Image Cropper and "magic happens".. stopped showing after NativeCamera.TakePicture. Also I also set the "maxSize" value to "512" (prev: SystemInfo.maxTextureSize) and the crashed occurs after a third attempt.
I'll keep searching how reduce memory consumption. Thnks for all. |
Reducing maxSize is a good optimization 👍 If your app needs an image cropper, I don't think you should delete it from the project. Does reducing maxSize even further to 32 (for testing purposes) prevent crashes? |
Hello again, As always, thank you very much for the plugin and any help you can provide! p.s.: I found this page while searching for solutions: https://dontkillmyapp.com/problem |
On Android, the path is probably a combination of Application.temporaryCachePath and IMG_camera.jpg: Line 55 in 5f57882
On iOS:
UnityNativeCamera/Plugins/NativeCamera/NativeCamera.cs Lines 137 to 149 in 5f57882
|
Thank you very much for your quick and helpful reply! I'm trying to find solutions online however unity seems to have basically no documentation on temporary cache path, which seems to be the same as the persistent data path, with the difference being the last folder is called "files" instead of "cache" |
I see. On Android, instead of Application.temporaryCachePath, try this: using( AndroidJavaObject unityClass = new AndroidJavaClass( "com.unity3d.player.UnityPlayer" ) )
using( AndroidJavaObject context = unityClass.GetStatic<AndroidJavaObject>( "currentActivity" ) )
{
string cachePath = context.Call<string>( "getCacheDir" );
} |
Max Size unfortunately can't resolve this issue because the app is restarted before that. NativeCamera simply uses more system resources (RAM) than NativeGallery which is why it's more possible for it to trigger the app restart. Since this restart is triggered by the operating system automatically, I don't believe that it can be resolved. |
if you know another camera package or unity camera example then please share with me |
Haven't researched it recently so there may be free alternatives. A paid alternative is NatDevice, it renders the camera inside Unity so it won't suffer from this issue. |
hello @yasirkula i have one question if app is crash after take photo then not automatic open app again. but in this case take photo in android then app is automatic restart. if you have any idea about this then let me know |
Yes app doesn't crash but restarts in this scenario. If your app doesn't restart and you see a popup saying that the app has crashed, then that's another issue and you should check logcat logs to see what happened. |
yes exactly my app is not crashing. but is restarting so i ask you any another issue or not. if you know any solution then please let me know it's very important for me. i am finding log and all last 5 days but didn't getting any proper reason for restart app after capture photo from camera |
That's the same issue. You can check out this discussion to learn more about it. |
please check this log i am getting from logcat. also i add permission and testing but still same issue. E/Util: writeImageDataToRequestedUri : failed to make directory or the directory already existed. |
If camera encounters a fatal exception, either the Unity app should crash completely or Unity app should resume as normal. When it restarts, it isn't caused by an exception, unfortunately we can't do anything to prevent this from happening. Operating system is responsible for that restart. That's how Android ecosystem's Activity lifecycle works. You can verify this by testing your app on a more powerful phone, it won't restart there. |
sometime same issue fetching on image or video pick using native Gallery. i am checking on 8GB RAM and 124GB Storage but sometime app restart after pick video or image. only on android device if you have any idea why app is restart. i have try lost of solution but didn't getting proper solution. if you have any idea then please let me help to solve this issue |
The words "sometimes" and "restart" strongly indicate the same problem. That device must have a lot of background tasks and the OS must be reserving a very small amount of RAM per app that it encounters all those restarts. I would recommend simply accepting this limitation because it's out of our hands. |
Hi, first of all thanks for your grate work! |
I haven't used this property, but: https://docs.unity3d.com/ScriptReference/Application-lowMemory.html Also on Android, there is Adaptive Performance Package which I've also not used. |
Hi, same situation here. It happens in every single device with Android 13 that I tried, is there any walk around? The lowMemory trigger never fires, I tried with largeHeap and is the same situation. |
Then I think lowMemory requires Unity activity to have focus. There might be two cases for other apps:
|
Not related to Unity, but while developing an android app using jetpack compose, launched the native camera app multiple times to collect photos and found the same app restarting. I'm testing on a Galaxy Tab Active Pro. I was sure I wasn't doing anything wrong, really thanks yasirkula for discussing and explaining this behavior. As explained here I will change the way I handle the camera to not launch native one. And again thanks! |
I'm having the same issue, my activity restarts but my app doesn't crash, and i can't see anything in logs... |
This issue is "Won't Fix" for the foreseeable future since there isn't a solution to this according to my research. |
Description of the bug
This issue is happening on Galaxy Tab A and Android A10 devices which a massive portion of our user base have. I've added a video of the issue but in summation after you capture an image and click 'Ok', it restarts the application instead of resuming when coming back from the Intent.
Reproduction steps
Capture an image, after clicking 'Ok' app restarts. This most of the time happens after 1 photo is taken but some times it only occurs after multiple images are captured in a row.
Platform specs
Please provide the following info if this is a Unity 3D repository.
Additional info
Video of Issue
https://user-images.githubusercontent.com/20043989/125259570-b966ec00-e2ff-11eb-8409-377edf728e3c.mp4
LogCat, search for 'START NATIVE CAPTURE' in log
logcat.txt
The text was updated successfully, but these errors were encountered: