Titanium JIRA Archive
Appcelerator Community (AC)

[AC-6225] Titanium.Media.showCamera. will crash my app

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionDone
Resolution Date2019-07-16T23:56:39.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterPeter Ladis
AssigneeShak Hossain
Created2019-04-25T01:05:04.000+0000
Updated2019-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

FileDateSize
BJGNx7LYHhlNEPercIGJCq.xccrashpoint.zip2019-05-20T12:39:10.000+0000129673
BqXELeolCHt9kjPiUMm_SS.xccrashpoint.zip2019-05-20T12:39:10.000+000028849
CMuGaHWQ3C5WLvk0FD2SjK.xccrashpoint.zip2019-05-20T12:39:10.000+000025442

Comments

  1. Rakhi Mitro 2019-04-25

    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?
  2. Peter Ladis 2019-04-25

    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?
  3. Rakhi Mitro 2019-04-28

    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.
  4. Peter Ladis 2019-04-30

    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()
  5. Peter Ladis 2019-05-01

    Any thoughts?
  6. Michael Gangolf 2019-05-01

    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
  7. Peter Ladis 2019-05-01

    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
  8. Michael Gangolf 2019-05-01

    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")?
  9. Peter Ladis 2019-05-01

    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
  10. Michael Gangolf 2019-05-01

    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
  11. Peter Ladis 2019-05-01

    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
  12. Peter Ladis 2019-05-01

    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()
  13. Peter Ladis 2019-05-01

    @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
  14. alec@lilypad.co 2019-05-01

    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).
  15. Michael Gangolf 2019-05-01

    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:
        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)
        
        function 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() {},
        		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]
        	});
        
        }
        
        addPhoto.addEventListener('click', function(done) {
        	var map = {};
        	map[Ti.Media.CAMERA_AUTHORIZATION_AUTHORIZED] = 'CAMERA_AUTHORIZATION_AUTHORIZED';
        	map[Ti.Media.CAMERA_AUTHORIZATION_DENIED] = 'CAMERA_AUTHORIZATION_DENIED';
        	map[Ti.Media.CAMERA_AUTHORIZATION_RESTRICTED] = 'CAMERA_AUTHORIZATION_RESTRICTED';
        	map[Ti.Media.CAMERA_AUTHORIZATION_NOT_DETERMINED] = 'CAMERA_AUTHORIZATION_NOT_DETERMINED';
        
        	var cameraAuthorization = Ti.Media.cameraAuthorization;
        
        	if (cameraAuthorization === Ti.Media.CAMERA_AUTHORIZATION_RESTRICTED) {
        		return;
        	} else if (cameraAuthorization === Ti.Media.CAMERA_AUTHORIZATION_DENIED) {
        		return;
        	}
        	Ti.Media.requestCameraPermissions(function(e) {
        		if (e.success) {
        			showCamera();
        		}
        	});
        
        })
        
        win.open()
        
    also add this to the tiapp.xml
        <key>NSCameraUsageDescription</key>
        <string>Use camera</string>
        
    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 ;-)
  16. Peter Ladis 2019-05-03

    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
  17. Rakhi Mitro 2019-05-04

    [~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.
  18. Peter Ladis 2019-05-05

    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
  19. Michael Gangolf 2019-05-05

    [~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.
  20. Peter Ladis 2019-05-05

    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
  21. Peter Ladis 2019-05-07

    Any updates on this issue?
  22. alec@lilypad.co 2019-05-08

    @Rakhi Mitro, I am experiencing the same issue for my application. What would need to speed getting this fix out a little faster?
  23. Rakhi Mitro 2019-05-10

    [~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:
        
        [INFO] :   symbols: /Users/sharifabudarda/Documents/Appcelerator_Studio_Workspace/project1/build/iphone/build/Products/Debug-iphoneos/project1.app.dSYM
        Please manually launch the application
        [INFO] :   project1/1.0 (0.0.0.(null))
        [INFO] :   project1 1.0 (Powered by Titanium 8.0.0.3726240fa2)
        [INFO] :   ACA started
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        
  24. Peter Ladis 2019-05-10

    @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
  25. Rakhi Mitro 2019-05-13

    [~peterladis], Okay. Thanks for your feedback. We will be waiting for the video.
  26. Peter Ladis 2019-05-13

    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
  27. Rakhi Mitro 2019-05-14

    Hello, Tested the issue using the sample code provided by the customer and unable to reproduce the issue. Test code:
        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);
         
        function 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() {},
        		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]
        	});
         
        }
         
        addPhoto.addEventListener('click', function(done) {
        	var map = {};
        	map[Ti.Media.CAMERA_AUTHORIZATION_AUTHORIZED] = 'CAMERA_AUTHORIZATION_AUTHORIZED';
        	map[Ti.Media.CAMERA_AUTHORIZATION_DENIED] = 'CAMERA_AUTHORIZATION_DENIED';
        	map[Ti.Media.CAMERA_AUTHORIZATION_RESTRICTED] = 'CAMERA_AUTHORIZATION_RESTRICTED';
        	map[Ti.Media.CAMERA_AUTHORIZATION_NOT_DETERMINED] = 'CAMERA_AUTHORIZATION_NOT_DETERMINED';
         
        	var cameraAuthorization = Ti.Media.cameraAuthorization;
         
        	if (cameraAuthorization === Ti.Media.CAMERA_AUTHORIZATION_RESTRICTED) {
        		return;
        	} else if (cameraAuthorization === Ti.Media.CAMERA_AUTHORIZATION_DENIED) {
        		return;
        	}
        	Ti.Media.requestCameraPermissions(function(e) {
        		if (e.success) {
        			showCamera();
        		}
        	});
         
        })
         
        win.open();
        
    *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:
        Please manually launch the application
        [INFO] :   project1/1.0 (0.0.0.(null))
        [INFO] :   project1 1.0 (Powered by Titanium 8.0.0.3726240fa2)
        [INFO] :   ACA started
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        [INFO] :   Our type was: public.image
        -- End application log -------------------------------------------------------
        
        
    It's tough to regenerate the issue by watching the video provided the reporter. [~jvennemann], Can you please take a look ?
  28. Sharif AbuDarda 2019-05-14

    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.
  29. Jan Vennemann 2019-05-17

    [~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.
  30. Peter Ladis 2019-05-20

    Attached are some logs from Xcode
  31. Sharif AbuDarda 2019-07-13

    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.
  32. Peter Ladis 2019-07-13

    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
  33. Sharif AbuDarda 2019-07-16

    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.

JSON Source