I am trying to make an android app that lets the user select an image from gallery and saving it in a data folder for later use. The image is classified by topic and subtopic, the data folder also having a folder system organized as such:

The problem is, on Android, I can't create directories and folders in "res://", I belive that's because the .apk is self contained, but i'm not 100% sure. My solution is moving the data from res:// to user:// for easy acces to it.

I am using this recursive function to move all files and folders from a root folder to it's counterpart in "user://":

func move_all_topic_data_to_user(var path):

		var err
		var dir=Directory.new()
		var user_dir=Directory.new()
		var copy_dir=Directory.new()
		dir.open("res://Data" + path)
		user_dir.open("user://"+path)
		dir.list_dir_begin(true)
		var file="(-_-)"
		while file!="":
			file=dir.get_next()
			if file!="" and !file.begins_with("."):
				if dir.dir_exists(file):
					err=user_dir.make_dir(file)
					#print(err,file)
					move_all_topic_data_to_user(path+"/"+file)
				if dir.file_exists(file):
					if !user_dir.file_exists(file):
						err=copy_dir.copy("res://Data"+path+"/"+file,"user://"+path+"/"+file)
						#print(err,path+"/"+file)
		dir.list_dir_end()

This works perfectly on PC, but when i try to run it on Android, the app just crashes with the error message: Condition "!process_map->has(p_pid)" is true

From my tests, the crash doesn't happen from a simple call of dir.open(), dir.copy() and user_dir.make_dir(). What could be the problem?

sidenote: i miswrote the function's name, it should be "move_all_topic_data_to_user".

The only thing I can think of is to make sure the Android app has permissions to edit folders in user://? I think there is a something you can set in the Android app permissions that allows for modifying local storage.

@KyleKyle said: sidenote: i miswrote the function's name, it should be "move_all_topic_data_to_user".

I've edited the OP for you, though for future reference, you can edit the opening post of your own topics by finding the little gear icon to the right of the topic title. ;)

@Megalomaniak Thanks for the heads up!

@TwistedTwigleg I don't think that is the problem as I can write in user:// outside the function without problem, but as an update I've narrowed it down to the copy_dir.copy("res://Data"+path+"/"+file,"user://"+path+"/"+file) line. Weirdly enough, this is what causes the app to crash, even if the root folder is empty, so my best guess is the conversion to .apk generates additional files that do weird stuff when copied.

Edit: turns out I was wrong, the problem actually came from the file_exists() function. For some reason, the call of it made the app crash. Removing it from the code will require some workaround, but at least the app runs, so I'll call it a win for now. Thank you for your time!

2 years later