Your Digital Media Has Never Looked So Good

 
Arezth
Topic Author
Posts: 19
Joined: Fri Mar 10, 2017 5:00 pm

Using roUrlTransfer from within a scene

Mon Mar 27, 2017 4:52 pm

Hi Forum

I appreciate the help I've gotten so far from you. I came here with a new question. I've tried to create a roUrlTransfer from a scene I've loaded, but as expected it says it is invalid or unitialized. My main.brs is as followed:

 sub RunUserInterface()
    screen = CreateObject("roSGScreen")
    scene = screen.CreateScene("HomeScene")
    port = CreateObject("roMessagePort")
    screen.SetMessagePort(port)
    screen.Show()
....
    scene.gridContent = ParseJsonContent(list)
...
while true
        msg = wait(0, port)
        print "--------- o --------"
        print "msg = "; msg
        print clock
    end while
    
    if screen <> invalid then
        screen.Close()
        screen = invalid
    end if    
end sub


Within this main.brs, I make a few calls using CreateObject("roUrlTransfer") without any problems, but when I tried to create this within my "HomeScene" it wasn't possible. After checking the forum it said that I should use interfaces in order to make the calls, but as far as I understood it can not be referenced directly (it seems roSgNode does not support objects). Global variable is not an option either. Some people create functions in order to make it happen, but I did not understand it fully ( https://forums.roku.com/viewtopic.php?f ... ne#p533154)  Am I too far from the correct way? Can I get some guidance? 
 
EnTerr
** Valued Community Member **
Posts: 3834
Joined: Sun Jan 02, 2011 2:41 am

Re: Using roUrlTransfer from within a scene

Mon Mar 27, 2017 5:21 pm

There are 3 kinds of contexts (sometimes referred to as "threads" because well, execution happens in different threads - which determines the limitations of the context): main, render and task. When function/code is executed in the scene graph render thread, no long-lasting calls are allowed since that thread is the one that redraws the screen tens of times per second - blocking that for e.g. waiting on network call means the screen freezing. Consequently, roUrlTransfer is banned from the render thread - which happens to be all functions/events (init()/onKeyEvent() etc) in a scene. Meaning, you have to do network calls either in the main thread or spin off a task for that.
 
Arezth
Topic Author
Posts: 19
Joined: Fri Mar 10, 2017 5:00 pm

Re: Using roUrlTransfer from within a scene

Mon Apr 17, 2017 10:34 am

Thank you for your reply EnTerr, and sorry for the late reply, I believed I had already done it. I created a Task exclusively to make the calls to the server given your explanation and have worked perfectly so far! Thank you for taking your time explaining it!

Who is online

Users browsing this forum: No registered users and 9 guests