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

Scene Graph roScene disposal best practices

Hello

I am developing an app with Scene Graph where more than one scene is shown. 

Each screen is abstracted to a controller and each controller presents its own Scene, like this example:
     
      ' Create the splash screen'
      m.screen = CreateObject("roSGScreen")
      m.port = CreateObject("roMessagePort")
      m.screen.setMessagePort(m.port)
      ' Create the component'
      m.scene = m.screen.CreateScene("splash")
      m.screen.show()


When i present another screen, i repeat the same process.

It all works fine.

What i notice though is that when i debug with
sgnodes all



It will tell me that previous Scenes are still there. I am worried this is a memory issue.

I tried removing each Scene individually with scene.Close() before presenting a new one but i get the error


BRIGHTSCRIPT: ERROR: roSGScreen: create screen interrupted.: pkg:/source/controllers/....


What is the best way to remove all nodes in a Scene before presenting a new one?

Thanks,
0 Kudos
7 REPLIES 7
EnTerr
Roku Guru

Re: Scene Graph roScene disposal best practices

I am not sure creating >1 scene is a good idea in RSG. I'd feel better if i see scene transitions API (i.e. how to replace one scene with another, animations etc) - but i dont find that.

What is the reason to wish for >1 scene? Why not just use multiple "subscenes" (ok, so just a Group nodes) under a "One Scene to Rule them All"? https://sdkdocs.roku.com/display/sdkdoc/Scene as such has rather un-interesting features.
0 Kudos
Veeta
Visitor

Re: Scene Graph roScene disposal best practices

I agree with EnTerr.  All of my SG channels have one "Controller" node extending Scene.  It's lifespan is the duration of the app.  It creates and destroys "Screens" which extend "Group"
0 Kudos
juantwc
Visitor

Re: Scene Graph roScene disposal best practices

Thanks for your replies. 

I had one Scene per controller only because it seems more organised. I come from a developer background in iOS and i guess i was trying to have a paradigm similar to each view controller having a view that gets shown/dismissed.

I understand from your replies this is the wrong approach, and i had suspected as much. Thank you for confirming.

So usually you just create one scene and remove nodes manually before inserting others. Can you share some sample code? 

Thanks again. 
0 Kudos
EnTerr
Roku Guru

Re: Scene Graph roScene disposal best practices

"juantwc" wrote:
I understand from your replies this is the wrong approach, and i had suspected as much. Thank you for confirming.

So usually you just create one scene and remove nodes manually before inserting others. Can you share some sample code?

I don't know for a fact that multiple scenes are the wrong approach - just suspicion. If i learn more, i'll let you know.

I imagine you can also hide/unhide whole Group trees - whether usable would depend on the real life performance though
0 Kudos
EnTerr
Roku Guru

Re: Scene Graph roScene disposal best practices

I got a chance to ask someone privy to RSG's mysteries and here is what i heard back:
"Scenography Swami" wrote:
Our recommended usage pattern is to create one RoSGScreen and one Scene node for a channel. You can treat the child nodes of the Scene (or one of its children) as different “views” and add transitions between them (e.g. crossfades, slides, etc.). This provides the same functionality as multiple Scene’s, just a different implementation.

I don’t think there is anything to prevent you from using multiple RoSGScreen’s but setting things up that way might fail to take advantage of future improvements to channel launching transitions, etc.
0 Kudos
juantwc
Visitor

Re: Scene Graph roScene disposal best practices

Thanks man, you are doing God's work  🙂 

Would be cool to see something like this in the SDK documentation (wink wink if anybody out there has the right connections) 
0 Kudos
EnTerr
Roku Guru

Re: Scene Graph roScene disposal best practices

RokuDanny can has   8-)
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.