[AC-6225] Titanium.Media.showCamera. will crash my app
GitHub Issue | n/a |
Type | Bug |
Priority | n/a |
Status | Resolved |
Resolution | Done |
Resolution Date | 2019-07-16T23:56:39.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | n/a |
Reporter | Peter Ladis |
Assignee | Shak Hossain |
Created | 2019-04-25T01:05:04.000+0000 |
Updated | 2019-07-16T23:56:39.000+0000 |
Description
Operating System
Name = Mac OS X
Version = 10.14.4
Architecture = 64bit
# CPUs = 12
Memory = 17179869184
Node.js
Node.js Version = 10.15.3
npm Version = 6.4.1
Titanium CLI
CLI Version = 5.1.1
Titanium SDK
SDK Version = 7.4.2.GA
SDK Path = /Users/peterladis/Library/Application Support/Titanium/mobilesdk/osx/7.4.2.GA
Target Platform = iphone
Steps to reporduce: On the device if I added a photo from the photo gallery all will work fine. If I attempt to call Titanium.Media.showCamera, it will work for 24 pictures, and fail on the 25th picture consistently.
Any ideas how to debug this?
Attachments
Hello, Thanks for reaching out! Are you using SDK 7.4.2.GA? Can you please try to open terminal and type: *appc ti sdk install latest.* After upgrading the SDK, please test the issue again on your device. If the error reproduces, share a simple test project demonstrate what you are trying?
I am on the latest...My app is super complex to give examples....But we have two code paths...one is for ADD photo and one is for TAKE PHOTO....we can add photos forever....but using the take function there seems to be a point of failure ( feels like memory). Once the camera is open..the app will freeze and then close. So....is there a way to free up memory when the show camera opens and closes?
Thanks for your feedback. Can you please make a simple test case? Call Ti.Media.showCamera and the camera opens up fine, takes the picture, click ok and check the app will freeze or not.
OK. here is sample code......Simple run on a device...take photos...after some time...the APP will crash when trying to open the Take Photo window. On my device it was around 20 photos var win = Ti.UI.createWindow({ title: 'TEST TAKE PHOTO', backgroundColor: '#fff' }); var view = Ti.UI.createView({ }) win.add(view); var tableview = Ti.UI.createTableView({ width:'100%', top:100 }) view.add(tableview) function addphotorow(file){ var row = Titanium.UI.createTableViewRow({ height:50, className:'pakrow', editable:false }); var imageView = Ti.UI.createImageView({ height:60, width:60 }); row.add(imageView); imageView.image = file.nativePath; tableview.appendRow(row); } var addPhoto = Ti.UI.createButton({title:'ADD',top:100,width:'90%',height:25}) view.add(addPhoto) addPhoto.addEventListener('click',function(done){ Titanium.Media.showCamera({ success:function(event) { // called when media returned from the camera Ti.API.info('Our type was: '+event.mediaType); if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) { var photo = event.media; if ( photo != null) { var num = Math.floor((Math.random()*10000)+1); fileName = num + '.png'; var currentFileName = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationCacheDirectory,fileName); if ( currentFileName.exists()) { currentFileName.deleteFile(); } currentFileName.write(photo); addphotorow(currentFileName) } } }, cancel:function() { // called when user cancels taking a picture }, error:function(error) { // called when there's an error var a = Titanium.UI.createAlertDialog({title:'Camera'}); if (error.code == Titanium.Media.NO_CAMERA) { a.setMessage('Please run this test on device'); } else { a.setMessage('Unexpected error: ' + error.code); } a.show(); }, saveToPhotoGallery:false, allowEditing:true, mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO] }); }) win.open()
Any thoughts?
first you can format your code in JIRA (see the help button in the bottom corner). Makes it easier to read and spot an error in your cancel function. Then I'm pretty sure that you run into memory problems since you are display all your big images in one screen. Even on my Android phone it is struggeling to show the images and you can see them appearing slowly. So what you need to do is resize then and display them (why displaying a high resolution image at 60x60) or use https://docs.appcelerator.com/platform/latest/#!/api/Titanium.App-event-memorywarning to check for memory warnings. Also try to run the Instruments (https://wiki.appcelerator.org/display/guides2/Managing+Memory+and+Finding+Leaks) to check your memory
I'll format....but this happens with just replacing the image....This does NOT happen with Add Photo from gallery. It feels as if TAKE PHOTO is loading into a memory space that I can't control or clean This is just a test app. In my real app..I Take photo...send the blob to my server and immediately delete. Still crashes after 20 or so I feel helpless here
So your example is not correctly. There you'll add rows to a Tableview, thats why I thought it might be reaching memory limit very soon. When you look at Instruments do you see an increase in memory that won't go away after a while? If so, then there might be a memory leak somewhere. Is it the same on Android? And which SDK are you using (version number, not just "latest")?
As stated above SDK Version = 7.4.2.GA This does NOT happen on android This does NOT happen on the simulator This has happened on various physical devices / iPhone 8 / iPhone X / iPads. This happens with just having one row, updating the image on the imageview, ...its as if the TAKE PHOTO is not clearing some internal memory store
7.4.2.GA is not latest! As Rakhi mentioned in the first post please update to the latest (use 7.5.2.GA or 8.0.0.GA). Not having a iOS device here to test that's why I've asked about Android. If it is only happening on iOS there might be some memory leak. Normally Android crashes quicker if there is a problem in Ti itself. Sorry but I can't debug it on iOS. But since the ticket is quiet new you'll need to wait a bit more and need to provide a different example that works more like your app. The TableView version from above is crashing on purpose. On the other hand: I have different apps that allow you to take pictures and upload them to a server without crashing. I'll resize the images before saving them
1. It happens on both 7.4.2 and 8.0.0. 2. Its not just taking a single picture.....its taking about 20 ( sometime around 25)....and when hitting Take Photo again....the IOS modal will open...freeze and crash the parent app I am reworking the code to not appendRows...to simply update an existing imageView control
var win = Ti.UI.createWindow({ title: 'TEST TAKE PHOTO', backgroundColor: '#fff' }); var view = Ti.UI.createView({ }) win.add(view); var tableview = Ti.UI.createTableView({ width:'100%', top:200 }) view.add(tableview) var row = Titanium.UI.createTableViewRow({ height:50, className:'pakrow', editable:false }); var imageView = Ti.UI.createImageView({ height:60, width:60 }); row.add(imageView); tableview.appendRow(row); function addphotorow(file){ imageView.image = file.nativePath; } var addPhoto = Ti.UI.createButton({title:'ADD',top:100,width:'90%',height:25}) view.add(addPhoto) addPhoto.addEventListener('click',function(done){ //Titanium.Media.showCamera Titanium.Media.showCamera({ success:function(event) { // called when media returned from the camera Ti.API.info('Our type was: '+event.mediaType); if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) { var photo = event.media; if ( photo != null) { var num = Math.floor((Math.random()*10000)+1); fileName = num + '.png'; var currentFileName = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationCacheDirectory,fileName); if ( currentFileName.exists()) { currentFileName.deleteFile(); } currentFileName.write(photo); addphotorow(currentFileName) currentFileName.deleteFile() } } }, cancel:function() { // called when user cancels taking a picture }, error:function(error) { // called when there's an error var a = Titanium.UI.createAlertDialog({title:'Camera'}); if (error.code == Titanium.Media.NO_CAMERA) { a.setMessage('Please run this test on device'); } else { a.setMessage('Unexpected error: ' + error.code); } a.show(); }, saveToPhotoGallery:false, allowEditing:true, mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO] }); }) win.open()
@micheal.. I tweaked the code to do the following... 1. Single Row with a single imageview 2. Take a photo....attached to imageview. 3. Delete original photo that I took After about 26 times.....CRASH
Michael, From what can be understood, is that each time a photo is taken, a copy of the photo is added to the /tmp (that will only be cleaned if the application is closed). I know that directory is supposed to be auto cleaned if it runs out of storage, but it seems that instead the application is being killed by the OS instead Please, with the latest code given try and add roughly 30 - 40 photos,WItHOUT killing the app in the process, at some point it should result in the code crashing (iOS only).
Hi Alec, I don't know anything about the iOS internals :-) But it sounds like a possible cause. Perhaps someone from the team can look into that direction. Still the example above is not working and styled correctly :-) I hope you don't mind that I'll add the example INCLUDING the permissions here:
also add this to the tiapp.xml
I didn't test it for the crash, but it is a example without the text error (inside cancel) and it asks for the permissions so the camera will open. Now it is up to Appc to test it ;-)
Thanks for you help. Honestly ive been using APPC for over 4 years...this seems like a pretty big issue.. My app is enterprise, used by a lot of users...and this is not being received positively in the field
[~peterladis], Thanks for your feedback.It looks like the sample code provided by you is not properly formatted. It would be great to share the correct code which will work for 24 pictures, and fail on the 25th picture consistently.
Rakhi....I dont understand what you're saying. This code works in my app. 1 The window pops open. 2. Click the button and the camera opens 3. Take photo and I set the image view 25 pictures and app closes
[~peterladis] that is what I was saying above. Your code as it is is not working because of !http://migaweb.de/ti_jira_code.png! the comment will remove the last } so the rest is broken (again: use the code formatting ;-) ) [~rmitro] I've added the correct code in my comment above where I removed that error and added the permissions so you could use and run it.
Thank for fixing that line of code ... but what I really want to focus on here is not my syntax...but the fact that the app is closing after too many images. Does NOT happen on android only TAKE photo on IOS. This is causing major issues for my customers
Any updates on this issue?
@Rakhi Mitro, I am experiencing the same issue for my application. What would need to speed getting this fix out a little faster?
[~peterladis], Tested the corrected sample code. Here are the tested steps: 1.The window pops open. 2. Click the ADD button and the camera opens 3. Take photo and anyhow photos are not displayed on image view. I took 25+ pictures and the app is not closing. Here are the console log:
@Rakhi. What version of your is your actual device, etc. We have about 50 people in the field experiencing the as well. You stopped at 25...but it could take 35 etc. ITs a memory leak so really depends on the status of your actual device. We are putting a video together for you
[~peterladis], Okay. Thanks for your feedback. We will be waiting for the video.
Here is a LINK to a video with TAKE PHOTO and it crashes https://www.dropbox.com/s/hx22v36rmbryazb/20190513_093259.mp4?dl=0 Here is a LINK to a video with ADD PHOTO and it does not crash https://www.dropbox.com/s/qvkxdxn73nb8wkd/20190513_102905.mp4?dl=0
Hello, Tested the issue using the sample code provided by the customer and unable to reproduce the issue. Test code:
*Test Steps:* 1.The window pops open. 2. Click the ADD button and the camera opens 3. Take photo and anyhow photos are not displayed on image view. I took 25+ pictures and there is no crash. Here are the console log:
It's tough to regenerate the issue by watching the video provided the reporter. [~jvennemann], Can you please take a look ?
Hello, we are testing your sample code and are not able to reproduce it on our end. let us know if there any steps we are missing? Thanks.
[~peterladis], please provide a crash report from the device which will help us to see what's going on since we can't seem to reproduce it yet.
Attached are some logs from Xcode
Hello [~peterladis], Are you still facing the issue? Can you try on the latest SDK 8.0.2.GA? Send us a trace log on the crash in here. Thanks.
Hello Sharif it appears as if SDK 8.0.2 has helped the issue. Before it would crash around 25 images....latest test ww where able to take 100 new images without any issues
Hello [~peterladis], Thanks for letting us know the update. We will close this ticket for now. Feel free to reach out anytime in the future.