Experiment crashing on iPhone

First let me just say that this is a very impressive bit of design when it all works! I never really put together all of what it was doing when we were troubleshooting it, but a darts game with reasonable physics and dynamic scaling with “distance” is really an impressive demonstration of the flexibility of PsychoPy and Pavlovia and a nice bit of programming to boot. This would be non-trivial in python or JS alone, being able to do it in both is awesome.

Back to the matter at hand. I wasn’t able to use your pilot link but I cloned your repository and ran my own pilot on my Android phone. It worked through the first break and a couple of trials after that, then put a black square around the dart image and crashed. I then tried it in Chrome’s mobile-interface-simulation mode on my laptop (it’s in the dev console, the little tablet+phone icon in the top left next to the mouse icon) and it worked straight through.

So this is really narrowly something that happens only on mobile devices (not just in browser simulating being in mobile mode), and that’s more difficult to troubleshoot. It may actually be easier for you on an iPhone. The instructions here tell you how to pull up a JS console on your iPhone: https://eclipsesource.com/blogs/2012/08/14/debugging-javascript-on-android-and-ios/ Try that and see if you get any informative messages.

Thanks for the compliment. My Python coding has entirely been learned via customising PsychoPy experiments created in builder, and it looks like I will continue to avoid learning to program in Javascript.

I couldn’t find the setting for a JS console in Safari on my iPhone, so I’ll ask around for help. I’ve been using Chrome on my iPhone (this is my first Apple device after a string of Androids) but my wife got the same black square you experienced on her Android.

On thing the black square makes me thing of is the mask parameter. In Python the default is mask=None which autotranslates to mask=null which gives an error. Without the mask parameter it works but there is a warning:

log4javascript.min.js:1 WARN unknown | setting the mask of ImageStim: dart with argument: undefined.
log4javascript.min.js:1 WARN unknown | setting the value of attribute: mask in PsychObject: dart as: undefined

It’s clearly very close if it’s working in an emulator. I was wondering if the problem was due to one of the warnings, but all the others seem to be based on text stimuli:

Deprecation Warning: text style property 'font' is now deprecated, please use the 'fontFamily','fontSize',fontStyle','fontVariant' and 'fontWeight' properties from now on

WARN unknown | setting the value of attribute: seed in PsychObject: TrialHandler as: undefined

Best wishes,

Wakefield

My only thought about that is that unless these warnings are present on some trials but not others, it doesn’t explain why you get through some trials and then it fails rather than it just failing immediately. The fact that it fails after N trials could suggest a memory issue, but that seems unlikely and it would probably fail in a slightly different way. Unfortunately I’m just not experienced enough with developing for mobile browsers to really know what could be causing this.

@jon is there anyone who might have better insight into this kind of problem?

A friend has given me a pointer as to how to debug Javascript on mobile devices by attaching them to a computer. They used instructions from https://www.joezimjs.com/javascript/how-to-debug-android-chrome-from-your-windows-pc/

I’ve also found some possibities for using iTunes libraries to debug an iPhone on a Windows computer, but I haven’t had a chance to try them yet. In the meantime my friend sent me this screenshot from her setup.

No error but the number by the last warning keeps incrementing.

WARN unknown | setting the value of attribute: text in PsychObject: instructions as: undefined

Instructions is causing an issue online, but I didn’t think it was the main problem. It’s coming up blank when it should be $blockinstruct[repeat.thisN] (currently set every frame in an attempt to fix it not working every repeat). I’ll therefore focus on that in the first instance, but I’d be surprised if it solved the issue.

I think that the error message

WebGL: CONTEXT_LOST_WEBGL: loseContext: context lost

occurs when the browser decides to crash out instead of staying in what it feels to be an infinite loop.

After some investigation I’ve narrowed down the problem to updating the dart’s position and size. It’s as if there is only enough memory to do this a fixed number of times.

The relevant code is:
Begin Experiment

dart = new visual.ImageStim({"win": win, "name": "dart", "image": "dandelion_dart.png", "ori": 0, "pos": [0, (- 0.35)], "size": [0.25, 0.25], "color": white, "colorSpace": "rgb", "opacity": 1, "flipHoriz": false, "flipVert": false, "texRes": 128, "interpolate": true});

