Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
greid
Visitor

Frustration with events, screens

I am having a lot of trouble building an app, and I'm frustrated because I don't have any information to work with on what is going wrong. I am a very experienced developer, though new to BrightScript. I have had some early success in getting my app working, but after "refactoring" into multiple .brs files and Functions, nothing seems to work predictably.

Here's the situation. I want to have a series of "screens" that progress through the user experience, from a Welcome screen to a Registration screen to a Play Movie screen. Each of these screens has worked, but when I try to orchestrate them in sequence, things quit working. The Welcome screen works, but when I dismiss it, the Reg screen fails. If I comment out the call to the Welcome screen, then the Reg screen works correctly.

It seems like it must be related to screens, message ports, and events, but I've been trying for two days to narrow it down, unsuccessfully.

The symptoms right now are that a screen that "used to work" will fail silently, partway through, without throwing any exceptions or giving any errors. The app just terminates, there is nothing on the telnet debugger screen, and no indication of what's wrong.

I don't know how to be more specific in asking this, because I don't have any repeatable scenarios. Things work sometimes, then fail silently partway through. I have even run the app twice in a row, with no changes, and it fails the first time, then works the second time.

I can provide sample code or specifics as needed, but I'm wondering if this is a "common problem" for newbies who don't get something about the event model? I've tried lots of things, like not reusing ports or variable names, closing screens when I'm done with them and not closing them, etc, etc. I'm meticulous in my debugging, but I don't know how to debug this!

Thanks for any help.

Glenn Reid
0 Kudos
5 REPLIES 5
RokuChris
Roku Employee
Roku Employee

Re: Frustration with events, screens

Any time you close all the screens in your channel, it will exit automatically. Best practice is to open a blank facade screen at the bottom of your stack to keep that from happening.

viewtopic.php?f=34&t=50590&p=343312
0 Kudos
greid
Visitor

Re: Frustration with events, screens

Thanks. I have already removed all the .close() calls but that didn't fix the problem. My main currently looks like this:

Sub Main()
valid = "INVALID"
if GetStoredRegCode() = invalid
'DoWelcomeScreen()
'valid = DoRegScreen()
valid = "VALID"
endif
if valid <> "INVALID"
choice = ChooseMovie()
if choice
DoVideoPlayer()
endif
endif
End Sub

The DoWelcomeScreen() works, and I can even call it multiple times, but DoRegScreen() only works if I do NOT previously call DoWelcomeScreen(). Same thing for ChooseMovie().
0 Kudos
destruk
Binge Watcher

Re: Frustration with events, screens

Look at Screen Stack in the SDK --
http://sdkdocs.roku.com/display/sdkdoc/ ... th+Screens

Close doesn't need to be specified to close a screen, when all references to the created object are invalidated, the screen will close itself automatically as an internal garbage collection procedure.
As long as you have one valid, referenced, created valid screen type available your channel will continue to run.
0 Kudos
greid
Visitor

Re: Frustration with events, screens

That looks like the crucial bit of info. I will check it out. Thanks!
0 Kudos
greid
Visitor

Re: Frustration with events, screens

Thanks, ROkuChris and destruk! That solved my problems. I didn't see this documented anywhere obvious, and none of the sample apps seem to do this, so it's a bit of "magic" but I'm beyond it now, at least!
0 Kudos