[v2] var is set to "" after return in function when called by a timer Topic is solved

Report problems with documented functionality
User avatar
aseiot
Posts: 79
Joined: 05 Mar 2017, 04:25

[v2] var is set to "" after return in function when called by a timer

Post by aseiot » 27 Mar 2023, 08:51

Demonstrated as follow:

Code: Select all

SetTimer(timer,200)
test()

test(){
	a := 0
	try{
		a:="something"					; should be string to reproduce the issue
		Sleep(1000)					; to wait timer
		return a						; a will be set to "" after return
	}finally{
		if a							;suppose always true, but a is "" when called in timer thread
			msgbox "yes"
	}
}

timer(){
	SetTimer(timer,0)
	test()
}

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: [v2] var is set to "" after return in function when called by a timer

Post by lexikos » 19 Jun 2023, 06:51

I was thrown off by the MsgBox being displayed, but I suppose that it should be displayed twice.

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: [v2] var is set to "" after return in function when called by a timer

Post by lexikos » 20 Jun 2023, 04:18

This demonstrates the issue much more clearly:

Code: Select all

test() {
	; "For performance reasons, freeing a variable whose previous capacity was less than
	; 64 characters might have no effect because its memory is of a permanent type."
	; Therefore, this ensures the variable has dynamic, non-permanent memory:
	VarSetStrCapacity(&v, 64)
	v := "Hello"
	try
		return v
	finally
		MsgBox 'v = "' v '"',, v = "Hello" ? '' : 'Iconx'
}
test
; Expected result: MsgBox with v = "Hello".
; Actual result: MsgBox with v = "".

User avatar
aseiot
Posts: 79
Joined: 05 Mar 2017, 04:25

Re: [v2] var is set to "" after return in function when called by a timer

Post by aseiot » 20 Jun 2023, 19:42

Thank you for confirming this issue.


Post Reply

Return to “Bug Reports”