SetTimeout / ClearTimeout troubles

Find quick help here to get you started with Hollywood
Post Reply
User avatar
mrupp
Posts: 147
Joined: Sun Jan 31, 2021 7:44 pm
Location: Switzerland
Contact:

SetTimeout / ClearTimeout troubles

Post by mrupp »

Hi there
Is there currently a bug in SetTimeout or what am I doing wrong? Reading the docs, SetTimeout should return an ID that can be used to call ClearTimeout to cancel a running timeout, correct? But SetTimeout always seems to return Nil. :?
Here's an example:

Test.hws:

Code: Select all

@REQUIRE "RapaGUI", {Link = True}
@APPTITLE "SetTimeout-Test"
@FILE 1, "TestGUI.xml"

m_timeoutID = Nil

Function p_EventFunc(msg)
	Switch(msg.ID)
	Case "set":
		m_timeoutID = SetTimeout(Nil, p_test, 2000)
		moai.DoMethod("log", "insert", "bottom", "SetTimeout started")	
		moai.DoMethod("log", "insert", "bottom", "m_timeoutID: " .. ToString(m_timeoutID))	
	Case "clear":
		ClearTimeout(m_timeoutID)
		moai.DoMethod("log", "insert", "bottom", "SetTimeout cleared")	
		moai.DoMethod("log", "insert", "bottom", "m_timeoutID: " .. ToString(m_timeoutID))	
	EndSwitch
EndFunction

Function p_test()
	moai.DoMethod("log", "insert", "bottom", "Timeout function executed")	
EndFunction

moai.CreateApp(ReadString(1))
InstallEventHandler({RapaGUI = p_EventFunc})

Repeat
	 WaitEvent
Forever
TestGUI.xml:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">
	<window id="mainWindow" title="SetTimeout">
		<vgroup>
			<hgroup>
				<button id="set">SetTimeout</button>
				<button id="clear">ClearTimeout</button>
			</hgroup>
			<listview id="log" >
				<column/>
			</listview>
		</vgroup>
	</window>
</application>
What am I doing wrong? Please help!
User avatar
airsoftsoftwair
Posts: 5425
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: SetTimeout / ClearTimeout troubles

Post by airsoftsoftwair »

Good spot! This only happens when a plugin replaces Hollywood's inbuilt timer adapter with a custom one. Currently, RapaGUI is the only plugin that does that (and only on Windows, macOS and Linux). Fixed now.

Code: Select all

- Fix: SetTimeout() didn't return a timeout handle when a timer adapter was installed and Nil was passed as the identifier
Post Reply