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

[SOLVED] Getting weird exception

Hi all, I'm new to roku development, and I'm encountering a strange error that I haven't been able to debug. Was wondering if some of you gurus could lend me your eyes 😄

Basically, I'm trying to create an intrinsic object to wrap up some json rpc functionality, and it keeps crashing whenever I access members of the object (both functions and data members crash).

Here's how I create the object:

function CreateAPI(hostAddress = "" as string) as object
api = CreateObject("roAssociativeArray")
api.HostAddress = hostAddress
api.ClientID = ""

api.ReceiveResponse = API_Receive
api.Call = API_CALL

return api
end function

Here's the function I'm testing with:

function debugAPI()
print "Creating API object"
api = CreateAPI("http://192.168.128.110/jsonrpc/")

print "Checking validity"
if api = invalid
print "API is invalid"
else
print "API is valid"
end if

print "Calling API(";api.HostAddress;")" <--- This line crashes
result = api.Call("Server.RegisterClient") <--- This one too

print "Execution successful"
end function


Any ideas what's going on?
0 Kudos
7 REPLIES 7
RokuChris
Roku Employee
Roku Employee

Re: Getting weird exception

It would be helpful if you shared the text of the crash(es), but off the top of my head...

    print "Calling API(";api.HostAddress;")"          <--- This line crashes

Probably the nested quotes are the problem. Try something like:
print "Calling API(" + Chr(34) + ";api.HostAddress;" + Chr(34) + ")"


result = api.Call("Server.RegisterClient")        <--- This one too

This would initiate a call to a function called API_CALL(). Is that function defined somewhere?
0 Kudos
Rek
Visitor

Re: Getting weird exception

"RokuChris" wrote:
It would be helpful if you shared the text of the crash(es), but off the top of my head...

    print "Calling API(";api.HostAddress;")"          <--- This line crashes

Probably the nested quotes are the problem. Try something like:
print "Calling API(" + Chr(34) + ";api.HostAddress;" + Chr(34) + ")"


result = api.Call("Server.RegisterClient")        <--- This one too

This would initiate a call to a function called API_CALL(). Is that function defined somewhere?


There are no nested quotes. Just to be sure though, I tried this and it still crashes:

print api.HostAddress


Here's the error text:

'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in ...3W3UR/pkg:/source/appMain.brs(23)

023: print api.HostAddress


And yes, API_Call is defined. Thanks for the quick response by the way 🙂
0 Kudos
Rek
Visitor

Re: Getting weird exception

Ok, here's some more information... apparently intrinsic objects don't work after being returned from a function?

function CreateAPI() as object
api = {}
return api
end function

function debugAPI()
print "Creating API object"
api = CreateAPI()
api.HostAddress = "test" <-- This line crashes... It should just be an
empty roAssociativeArray right? Why would this fail?

print "Checking validity"
if api = invalid
print "API is invalid"
else
print "API is valid"
end if

print "Execution successful"
end function
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: Getting weird exception

The crash indicates that your api variable is invalid for some reason.

But that latest snippet works fine for me. I get this on the console:

Creating API object
Checking validity
API is valid
Execution successful
0 Kudos
Rek
Visitor

Re: Getting weird exception

"RokuChris" wrote:
The crash indicates that your api variable is invalid for some reason.

But that latest snippet works fine for me. I get this on the console:

Creating API object
Checking validity
API is valid
Execution successful


I tried making a new project and running that snippet, and it works for me there too. I suspect the error message is completely wrong, and I need to look somewhere else.
0 Kudos
TheEndless
Channel Surfer

Re: Getting weird exception

"Rek" wrote:
I tried making a new project and running that snippet, and it works for me there too. I suspect the error message is completely wrong, and I need to look somewhere else.

It sounds to me like you're either inadvertently overwriting the api variable at some point, or CreateAPI isn't returning what you think it is. Could you post the actual code you're using?
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
Rek
Visitor

Re: Getting weird exception

Thanks for the help guys, I have worked it out. It was completely unrelated to the code in question. There was a failed UrlTransfer happening, and for whatever reason, it was reporting it as being caused by the wrong line. At least I'm fairly certain that's what was happening... I made sure the UrlTransfer fails cleanly and its no longer an issue. Cheers.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.