Roku channel not exiting

Hello All,
I wrote a roku channel, I have a function main() as entry point, which then opens another function homescreen(), when I hit back button in homescreen I can see in the debugger console that the homescreen function has returned control to the main function and the print line in main() function below the homescreen() function call is being printed. But the channel is not exiting. Its showing blank screen.
I had no luck with End / Stop.
Is there someone who had this issue and fixed it? Thanks.

I know you had to have checked this, but the code isn’t there so I can’t be sure… Is there any reason Main() wouldn’t be exiting?

As dcrandall noted, there’s no way for us to help you without seeing your code. Can you post your main() and homescreen() functions?

Make sure you homescreen() function has a return statement after the msg.isScreenClosed() event-detection logic. Also make sure you havent created an roImageCanvas in-line within a function that has another screen active within it.

  • Joel

Below is short snippet of my code. On back button press I can see “Reached End” printed in debugger console, but the channel doesn’t exit. I am not using roImageCanvas anywhere in the project.

Function Main()
	
    'Apply the theme
    initTheme()
	
 
    if GetAuthData() <> invalid then
        response1=APICall(GetAPIurl()+"linked_roku.php?roku_code="+GetAuthData()) 
    else
        showRegistration()
    endif

    
    if response1 <> invalid then
	    if response1.status="true" then
		'Show HOmeScreen
		print "Status true"
		SetXtraData("ctv_userid",response1.user.id)       		
		homeScreen(0,2)
	    else 		
		showRegistration()
		
	    endif
    endif
    print "Reached End"    

End Function
function homeScreen(row as Integer,col as Integer)  

    'Normal API call for listing items	in roGridScreen 

    dialog=ShowPleaseWait("Please wait","")
    grid.SetUpBehaviorAtTopRow("stop")
    grid.Show() 
    dialog.close()
    while true
	mresponse=APICall(GetAPIurl()+"message.php")
	if mresponse.message <> invalid
		if mresponse.message="r"
			homeScreen(0,2)
		else
		   'open roMessageDialog using a function call 
		endif	
	endif 
	if type(msg) = "roGridScreenEvent" then
	    if msg.isScreenClosed() then
		return -1
		exit while
	    elseif msg.isListItemFocused()
		'no operation here
            elseif msg.isListItemSelected()
		'opens roSpringboardScreen  using a function call
            elseif msg.isRemoteKeyPressed()
		'opens roMessageDialog using a functional call
	    endif
      end if
    end while
end function
   
Function ShowPleaseWait(title As dynamic, text As dynamic) As Object
    port = CreateObject("roMessagePort")
    dialog = CreateObject("roOneLineDialog")
    dialog.SetMessagePort(port)
    dialog.SetTitle(title)
    dialog.ShowBusyAnimation()
    dialog.Show()
    return dialog
End Function

Thanks

You could ‘ignore’ the problem by adding END on the line below the print for Reached End - to insure the app exits when you want it to.
The code you posted is incomplete (as you are missing at least one “end if” in the homescreeen function) - which would have been caught by the debugger when you sideloaded the channel app.

My guess would be that the channel is actually crashing, which will prevent the channel from closing, when sideloaded, so you can debug the crash. What output do you see in the debug console?

Sorry for the endif missing in the snippet pasted here. The channel is not crashing. There is no error in debugger console. The mistake was only when I pasted my code here. And adding End after the print for “Reached End” didn’t help. The channel doesn’t close, remains open with a blank white screen.

“TheEndless” wrote:
My guess would be that the channel is actually crashing, which will prevent the channel from closing, when sideloaded, so you can debug the crash.
Your diagnosis is spot-on.

It always confuses me though, when someone says “crashing” about an Roku app that is in “interrupted” or “stopped”* state. If i really try to hone a metaphor, dev.channel is left in a “vegetative state” since UI is “wakeful” (some UI elements function and events may get queued) while BrightScript code is “unconscious”. Subsequently, a side-loaded channel may regain consciousness, while a workhorse one gets shot.

(*) after the STOP statement for willfully breaking into console.

If it’s printing “Reached End” – is this print anywhere else in your code files? It might not be at the place you think it is.
“End” would exit the channel if it executes a single end statement.

“opnchaudhary” wrote:
Sorry for the endif missing in the snippet pasted here. The channel is not crashing. There is no error in debugger console. The mistake was only when I pasted my code here. And adding End after the print for “Reached End” didn’t help. The channel doesn’t close, remains open with a blank white screen.
String missing ending quote. (compile error &hb3) in …

   mresponse=APICall(GetAPIurl()+"message.php)

If that was just another typo that was fixed later, what you describe would be highly unusual and i have never seen it.
What player model and firmware are you debugging on?
Can you give a minimal working code that demonstrates the behavior?
(the code snippet above has too many dependencies of functions and global N/A to be useful)