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: 
squirreltown
Roku Guru

bitmaps

I have screensaver that uses a roScreen, takes 10 aprox 400x600 bitmaps and flys them around. At a given time interval, it shows a logo screen and downloads a new set of pics and calls the flying-around function again. it can do this 3 times before I get a stack overflow error, And I'm not completely sure what that indicates.
Code below is in the roScreen while loop, which erases the variables and calls Main() again to start the process over.
What to do here ? thanks

 		if m.timex.totalseconds() > 90
DeleteFile("tmp:/z"+curr_photo0.GetName())
DeleteFile("tmp:/z"+curr_photo1.GetName())
DeleteFile("tmp:/z"+curr_photo2.GetName())
DeleteFile("tmp:/z"+curr_photo3.GetName())
DeleteFile("tmp:/z"+curr_photo4.GetName())
DeleteFile("tmp:/z"+curr_photo5.GetName())
DeleteFile("tmp:/z"+curr_photo6.GetName())
DeleteFile("tmp:/z"+curr_photo7.GetName())
DeleteFile("tmp:/z"+curr_photo8.GetName())
DeleteFile("tmp:/z"+curr_photo9.GetName())
ballbitmap0 = invalid
ballbitmap1 = invalid
ballbitmap2 = invalid
ballbitmap3 = invalid
ballbitmap4 = invalid
ballbitmap5 = invalid
ballbitmap6 = invalid
ballbitmap7 = invalid
ballbitmap8 = invalid
ballbitmap9 = invalid
print "Bitmaps Deleted"
Main()
exit while
end if


here is the error
Stack overflow. (runtime error &hdf) in .../pkg:/source/motionscreen.brs(232)

232: drawing_regions = dfSetupDisplayRegions(screenFull, topx, topy, w, h)
Kinetics Screensavers
0 Kudos
8 REPLIES 8
RokuMarkn
Visitor

Re: bitmaps

Your code is calling Main. That's a big no-no. Think about it -- Main is the entry point; it then calls your function. Your function calls Main. Main calls your function again. This goes on forever, each time using up some stack space for local variables and the return address. Eventually you run out of stack space and overflow. I'm not sure why you're deleting your bitmaps but if you really need to do that you should do it in a loop, rather than using recursion.

--Mark
0 Kudos
NewManLiving
Visitor

Re: bitmaps

Main is an entry point into your application
It appears that you are calling it recursively
Main is generally called once and remains until the
Application exits This may be your problem
It would be in lower level languages.
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
squirreltown
Roku Guru

Re: bitmaps

Thank you Mark. I'm deleting the bitmaps because i don't know whats going on here and am trying stuff, besides once the cycle starts over I don't need those bitmaps any way and they do take memory and will eventually fill it up right? Sorry i don't know what recursion means in this context, could you explain that statement?

As for the Main-Function loop, I need the code in Main to show the splash screen and set up the roScreen. I understand what you said about the looping causing a problem. Should I make Main() mostly empty and just call a functionB which has that code, and then call functionB on each cycle? Will that get around it?
Thanks for your help.
Kinetics Screensavers
0 Kudos
squirreltown
Roku Guru

Re: bitmaps

Thank you NewManLiving, You and Mark agree that is the problem, now to just get around it somehow.
Kinetics Screensavers
0 Kudos
squirreltown
Roku Guru

Re: bitmaps

OK i just tried duplicating the Main() function called Reload() and called that each time, it didnt work, so I'm not getting some part of this loop problem.
I need to start the process over, and have now kept Main() out of it. Doesn't the RoScreen function disappear when you Exit its while loop?

edit: tried return instead of calling a function and that just exits the app. Could use some help on the correct strategy here, I know its obvious to some of you but its not something I've dealt with, thanks.
Kinetics Screensavers
0 Kudos
squirreltown
Roku Guru

Re: bitmaps

Now i made a Main() function which only show a canvas and moves on
Sub Main()


m.port = CreateObject("roMessagePort")
canvas = createobject("roImageCanvas")
canvas.SetMessagePort(m.port)
canvas.SetLayer(0, {Color:"#FF000000", CompositionMode:"Source"})
canvas.Show()

Reload()
end sub

the Reload() function starts the process of getting the rss feed, downloading files and then calling textrect() which is the roScreen animation function. At the proper time the textrect() while loop does this:
if m.timex.totalseconds() > 90
DeleteFile("tmp:/z"+curr_photo0.GetName())
DeleteFile("tmp:/z"+curr_photo1.GetName())
DeleteFile("tmp:/z"+curr_photo2.GetName())
DeleteFile("tmp:/z"+curr_photo3.GetName())
DeleteFile("tmp:/z"+curr_photo4.GetName())
DeleteFile("tmp:/z"+curr_photo5.GetName())
DeleteFile("tmp:/z"+curr_photo6.GetName())
DeleteFile("tmp:/z"+curr_photo7.GetName())
DeleteFile("tmp:/z"+curr_photo8.GetName())
DeleteFile("tmp:/z"+curr_photo9.GetName())
screenFull = invalid
screen=invalid
print "Files Deleted"
Reload()
return
exit while
end if

to send it back to restart the process. I'm not looping back to Main(), and I'm returning from textrect() so it should be gone. Still getting this error after 3 cycles so the only thing that has changed from when I was calling Main() is that the error is 3 lines into the textrect() function, not on the function call itself.
Stack overflow. (runtime error &hdf) in .../pkg:/source/motionscreen.brs(245)

245: drawing_regions = dfSetupDisplayRegions(screenFull, topx, topy, w, h)
Kinetics Screensavers
0 Kudos
NewManLiving
Visitor

Re: bitmaps

Most stack exceptions are a result of recursive
Calls to a function directly or indirectly.
All calls to functions are pushed onto the stack
When the function returns it is popped off If you are
Calling the same function either in the body of the
That Function itself or through another function that
Is called by That Function but ends up calling That
Function itself you will bomb out. Make sure all your
Functions return completely before calling them
Again. Make sure any functions that are called
By That Function do not call its caller. I know
This is confusing but that is what recursive means
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
squirreltown
Roku Guru

Re: bitmaps

Thank you NewManLiving for that explanation, I finally got it. Like you said I needed to return completely. I added a wait loop to Main() that launches the process and just put a return in the roscreen function so that it exits without going somewhere, now It loops forever without overflowing. Thanks for the help.
Kinetics Screensavers
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.