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: 
goya
Visitor

the following code reboots my roku 2 xs

the following code reboots my roku 2 xs

the first 2 benchs if runned by themselves are not a problem.
it appears the code crashes if after integerArithmeticMix runs... My debug console closes and I do not see any messages. All that happens is the roku freezes then reboots on its on...

so why is messing up the vm, looks live vm bug... since the code runs by itself... it just leaves the vm unstable...
or its actually running... Maybe it's eval() that is causing the problem...

Are there any log files I can look at after a reboot to see why it reboots. Too bad I don't have access to linux/c level I could debug this one. And if I had source code to BrightScript I could fix it... 😉

here is the full source code listing that crashes (reboots) the box...

sub bench(n)
end sub

sub sieve(n)
flags = CreateObject("roArray", 8192 + 1, true)

count = 0

while n > 0
n = n - 1

count = 0

for i = 2 to 8192
flags[i] = true
end for

for i = 2 to 8192
if (flags[i])
' remove all multiples of prime: i
for k = i + i to 8192 step i
flags[k] = false
end for

count = count + 1
end if
end for
end while
end sub

sub integerArithmeticMix(n%)
r% = 1%

for i% = 1% to n%
r% = r% - i%
r% = r% + i%
r% = r% * i%
r% = r% / i%
r% = r% ^ i%
end for
end sub

sub floatArithmeticMix(n!)
r! = 1.0!

for i! = 1.0! to n!
r! = r! - i!
r! = r! + i!
r! = r! * i!
r! = r! / i!
r! = r! ^ i!
end for
end sub

