Forum Discussion

belltown's avatar
belltown
Roku Guru
15 years ago

Reading events with 'for each' crashes Roku

If I run the following code to display a default springboard screen and the only thing I do after entering the channel is press the Home key on my Roku remote, then my Roku reboots:

sub main ()

port = CreateObject ("roMessagePort")
screen = CreateObject ("roSpringboardScreen")
screen.SetMessagePort (port)
screen.SetContent ({ContentType: "episode"})
screen.Show ()

for each msg in port
print "Message received"
end for

end sub


However, if I run the following code replacing the for-each loop with a while loop, then when I press the Home key the channel correctly exits:

sub main ()

port = CreateObject ("roMessagePort")
screen = CreateObject ("roSpringboardScreen")
screen.SetMessagePort (port)
screen.SetContent ({ContentType: "episode"})
screen.Show ()

while true
msg = wait (0, port)
print "Message received"
end while

end sub


According to the BrightScript reference manual, section 4.7 Events, on page 20, these two statements should be equivalent.

Any idea why the first one would crash the Roku? I'm running the 3.0 build 2227 firmware on a Roku HD model 2000C.

4 Replies

  • renojim's avatar
    renojim
    Community Streaming Expert
    It's probably got something to do with the Home key spewing invalid messages to the message port. Do you see a bunch of "Message received" strings when you run your second example? (I do when I try it.)

    -JT
  • "renojim" wrote:
    It's probably got something to do with the Home key spewing invalid messages to the message port. Do you see a bunch of "Message received" strings when you run your second example? (I do when I try it.)

    -JT


    Yes, I do see a bunch of "Message received" strings in the second example, and only one in the first case before it crashes.

    Still, I don't see why the Roku would crash in the first case if the for-each and while loops are supposed to be equivalent ways to read event messages. Does this seem like a firmware bug or a "feature"? Out of curiousity, renojim, did the first example also crash your Roku?
  • YungBlood's avatar
    YungBlood
    Streaming Star
    I did a test, with very interesting results. Although I did not use your code exactly, I put the piece in question into the project I'm currently working on. Both worked to my surprise. I'm running 4.1 Build 2663 on a Roku 2 3100X. I placed in a roscreen...

    I was expecting it to be a problem since you weren't calling wait(0, port) in the for loop... but it ran fine for me...
  • renojim's avatar
    renojim
    Community Streaming Expert
    "belltown" wrote:
    Still, I don't see why the Roku would crash in the first case if the for-each and while loops are supposed to be equivalent ways to read event messages. Does this seem like a firmware bug or a "feature"?

    They (Roku) have said on more than one occasion that anything that crashes the box is considered a firmware bug. It probably worked before the Home key started spewing invalid messages (several firmware versions ago). This would probably be a pretty low priority for them to fix. The normal way to do a message loop is to use the while with the wait function; just make sure to check for invalid messages after the wait.

    "belltown" wrote:
    Out of curiousity, renojim, did the first example also crash your Roku?

    Yep. Crashes v3 and v4.

    -JT