Hi Codea people,
I’ve got a Codea crash problem
I’m working on a small scientific app - it collects data about the way a subject moves their finger or stylus to follow a moving line. The subject will follow the line for a set number of movements - say 50 - which last for random time periods - usually between 1 and 3 seconds. Once the subject has followed all the movements, the trail is complete and the program re-draws a “start” button so a new trial can be started.
Every time the draw() function is called, the app saves data into a table. In a function sub-called by the Main draw() function I have:
-- Insert data into main data table:
table.insert(self.dataBuffer, {ElapsedTime, ti, self.current.i,
self.t.x, self.t.y, self.lastTouch.x,
self.lastTouch.y, tpos, dx, p.mirrx,
CurrentTouch.state, self.lapse,
UserAcceleration.x, UserAcceleration.y,
UserAcceleration.z, 0,
maskOn})
After a variable amount of time (the moving line moves a fixed number of times, but spends a randomised amount of time at each location), a function is called to output the content of self.dataBuffer into a Dropbox file:
In a method called PBPath:endAnimation (called when the trial is complete) the code is something like this:
self.file = "Dropbox:somefile.txt"
local txt = self:header()
for i, l in ipairs(self.dataBuffer) do
txt = txt..table.concat(l, "\\t").."\
"
end
-- Crash occurs within saveText:
saveText(self.file, txt)
Unfortunately, saveText causes a Codea crash (I believe this as I have debugged the program with debug calls which output one Dropbox file per call). It crashes more often when the program has been running for more than a single trial. It does so more often when the number of movements in a trial is 50, when compared with 10 movements/trial. The amount of data produced and stored in dataBuffer and the local txt variable in a trial containing 50 steps is no more than 1 MB.
I’m keen to either find a workaround or a suitable debugging approach. I’m not near a Mac right now, but later on I plan to have a look at the iPad Air 2’s crash logs to see if they shed any light.
I tried building a sort of dummy program, by taking the real program and cutting out the animation so that it simply does the table.insert() with some dummy data, followed by the save step. That also crashes, but more intermittently than the real app. It allows you to run the program for as long as you like, adding 10 entries to self.dataBuffer on each call to draw, displaying the length of dataBuffer on the screen as you go. It sometimes crashes while it’s filling dataBuffer, and if dataBuffer is allowed to become greater than about 10000 entries, the process of populating the local txt variable appears to hang, but I’ve not yet been patient enough to allow it more than about 10 minutes for this - Codea doesn’t crash in this case though.
I have colleagues who have seen similar crashy behaviour with various other versions of this program, all of which share the same “save to dataBuffer” then “saveText from dataBuffer/local txt”.
All the best,
Seb James