sub doubleArithmeticMix(n#)
r# = 1.0#

for i# = 1.0# to n#
r# = r# - i#
r# = r# + i#
r# = r# * i#
r# = r# / i#
r# = r# ^ i#
end for
end sub

sub RunBenchmarks()
benchmarks = [["bench",1],["sieve",10],["integerArithmeticMix",10],["floatArithmeticMix",10],["doubleArithmeticMix",10]]

screen = CreateObject("roParagraphScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)

screen.SetTitle("Benchmark Suite")

screen.AddButton(1, "Close")

screen.Show()

dialog = CreateObject("roOneLineDialog")
dialog.SetTitle("Running benchmarks ...")
dialog.ShowBusyAnimation()
dialog.Show()

for each benchmark in benchmarks
dialog.SetTitle("Running benchmark " + benchmark[0] + "(" + Stri(benchmark[1]) + ") ...")

st = UpTime(0)
Eval(benchmark[0] + "(" + Stri(benchmark[1]) + ")")
et = UpTime(0)

screen.AddHeaderText(benchmark[0] + "(" + Stri(benchmark[1]) + "): " + Str(et-st))
end for

dialog.Close()

closed = false

' event loop
while true
msg = wait(0, port) ' wait for an event

if type(msg) = "roParagraphScreenEvent"
if msg.isButtonPressed()
buttonIndex = msg.GetIndex()

if buttonIndex = 1
exit while
end if
else if msg.isScreenClosed()
exit while
end if
end if
end while

screen.Close()
end sub


sub DisplayMainScreen()
screen = CreateObject("roParagraphScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)

screen.SetTitle("Benchmark Suite")

screen.AddButton(1, "Start")
screen.AddButton(2, "Close")

screen.Show()

' event loop
while true
msg = wait(0, port) ' wait for an event

if type(msg) = "roParagraphScreenEvent"
if msg.isButtonPressed()
buttonIndex = msg.GetIndex()

if buttonIndex = 1
RunBenchmarks()
else
exit while
end if
else if msg.isScreenClosed()
exit while
end if
end if
end while

screen.Close()
' anytime all screens within a channel are closed, the channel will exit
end sub

sub Main()
DisplayMainScreen()
end sub
0 Kudos
10 REPLIES 10
goya
Visitor

Re: the following code reboots my roku 2 xs

i have some good / bad news

the code runs great on older roku xd model

i guess i paid to be a beta tester, joy 😉
0 Kudos
jbrave
Channel Surfer

Re: the following code reboots my roku 2 xs

for starters, just put a print statement after each line, see if you can figure out the last line to execute before it rebooted, that is usually the one that caused it, or nearby.
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
jbrave
Channel Surfer

Re: the following code reboots my roku 2 xs

Whatever it is, it appears to occur in the doubleArithmetic sub

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
RokuMarkn
Visitor

Re: the following code reboots my roku 2 xs

Apparently Brightscript is not properly handling a for loop which uses a double variable as the index (generally not a good idea, but it shouldn't crash). I have filed a bug report for this.

--Mark
0 Kudos
jbrave
Channel Surfer

Re: the following code reboots my roku 2 xs

Output:

entered sieve
exiting sieve
entered integer arithmetic
exiting integer arithmetic
enter float
exit float
entered double
first line executed

sub doubleArithmeticMix(n#)
?"entered double"
r# = 1.0#
?"first line executed"
for i# = 1.0# to n#
?"entered for loop"
r# = r# - i#
?"line1 executed"
r# = r# + i#
?"line2 executed"
r# = r# * i#
?"line3 executed"
r# = r# / i#
?"line4 executed"
r# = r# ^ i#
?"line5 executed"
?i#
end for
?"exit double"
end sub
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
goya
Visitor

Re: the following code reboots my roku 2 xs

thank you

please let me know when there is fix release out so that i can rerun my benchmark suite on my roku 2 xs

right now its runs great on my roku xd

best regards
0 Kudos
jbrave
Channel Surfer

Re: the following code reboots my roku 2 xs

Might it possibly be more efficient & accurate to calculate the time from the time it entered the benchmark sub till it exits, and instead of using a call to the system time use rotimespan:

Like:


et=Eval(benchmark[0] + "(" + Stri(benchmark[1]) + ")")

function sieve(n) as integer
?"entered sieve"
timer=createobject("rotimespan")
timer.mark()
flags = CreateObject("roArray", 8192 + 1, true)

count = 0

while n > 0
n = n - 1

count = 0

for i = 2 to 8192
flags[i] = true
end for

for i = 2 to 8192
if (flags[i])
' remove all multiples of prime: i
for k = i + i to 8192 step i
flags[k] = false
end for

count = count + 1
end if
end for
end while
return timer.totalmilliseconds()
?"exiting sieve"
end sub


Also eval itself has some significant overhead I think, it compiles the code it is evaluating before it executes, so if you want to time the total process, wouldn't it be better to call the function directly, or at least do your timing within the functions being evaluated?

Just a thought, there is probably a good reason why you are doing it that way.

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
goya
Visitor

Re: the following code reboots my roku 2 xs

"jbrave" wrote:
Might it possibly be more efficient & accurate to calculate the time from the time it entered the benchmark sub till it exits, and instead of using a call to the system time use rotimespan:

Like:


et=Eval(benchmark[0] + "(" + Stri(benchmark[1]) + ")")

function sieve(n) as integer
?"entered sieve"
timer=createobject("rotimespan")
timer.mark()
flags = CreateObject("roArray", 8192 + 1, true)

count = 0

while n > 0
n = n - 1

count = 0

for i = 2 to 8192
flags[i] = true
end for

for i = 2 to 8192
if (flags[i])
' remove all multiples of prime: i
for k = i + i to 8192 step i
flags[k] = false
end for

count = count + 1
end if
end for
end while
return timer.totalmilliseconds()
?"exiting sieve"
end sub


Also eval itself has some significant overhead I think, it compiles the code it is evaluating before it executes, so if you want to time the total process, wouldn't it be better to call the function directly, or at least do your timing within the functions being evaluated?

Just a thought, there is probably a good reason why you are doing it that way.

- Joel



good ideas and most likely i will make changes to code

i'm porting code that is written in other languages, this was quick, easy and dirty way.

this is what happens when you put quare peg in round hole...

i will go back and make better, most likely replace use of eval and just have long list of calls, i was just hacking down a bigger bench / test framework and tried to stick it with some simple screens.

notice the first call to bench to get base time... this is supposed to be removed from each call and it like takes out time spent in eval

then again im not sure about brightscript internals... i know how the languages that i have created and worked on work, but i know very little about brightscript, just started the other day.

i didnt use rotimespan because it looked like call to createObject would create an object and i would rather not instantiate objects which i then throw away. anyways the call i'm using appears to me to give accurate valies... but i will look eventually i will create benchmark test for it and then i can compare between one and the other... too bad i cant see how much memory im using..

i wish i had linux/c access... then i could see much more in asm/c debugger... too bad brightscript language is not open source. iscript has full exception handling / object oriented / ect... all the syntax sugar in the world. should not be too hard to add to brightscript...

i guess brightscript is what it is because i guess its for us to create simple screen savers and channels to glue the components they give us

and i guess some of the new components is for us to create (port) classic 2d games...

angry birds is fun... i tried it (too bad about patent lawsuit)

anyways i got to get some work done and then i'll play more with my new roku and the emulator stuff. i have a bit of work i must do on iscript so i can clear up time to undo my work so it can be more like iscript so it can be used in emulator... plus i still have to finish my work on all those components, i've done a good bit this weekend on creating mock objects, but there is still a lot more to do...

i wonder when i have this all done what i will do with all my little roku stuff. maybe port some game... that sounds fun. i like tower defense, should not be too hard. i have lots of sample code for games, mostly classic games...
0 Kudos
jbrave
Channel Surfer

Re: the following code reboots my roku 2 xs

Whoa, I didn't know about that lawsuit. I just read up a bit on it.

Apparently its about having a button in your "Lite" app that links to a paid app. That applies to almost every other free app in the Apple app store, and now on Roku, we have that functionality available too. The patent system needs to be dismantled be revised in some fundamental way.

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos