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

runtime error 18: Type Mismatch

The third line here sometimes causes a crash with "runtime error 18: Type Mismatch":


if( rsp = invalid ) fatal_connection_error()
xml = CreateObject("roXMLElement")
if not xml.Parse(rsp) then


The rsp variable might contain a string or it might contain invalid. The string might not be valid xml, sure, but I don't think that the error in that case would be a type mismatch. The value might be invalid, but in that case the fatal_connection_error() call will prevent processing reaching the line with the type mismatch.

So it must be xml.Parse that is the mismatch. xml must contain a thing that is not an roXMLElement. Most likely it's invalid.

That implies that Brightscript apps need to always check for allocation errors in CreateObject(). We can do that, and I guess we will, but all we'll do with the failure is to shut down with a prettier error screen than a crash will give you.

Ideas welcome.
0 Kudos
6 REPLIES 6
renojim
Community Streaming Expert

Re: runtime error 18: Type Mismatch

How exactly does fatal_connection_error() prevent the following statements from executing? Does it never return? Shouldn't there be an 'else' in there someplace?

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
TheEndless
Channel Surfer

Re: runtime error 18: Type Mismatch

If the xml object weren't valid, you wouldn't get a Type Mismatch. The problem is almost definitely the rsp variable. What is the code that sets that?
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
kbenson
Visitor

Re: runtime error 18: Type Mismatch

somehow, rsp is invalid. xml was correctly assigned, otherwise you would get an error about trying to access an invalid method or attribute of a brightscript object (I forget the exact wording), since there would be no parse method if the object wasn't assigned correctly. I suggest testing that the "fatal_connection_error()" function is actually stopping the channel.
-- GandK Labs
Check out Reversi! in the channel store!
0 Kudos
lucasgonze
Visitor

Re: runtime error 18: Type Mismatch

fatal_connection_error() is supposed to exit. It's gives a screen that says you have crashed, sorry, etc.

I wonder if there's a way out of it that we're not aware of? Maybe the back key in that screen takes the user back to the calling routine, and then control flows down to the xml.parse() call.

TheEndless, the code that sets it either returns invalid or returns the value of a getString() on an roUrlTransfer object. So if getString can return something which would cause the xml parser to throw a type mismatch, that could also be the cause.
0 Kudos
TheEndless
Channel Surfer

Re: runtime error 18: Type Mismatch

Have you tried checking the Type of rsp when it crashes in the debugger?
?Type(rsp)
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
lucasgonze
Visitor

Re: runtime error 18: Type Mismatch

"TheEndless" wrote:
Have you tried checking the Type of rsp when it crashes in the debugger?
?Type(rsp)


All I know is that the system crash logs are seeing the error thrown. I don't even know about the overall system flow to get there.

My plan of attack to see about forcing rsp to invalid, then going into the fatal error screen and looking for a way to get back to the calling routine.
0 Kudos