Begin Routine

dartx = 0;
darty = (- 0.35);
dartsize = [0.25, 0.25];
dartvx = 0;
dartvy = 0;
dartoldpos = [0, (- 0.35)];
inflight = (- 1);
drag = [0.95, 0.9];
framecount = 0;
dart.size = dartsize;
dart.pos = [dartx, darty];

dart.setAutoDraw(true);

Each Frame (improved from previous version when the size and position were updated even with no movement)

else {
                    if ((inflight === 2)) {
                        dartx = (dartx + dartvx);
                        darty = (darty + dartvy);
                        dartvx = (dartvx * drag[0]);
                        dartvy = (dartvy * drag[1]);
                        dartsize = [(dartsize[0] * 0.99), (dartsize[1] * 0.98)];
                        dart.size = dartsize;
                        if ((dartvy < 0.001)) {
                            inflight = 3;
                        }
                    }
if (((abs(dartvx) + abs(dartvy)) > 0)) {
    dart.pos = [dartx, darty];
}

End Routine

dart.setAutoDraw(false);

I’ve replaced the dart image with a polygon which seems to have solved the problem (by avoiding it). My guess is that there is some form of memory leakage in the/my image code. The same issue may still be true for polygons but at a much lower level.

Cheers,

Wakefield

Yes, I think that’s right. See here: Update every frame doesnt work

@jon this memory thing is rearing its head again.

Yes, our working hypothesis is that certain stimuli are using graphcs card memory and that this isn’t properly cleared by standard garbage collection. That fits with Wakefield’s issue - a phone would typically have less graphics memeory so crashes sooner, and a polygon doesn’t need to put a texture on the card so no leak. I’m hoping we’ll be able to get to this soon now (the deluge of urgent lockdown-induced issues is coming a little more under control!)

was there any update on this? I have a similar issue which can’t be resolved by switching out images to polygons.

Cheers

Have you already ensured that you only update your image(s) when they actually change? The other thing I tried was reducing the frame rate of my animation (e.g. by only updating a constantly moving image every 5 or 10 frames).

yeah my image and textstim are now set to either constant or set every repeat.

I still have the issue that if someone exits fullscreen mode or their phone goes to sleep this happens:

(the background image should take up the whole screen).

Cheers

That sounds like a different issue. Are you using different units for your images and your background?

there was initially different units within a nested loop (but not within the inner loop where the bug appears to occur) - changing them all to a consistent unit seems to fix the issue of the phone going to sleep, but not exiting fullscreen mode - is exiting fullscreen mode a problem for your study?

Now you come to mention it I’m even getting into full screen mode when piloting on Chrome on my iPhone.

ok i seem to have fixed it by setting a bunch of the offending articles to “set every repeat” instead of constant, even though logically there shouldnt be any issue with setting to constant.

What I take from this is that something funky is still going on here but that setting it to every repeat wipes the slate clean.

ignore: i tried it on a different phone and encountered problems, this is weird

Constant means that they won’t change, even if the environment changes – and probably everything gets translated to pixels in the background, so it could be that the underlying value need to be updated even if the value in your code doesn’t change.

yeah that makes sense - i’m not sure why it would still work on laptop then but it seems to be working now so that’s that for now haha thanks.

Any updates on this? I’m having a very similar issue and only happens at random times with random participants (or what seems to be random)

We have certainly made some progress in tracking this down and we’re checking that the scope of the fix (i.e. does it cure all cases or just some?). We’re confident we can have this fixed in 2020.2 release (due in the next few weeks) so that you can use the full range of live-updating stimuli again :slight_smile:

Hey, Just checking if this is the same issue or something else!

My experiment runs to completion and smoothly on chrome but in safari I get the following error for presenting very simple images. This is the first routine in an experiment, but the experiment as a whole has a lot of images and videos (but only 50 resources). The route to go might be to reduce the number of “fancy” images, although I would rather not, so checking if this seems like a similar scenario to what you encountered here.