3

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
neowinston
  • 7,584
  • 10
  • 52
  • 83

3 Answers3

1

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" >
Eugene Smoliy
  • 934
  • 4
  • 9
  • Hello Eugene, thanks for your reply. I'm still have the same error, after your suggestion. I've updated my question with the full error message. Would please take a look at it? Thanks again! – neowinston Aug 10 '17 at 18:25
  • Make sure you are not running showChannelSGScreen function in a Render thread. This function should be called in Main thread. – Eugene Smoliy Aug 11 '17 at 11:52
  • Dear Eugene, thanks for helping me. I'm calling showChannelSGScreen in Sub onItemSelected(). I think that's the Main Thread, right? – neowinston Aug 11 '17 at 12:49
  • No, it is a Render thread. Essentially, you would need creating roSGScreen only once, at the start of an app. – Eugene Smoliy Aug 11 '17 at 14:45
  • So, instead of calling screen = CreateObject("roSGScreen"), how do I invoke this new screen? Would please include de code in your answer? Thank you! – neowinston Aug 11 '17 at 15:05
  • Would you please include how to call it from the Main Thread? Thanks a lot. – neowinston Aug 11 '17 at 15:16
  • The problem is that I'm trying to populate a Label List after the channel has started, as another screen. – neowinston Aug 11 '17 at 15:32
1

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!!!

ganka
  • 191
  • 1
  • 11
0

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()
  • 2
    Hi Daniel and welcome to the Stackoverflow community! For someone to help you, please create a new question. If you post here under this question nobody will be able to find your question and help you. Thank you! Here is the link: https://stackoverflow.com/questions/ask – neowinston Jun 18 '21 at 18:23