I have a Scene Graph channel with a Scene Graph private screensaver. The screensaver uses a Task node, which gets started when the screensaver starts. I would expect that each time the screensaver exits, the Task thread would terminate, to be started anew the next time the screensaver runs. However, the screensaver Task thread does not terminate when the screensaver exits. Consequently, each time the screensaver runs, a new Task thread is spawned, and ALL Task threads from prior invocations of the screensaver continue to run simultaneously.
Is this a bug, or am I doing something wrong??? I'm using a Roku 2XS, Model 3100X, Software version 7.5.0 • build 4099-02.
Here's some code that demonstrates the problem. Run the channel, wait for the screensaver to activate, then exit the screensaver back to the main thread. Repeat several times. Observe output from multiple instances of the Task node in the debug console.
components/MainScene.xml<?xml version="1.0" encoding="UTF-8"?>
<component name="MainScene" extends="Scene">
<children>
<Label
id="label"
text="Hello, World!"
color="0x0000ffff"
width="1280"
height="720"
horizAlign="center"
vertAlign="center" />
</children>
<script type="text/brightscript" >
<![CDATA[
sub init()
label = m.top.findNode("label")
label.font = "font:LargeSystemFont"
label.font.size = 150
end sub
]]>
</script>
</component>
components/Screensaver.xml<?xml version="1.0" encoding="UTF-8"?>
<component name="Screensaver" extends="Scene">
<children>
<Label
id="label"
text="Screensaver!"
color="0x00ffffff"
width="1280"
height="720"
horizAlign="center"
vertAlign="center" />
<TaskScreensaver id="taskScreensaver" control="RUN" />
</children>
<script type="text/brightscript" >
<![CDATA[
sub init()
label = m.top.findNode("label")
label.font = "font:LargeSystemFont"
label.font.size = 150
end sub
]]>
</script>
</component>
components/TaskScreensaver.xml
<?xml version="1.0" encoding="UTF-8"?>
<component name="TaskScreensaver" extends="Task">
<script type="text/brightscript" >
<![CDATA[
sub init()
m.top.functionName = "taskRun"
end sub
sub taskRun()
taskId = CreateObject("roDateTime").ToISOString()
port = CreateObject("roMessagePort")
while true
Wait(5000, port)
print taskId
end while
end sub
]]>
</script>
</component>
source/Main.brssub Main()
screen = CreateObject("roSGScreen")
scene = screen.createScene("MainScene")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
screen.Show()
while true
msg = Wait(0, port)
if Type(msg) = "roSGScreenEvent"
if msg.IsScreenClosed()
exit while
end if
end if
end while
end sub
source/Screensaver.brssub RunScreenSaver()
screen = CreateObject("roSGScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
scene = screen.CreateScene("Screensaver")
screen.Show()
while true
msg = Wait(0, port)
if Type(msg) = "roSGScreenEvent"
if msg.IsScreenClosed()
exit while
end if
end if
end while
end sub
manifest
title=Screensaver Task Test
major_version=1
minor_version=0
build_version=0
mm_icon_focus_hd=pkg:/images/FocusHD-540x405.png
splash_screen_fhd=pkg:/images/SplashFHD-1920x1080.png
screensaver_title=Screensaver
screensaver_private=1
ui_resolutions=hd