{ "id": "93075", "key": "TIMOB-9492", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "13505", "description": "Release 3.0.0", "name": "Release 3.0.0", "archived": true, "released": true, "releaseDate": "2012-12-14" }, { "id": "14126", "description": "Sprint 2012-19 Core", "name": "Sprint 2012-19 Core", "archived": true, "released": true, "releaseDate": "2012-09-24" }, { "id": "14271", "description": "2012 Sprint 19", "name": "2012 Sprint 19", "archived": true, "released": true, "releaseDate": "2012-09-24" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2013-07-16T09:39:27.000+0000", "created": "2012-06-11T17:44:43.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "core", "module_media", "qe-testadded" ], "versions": [ { "id": "13271", "description": "Release 2.1.0", "name": "Release 2.1.0", "archived": false, "released": true, "releaseDate": "2012-06-29" }, { "id": "13272", "description": "Release 2.0.1", "name": "Release 2.0.1", "archived": true, "released": true, "releaseDate": "2012-04-16" } ], "issuelinks": [], "assignee": { "name": "mstepanov", "key": "mstepanov", "displayName": "Max Stepanov", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2013-07-16T09:39:27.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "h2. Problem description\r\nA function defined inside an event listener, without an external reference, fails to be invoked after a few calls.\r\n\r\nh2. Steps to reproduce and sample code:\r\n1. Run the sample code below.\r\n2. Launch app, tap \"Open Camera\" button.\r\n3. Tap \"Take Photo\" button, alert displays for success callback it's correctly triggered.\r\n4. Tap \"Take Photo\" button again and repeat multiple times to simulate taking photo photos in succession. Success callback does not fire.\r\n5. Tap \"Close Camera\" button, camera does not close.\r\n\r\n{code}\r\nvar win = Ti.UI.createWindow({\r\n\tbackgroundColor: '#efefef',\r\n\ttitle: 'Test'\r\n});\r\n\r\nopenCameraButton = Ti.UI.createButton({\r\n\tstyle: Ti.UI.iPhone.SystemButtonStyle.BORDERED,\r\n\ttitle: 'Open Camera'\r\n});\r\n\r\nopenCameraButton.addEventListener('click', function(e) {\r\n\tvar cameraOverlay = Ti.UI.createView();\r\n\t\r\n\tvar takePhotoButton = Ti.UI.createButton({\r\n\t\tbackgroundColor: '#fff',\r\n\t\tbackgroundSelectedColor: '#efefef',\r\n\t\tborderColor: '#000',\r\n\t\tborderRadius: 17,\r\n\t\tborderWidth: 1,\r\n\t\tbottom: 65,\r\n\t\tcolor: '#000',\r\n\t\theight: 34,\r\n\t\topacity: 0.4,\r\n\t\ttitle: 'Take Photo',\r\n\t\twidth: 100\r\n\t});\r\n\t\r\n\tvar closeCameraButton = Ti.UI.createButton({\r\n\t\tbackgroundColor: '#fff',\r\n\t\tbackgroundSelectedColor: '#efefef',\r\n\t\tborderColor: '#000',\r\n\t\tborderRadius: 17,\r\n\t\tborderWidth: 1,\r\n\t\tbottom: 65,\r\n\t\tcolor: '#000',\r\n\t\theight: 34,\r\n\t\topacity: 0.4,\r\n\t\tright: 10,\r\n\t\ttitle: 'Close Camera',\r\n\t\ttop: 10,\r\n\t\twidth: 150\r\n\t});\r\n\t\r\n\ttakePhotoButton.addEventListener('click', function(e) {\r\n\t\tTi.Media.takePicture();\r\n\t});\r\n\t\r\n\tcloseCameraButton.addEventListener('click', function(e) {\r\n\t\talert('closing camera');\r\n\t\tTi.Media.hideCamera();\r\n\t});\r\n\t\r\n\tcameraOverlay.add(takePhotoButton);\r\n\tcameraOverlay.add(closeCameraButton);\r\n\t\r\n\tTi.Media.showCamera({\r\n\t\tsuccess: function(e) {\r\n\t\t\talert('success callback');\r\n\t\t},\r\n\t\tcancel: function() {\r\n\t\t\tTi.API.info('cancel callback');\r\n\t\t},\r\n\t\terror: function(e) {\r\n\t\t\tTi.API.info('error callback');\r\n\t\t},\r\n\t\tallowEditing: false,\r\n\t\tanimated: false,\r\n\t\tautohide: false,\r\n\t\tmediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO],\r\n\t\toverlay: cameraOverlay,\r\n\t\tsaveToPhotoGallery: false,\r\n\t\tshowControls: false\r\n\t});\r\n});\r\n\r\nwin.add(openCameraButton);\r\nwin.open();\r\n{code}\r\n\r\n\r\nh2. Additional notes\r\nIn the sample code above, objects are defined inside 'openCameraButton.addEventListener' function. \r\nMoving them outside of the function will solve the problem for this particular case.\r\nLooks like to the references to the objects in the function are lost (maybe after items have been garbage collected).\r\n\r\nTickets references: http://support.appcelerator.com/tickets/APP-397683 and http://support.appcelerator.com/tickets/APP-499212", "attachment": [], "flagged": false, "summary": "iOS: loss of reference to functions using event handlers ", "creator": { "name": "fcasali", "key": "fcasali", "displayName": "Federico Casali", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "fcasali", "key": "fcasali", "displayName": "Federico Casali", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "iOS 5\r\nTiSDK tested 2.0 - 2.1", "comment": { "comments": [ { "id": "218940", "author": { "name": "mstepanov", "key": "mstepanov", "displayName": "Max Stepanov", "active": true, "timeZone": "America/Los_Angeles" }, "body": "PR pending https://github.com/appcelerator/titanium_mobile/pull/2942", "updateAuthor": { "name": "mstepanov", "key": "mstepanov", "displayName": "Max Stepanov", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-09-13T16:25:55.000+0000", "updated": "2012-09-13T16:25:55.000+0000" }, { "id": "229908", "author": { "name": "nhuynh", "key": "nhuynh", "displayName": "Natalie Huynh", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Tested with 3.0.0.v20121130200208 on iPhone 4 5.1.1", "updateAuthor": { "name": "nhuynh", "key": "nhuynh", "displayName": "Natalie Huynh", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-12-04T19:42:49.000+0000", "updated": "2012-12-04T19:42:49.000+0000" }, { "id": "261987", "author": { "name": "pagarwal", "key": "pagarwal", "displayName": "Priya Agarwal", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Reopening just to updated label.", "updateAuthor": { "name": "pagarwal", "key": "pagarwal", "displayName": "Priya Agarwal", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-07-16T09:38:00.000+0000", "updated": "2013-07-16T09:38:00.000+0000" }, { "id": "261988", "author": { "name": "pagarwal", "key": "pagarwal", "displayName": "Priya Agarwal", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Updated label.\r\nVerified with:\r\n\r\nTitanium Studio:3.1.2.201307091843\r\nTitanium SDK: 3.1.2.v20130710144553\r\nacs:1.0.3\r\nalloy:1.1.3\r\nnpm:1.2.14\r\ntitanium:3.1.1\r\ntitanium-code-processor:1.0.1\r\nOS: OSX 10.8\r\nDevice:iphone4(v5.1)\r\nXcode: 4.5.1\r\n", "updateAuthor": { "name": "pagarwal", "key": "pagarwal", "displayName": "Priya Agarwal", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-07-16T09:39:27.000+0000", "updated": "2013-07-16T09:39:27.000+0000" } ], "maxResults": 4, "total": 4, "startAt": 0 } } }