Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1729] Application hard-resets when saving an image file to internal storage

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionFixed
Resolution Date2013-02-14T18:52:52.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsStudio, Titanium SDK & CLI
Labelsandroid, defect, studio3
ReporterRobin Williams
AssigneeCarter Lathrop
Created2013-02-13T20:21:36.000+0000
Updated2016-03-08T07:40:36.000+0000

Description

Worst possible scenario - an intermittent fault! It mostly fails but occasionally will work! I am downloading Facebook Profile Pictures and trying to save them to the ApplicationDataDirectory (but any internal directory would be fine!) The file is received and then the app does a hard reset and restarts. No 'rsod' or java exceptions, it just restarts! Eventually after enough restarts it will have actually successfully saved all of the required profile pictures. NO, the number of restarts does NOT correlate to the number of pictures required - the number of restarts is much higher and variable / random. Once it has managed to save all the profile pictures, they all load perfectly without issue. The restart occurs when trying to actually write the file to the filesystem. I have tested the code by commenting out various sections and lines to see what causes the crash and it is the 'file.write()' command that does it! I know I could just download the pictures on the fly as a workaround but that's 1) slow, 2) uses up users' monthly data allowance and 3) is plastering over a crack! The problem occurs on 2 completely different, unrelated Android devices from different manufacturers with different Android versions. Yes, the function IS being sent correct Facebook account data, held in friendsArray[friendCount].id Many thanks in advance, Robin
getAllProfilePictures = function(friendCount){

	var playerToGet = friendsArray[friendCount].id;
		
	var pictureFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, playerToGet +'.jpg');
	if (!pictureFile.exists()){
	
		var xhr = Ti.Network.createHTTPClient();
		
		xhr.onload = function(){

			holder = this.responseData;
			pictureFile.write(holder);
			pictureFile = null;
			if(friendCount > 0 ) {
				friendCount-=1;
				getAllProfilePictures(friendCount);
			} else {
				return;
			};
		};

		xhr.open('GET', 'https://graph.facebook.com/' + playerToGet + '/picture');
		xhr.send();	
	
	} else if(friendCount > 0 ) {
				pictureFile = null;
				friendCount-=1;
				getAllProfilePictures(friendCount);
			} else {

				return;
			};

};  //  End Get All Profile Pictures Function

Comments

  1. Carter Lathrop 2013-02-13

    Robin, Would you mind editing your code so it can be directly pasted into an app.js and run right away? This way I can more quickly determine the validity of the bug and pass it on to engineering. Thank you, Carter
  2. Robin Williams 2013-02-14

    Hi Carter, Thanks for your help. Is there an e-mail address I can send you the file to please? I'd really rather not post anything in public as I'm not sure if it would expose any I.P at this point?! Many thanks, Robin
  3. Carter Lathrop 2013-02-14

    Robin, Is there no way to minimize your code as to isolate the bug in question? This will have to be done in order for engineering to look at the problem and come to a solution. This is why I ask. Try to break down your code into the smallest possible size while still displaying the bug and I will take a look at it. PM me at clathrop@appcelerator.com with the project. Regards, Carter
  4. Robin Williams 2013-02-14

    Hi Carter, Thank you for your response. In order to e-mail you some functional code, this afternoon I had condensed the code down to about 500 lines using a very, very early prototype / testbed program I had made when first trying out some of the functions for my game. The most extraordinary thing happened... When I first ran the 'testbed' version with the troublesome code pasted into it, the program did indeed reset as per usual, so I thought "okay... here we go again..." I tidied up a couple of bits and bobs in the code to send to you (just removing unneeded functions and buttons etc) and recompiled and ran the code and it didn't reset! I uninstalled and reinstalled numerous times and it didn't reset again. So... I uninstalled the actual game itself and reinstalled it using the exact same apk I had previously installed it with and it reset once. I uninstalled and reinstalled (many many times) and it hasn't reset once! I did this both on my telephone and my tablet and the exact same thing happened on both devices! So something which has been causing the program to hard reset every time for the last few weeks has stopped doing it after I installed a different app that accessed the internal storage. It is utterly inexplicable! I am really glad it is all now working as I couldn't for the life of me see anything that was incorrect in my code (after weeks of trying!) but I cannot explain what caused it to stop or then caused it to start working again?! Many thanks for your time, Robin
  5. Robin Williams 2013-02-14

    I should point out that I haven't actually changed *anything* in the code! I ran a different program, using a copy and paste of the code and it has started working again! :-s Many Thanks! Robin

JSON Source