neowinston
neowinston

Reputation: 7764

How do I call XML code from Brightscript for a Roku Channel?

I'm trying to populate a Label List using the below XML Roku Channel, Scenegraph code. I'm getting these errors:

BRIGHTSCRIPT: ERROR: roSGScreen: creating MAIN|TASK-only component failed on RENDER thread: pkg:/components/screens/DetailsScreen/DetailsScreen.brs(101)
BRIGHTSCRIPT: ERROR: roMessagePort: Trying to construct a message port on a non-plugin thread: pkg:/components/screens/DetailsScreen/DetailsScreen.brs(102) 

Invoking Brightscript code:

   ' on Button press handle
Sub onItemSelected()
    showChannelSGScreen()
End Sub

sub showChannelSGScreen()
  screen = CreateObject("roSGScreen")
  m.port = CreateObject("roMessagePort")
  screen.setMessagePort(m.port)
  scene = screen.CreateScene("LabelListExample")
  screen.show()

  while(true)
    msg = wait(0, m.port)
    msgType = type(msg)

    if msgType = "roSGScreenEvent"
      if msg.isScreenClosed() then return
    end if
  end while

end sub

XML code:

<?xml version = "1.0" encoding = "utf-8" ?>

<!--********** Copyright 2016 Roku Corp.  All Rights Reserved. **********-->

<component name = "LabelListExample" extends = "Group" initialFocus = "exampleLabelList" >

  <script type = "text/brightscript" >

    <![CDATA[

    sub init()
      examplerect = m.top.boundingRect()
      centerx = (1280 - examplerect.width) / 2
      centery = (720 - examplerect.height) / 2
      m.top.translation = [ centerx, centery ]
    end sub

    ]]>

  </script>

  <children >

    <LabelList id = "exampleLabelList" >

      <ContentNode role = "content" >
        <ContentNode title = "Renderable Nodes" />
        <ContentNode title = "Z-Order/Parent-Child" />
        <ContentNode title = "Animations" />
        <ContentNode title = "Events and Observers" />
      </ContentNode>

    </LabelList>

  </children>

</component>

My question is: What's the proper way to call the XML from the Brightscript?

*****Full error message**:

BRIGHTSCRIPT: ERROR: roSGScreen: creating MAIN|TASK-only component failed on RENDER thread: pkg:/components/screens/DetailsScreen/DetailsScreen.brs(101)
BRIGHTSCRIPT: ERROR: roMessagePort: Trying to construct a message port on a non-plugin thread: pkg:/components/screens/DetailsScreen/DetailsScreen.brs(102)

BrightScript Micro Debugger.
Enter any BrightScript statement, debug commands, or HELP.

Suspending threads...
Thread selected:  1*   ...ailsScreen/DetailsScreen.brs(103)    screen.setMessagePort(m.port)

Current Function:
100:  sub showChannelSGScreen()
101:    screen = CreateObject("roSGScreen")
102:    m.port = CreateObject("roMessagePort")
103:*   screen.setMessagePort(m.port)
104:    scene = screen.CreateScene("LabelListExample")
105:    screen.show()
106:  
107:    while(true)
'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in pkg:/components/screens/DetailsScreen/DetailsScreen.brs(103)
103:   screen.setMessagePort(m.port)
Backtrace:
#1  Function showchannelsgscreen() As Void
   file/line: pkg:/components/screens/DetailsScreen/DetailsScreen.brs(103)
#0  Function onitemselected() As Void
   file/line: pkg:/components/screens/DetailsScreen/DetailsScreen.brs(95)
Local Variables:
global           Interface:ifGlobal
m                roAssociativeArray refcnt=3 count:7
screen           Invalid
scene            <uninitialized>
msg              <uninitialized>
msgtype          <uninitialized>
Threads:
ID    Location                                Source Code
 0    pkg:/source/main.brs(20)                msg = wait(0, port)
 1*   ...ailsScreen/DetailsScreen.brs(103)    screen.setMessagePort(m.port)
  *selected

Brightscript Debugger> 
Thread detached
>>> Details >> OnkeyEvent

Thread detached

Upvotes: 3

Views: 922

Answers (3)

Daniel M&#225;rquez
Daniel M&#225;rquez

Reputation: 1

Hi community I'm making an Roku app and I need to create window instance for can surf between it. The develop is inside the main fuction because is the only way that it works.

Also I need to create some moduls that it not depend of the main, I have been investigating and is nesessary the nodes use and task.

This's my code I wonder if you have some example using nodes and task

    screen = CreateObject("roSGScreen")
     m.port = CreateObject("roMessagePort")
     screen.setMessagePort(m.port)
     scene = screen.CreateScene("PlayerScreen")
     screen.show()

Upvotes: 0

ganka
ganka

Reputation: 309

From your error message

BRIGHTSCRIPT: ERROR: roSGScreen: creating MAIN|TASK-only component failed on RENDER thread: pkg:/components/screens/DetailsScreen/DetailsScreen.brs(101)

It is clear that you are creating a screen instance in Render thread. There are two posible ways to achieve the screen navigation

  1. Through Main class when the app is being initiated
  2. By using Task component for creating screen instances and push them to screen stack

I would suggest to use the second option in which you can create and push the screen on your need basis.

In your case you can script the showChannelSGScreen function inside a Task component and RUN the task before you start navigating the screens.

All the best!!!

Upvotes: 1

Eugene Smoliy
Eugene Smoliy

Reputation: 954

CreateScene method should be called only with a scene component as an argument. LabelListExample component in your case is not a scene, because it extends Group. Change this line:

<component name = "LabelListExample" extends = "Group" initialFocus = "exampleLabelList" >

To this:

<component name = "LabelListExample" extends = "Scene" initialFocus = "exampleLabelList" >

Upvotes: 1

Related Questions