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: 
360tv
Streaming Star

This code works 99.5% of the time...

I'm doing a thing for a guy, the core chunk of code is this...

	if (imagetimer.totalseconds() > 10) and (fadelevelA.[0] = 255 )  then
print "mark " + imageindex.tostr()
print "Checking for " + randpics[imageindex].url + " -> " + "tmp:/"+imageindex.tostr()+".jpg"
if files.exists("tmp:/"+imageindex.tostr()+".jpg") = false
Print "Downloading " + randpics[imageindex].url + " -> " + "tmp:/"+imageindex.tostr()+".jpg"
timer.mark()
http.SetUrl(randpics[imageindex].url)
http.GetTofile("tmp:/"+imageindex.tostr()+".jpg")
print "...Downloaded in " + (timer.totalmilliseconds()).tostr() + "ms."
else
print "Already Exists: " + "tmp:/"+imageindex.tostr()+".jpg"
end if

timer.mark()
'loads in the next image to be transitioned to
bm=CreateObject("roBitmap", "tmp:/"+imageindex.tostr()+".jpg")
images.push(bm)
print "Drew screen in " + (timer.totalmilliseconds()).tostr() + "ms."
if imageindex = (randpics.count() -1) then imageindex = 0 else imageindex = imageindex + 1
end if
'After 10 seconds, transitions between images[0] and images[1]
if (imagetimer.totalseconds() > 10) and fadelevelB[0] <= 254 then
fadelevelA[0] = fadelevelA[0] - 1
fadelevelB[0] = fadelevelB[0] + 1
end if
'when the transition is finished, reset fade levels, timers and move next image up to current.
if (fadelevelB[0] = 255) and (imagetimer.totalseconds() > 10 ) then
fadelevelA[0] = 255
fadelevelB[0] = 0
images.delete(0)
imagetimer.mark()
end if


m.screen.Clear(&h00000000)
if images.count() > 0 then m.screen.DrawObject(0,0,images[1],HexToInteger3("FFFFFF" + fadelevelB.tohexstring()))
m.screen.DrawObject(0,0,images[0],HexToInteger3("FFFFFF" + fadelevelA.tohexstring()))

m.screen.SwapBuffers()



it cycles an array of image urls, downloads them (if they don't exist already) and cross-fades them.
that works 99.5%of the time, but on some super rare occasions, it does this...

https://www.youtube.com/watch?v=vU-gl4RXa3w

Here, it's showing a blank screen, it begins to show the next image only as the cross fade begins and fades to black. I can't figure out what causes it, and I've only seen it on my Roku LT. The guy I'm doing this for can get it to happen a little more often on his Roku 3.

Any ideas?
0 Kudos
6 REPLIES 6
TheEndless
Channel Surfer

Re: This code works 99.5% of the time...

How long does it run before it fails? Does it fail at the same time every time? Have you checked r2d2_bitmaps to see the available memory when this happens? Also, are you periodically cleaning up tmp:/? You're not checking the validity of bm, so my guess is that the image itself isn't loading, which would point to 1) a bad image file (unlikely), 2) out of video/graphic memory, 3) out of tmp storage, or 4) a combination of those.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
EnTerr
Roku Guru

Re: This code works 99.5% of the time...

"360tv" wrote:

if (imagetimer.totalseconds() > 10) and (fadelevelA.[0] = 255 ) then

Holy carp fish! How does this thing even compile?
mind.isBlown = true

Other than that, i am unable to see what problem behavior is - either from video or description. Explain?
0 Kudos
RokuMarkn
Visitor

Re: This code works 99.5% of the time...

Hm, the parser seems a little overpermissive here and ignores a dot before a subscript. I don't think it's a big deal but I'll file a bug report.


BrightScript Debugger> a=[1,2,3]
BrightScript Debugger> ?a[1]
2
BrightScript Debugger> ?a.[1]
2
BrightScript Debugger>


--Mark
0 Kudos
EnTerr
Roku Guru

Re: This code works 99.5% of the time...

"RokuMarkn" wrote:
Hm, the parser seems a little overpermissive here and ignores a dot before a subscript. I don't think it's a big deal but I'll file a bug report.

It's not a tragedy, it was just so startling (i tested it to work with roByteArray). Now it turns out same is true for any variable name:
BrightScript Debugger> a = 7
BrightScript Debugger> ? a , a. , a.-1
7 7 6

PS. this is a long shot but perhaps stems from a strtok(..., ".")
0 Kudos
360tv
Streaming Star

Re: This code works 99.5% of the time...

"EnTerr" wrote:
"360tv" wrote:

if (imagetimer.totalseconds() > 10) and (fadelevelA.[0] = 255 ) then

Holy carp fish! How does this thing even compile?
mind.isBlown = true

Other than that, i am unable to see what problem behavior is - either from video or description. Explain?


The problem behavior in the video is that instead of cross-fading between two images, it's bringing up image 1 long enough to fade it from &hFFFFFFFE till &hFFFFFF00 and not showing image 2 at all. It's supposed to do a simple cross-fade and it works... 99.5% of the time.

"TheEndless" wrote:
How long does it run before it fails? Does it fail at the same time every time? Have you checked r2d2_bitmaps to see the available memory when this happens? Also, are you periodically cleaning up tmp:/? You're not checking the validity of bm, so my guess is that the image itself isn't loading, which would point to 1) a bad image file (unlikely), 2) out of video/graphic memory, 3) out of tmp storage, or 4) a combination of those.


I've been able to run it for hours without a problem. The code is written so that it dosen't download an image if it already exists in tmp storage. However, I might need to change it so it downloads the image every single time? I dunno...

Since I am having trouble reproducing the issue, I haven't been able to look at r2d2_bitmaps to see if it's some sort of memory problem. Does the original size of a downloaded jpg affect the amount of memory used when creating an orBitmap?
0 Kudos
TheEndless
Channel Surfer

Re: This code works 99.5% of the time...

"360tv" wrote:
Does the original size of a downloaded jpg affect the amount of memory used when creating an orBitmap?

No, only the pixel width and height. The amount of tmp storage used does, however. At the very least you should be checking the CreateObject("roBitmap") call to see if it's failing.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.