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

8.1 CallFunc Scope Issue

Have any of you experienced scoping issues with CallFunc since 8.1?

I have a component with an interface function, when i perform a component.callFunc(), sometimes there there are missing properties on m. For example, i define m.consts = {} in this components init and m.consts is referenced inside the interface function. Sometimes m.consts is accessible, other times the only thing on m is global and top.

Instances of this component are created in a loop in multiple controllers, and in the same way. For example:

    for each tile in section.tiles
      model = row_node.createChild("AssetModel")
      model.content = tile
    end for


Strangely, when CallFunc is called on an instance of this component (AssetModel), for example from ControllerA.brs, everything works as expected. But then when CallFunc is called on an instance of the component created in ControllerB.brs, no m.consts!

The interface function:

FUNCTION GET_BOOKMARK(data as Object) as Integer

  section = CreateObject("roRegistrySection", m.CONSTS.BOOKMARK.SECTION_KEY)
  if section.Exists(m.top.id)
    return section.Read(m.top.id).ToInt()
  end if
  return 0

END FUNCTION



Roku 2 XS 3100X
0 Kudos
3 REPLIES 3
Komag
Roku Guru

Re: 8.1 CallFunc Scope Issue

m can sometimes be the global array, or can be a pointer to "this" array, so maybe this is a case of needing to use GetGlobalAA() either when assigning the info or when looking for it or both.
0 Kudos
twig
Visitor

Re: 8.1 CallFunc Scope Issue

"Komag" wrote:
m can sometimes be the global array, or can be a pointer to "this" array, so maybe this is a case of needing to use GetGlobalAA() either when assigning the info or when looking for it or both.

"Sometimes" being the issue here. Never had this issue on <= 8.0.

I tested codebase on a box still running 8.0 earlier in the week and there's no issue. Looks like a FW regression to me, in the absence of any decent documentation on CallFunc.  

Some input from @Roku would be appreciated, as this is holding up a release. 
0 Kudos
twig
Visitor

Re: 8.1 CallFunc Scope Issue

After some debugging i have discovered that this scope issue relates to the cloned nodes. I have provided code to replicate below. This wasn't the behaviour in 8.0. Can someone confirm if the behaviour is expected?

' main.brs

function RunUserInterface(args as Object)

  my_component = CreateObject("roSgNode", "MyComponent")

  ? "Disappearing Property: " my_component.CallFunc("get_property", {})

  entire_tree = true
  my_cloned_component = my_component.Clone(entire_tree)

  ' Breaks
  ? "Disappearing Property: " my_cloned_component.CallFunc("get_property", {})

end function


<!-- compontents/MyComponent.xml -->

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

<component name="MyComponent" extends="ContentNode">

    <interface>
        <function name="get_property" />
    </interface>

    <script type="text/brightscript" uri="pkg:/components/MyComponent.brs" />

</component>




' compontents/myComponent.brs

function init()
  m.disappearing_property = true
end function

function get_property(data = {}) as Boolean
  return m.disappearing_property
end function

0 Kudos