Calling a function from another screen crashes companion

A student of mine recently submitted code that was, well, broken. It went like this:

Screen1: function PlaySound1
Screen2: button.onClick(PlaySound1)

Now obviously, calling functions from one screen on another doesn't work. That's just a basic limitation of App Inventor. But when testing this on my iPhone 11 running companion version 0.9.11, the app crashed upon pressing the button (as opposed to simply doing nothing or throwing an error, which I assume would be the intended effect).

Thanks for the report. So if I understand correctly, did the student copy and paste a call PlaySound1 procedure call from Screen1 to Screen2? Normally the procedure drawer only shows valid procedures for the given screen.

Yes, they copied and pasted from screen to screen; definitely weren't following the assignment instructions.

I think it will sho warning or error on the block because screen 2 doesn't have a player component then how it play also calling a procedure needs definition of it if they just copied the call block and without definition copied then how it work

image

I was able to do the same while using the backpack. So the sound component is in screen one. I copied the block to the backpack and pasted it in screen2. So with the backpack this is possible.

1 Like

Yes, I'm not actually worried about the fact that the block is from a different location. I'm investigating how we can make sure it doesn't cause a crash in the future.

Yep, this appears to be exactly how it was done.

This is my main concern as well. Students that may eventually use the iOS companion might be daunted by a crash that doesn't explain the issue.

Unfortunately I can't seem to replicate this. When I copy the call block to Screen2 the system correctly marks it as an error and won't generate code for the event handler. @sulliops since you can see the students original code can you come up with a simple project that exhibits the issue so we can work on a fix?

Here's the actual project file for the student's work.

Yep that did it. I think there are two bugs to tease apart here. The first is that we crash when a component isn't defined on a screen. The second is that it seems like the error checking code is running after the code generation when switching to a previously unopened screen. The latter causes invalid code to be sent to the companion, which then triggers the second bug.

FYI, I've removed the project since it contains some PII.

1 Like

They copied the blocks from the back pack, but didn't change the sound to play to the sound that was actually on the screen. Note: I downloaded it before @ewpatton deleted it. I have deleted the project.

I definitely didn't experience this crash myself, only the second one. Likely because I never got the chance to visit more than one non-home screen before I encountered a crash.

Copied the original file straight from Google Classroom, forgot the student had included their name in the project. Totally my bad, thanks for being good sports about it!

I have come up with a fix for the crash.

Cool beans! I'll look out for it with the next beta release, and let you know if I still encounter it (should the situation arise again).