Good evening,
Recently I posted this code on the forum, in order to get help with an issue. But I am not going to talk about it: I've found a bug (I've found a bug??) related to an excess of callings to the same label recursively (I have used Goto, but it also happens when you replace the Goto with Gosub).
The bug goes as follows: if you try to execute File -> New count more than 10 times, the File -> New count stops working and responding. There seems to be an error with the Goto, but as I mentioned before, if you replace the Goto with a Gosub, the bug will be the same after the 10th execution. Is this a bug of AutoHotkey, or just my fault?
And if it is my fault, what's wrong with the code?
Strange!
[Edited code, thanks to swagfag for pointing out my mistake]
Code: Select all
; Generated by AutoGUI 2.6.2
#SingleInstance Force
#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
Menu FileMenu, Add, New count, NewCount
Menu MenuBar, Add, &File, :FileMenu
Gui, 1: New
Gui, 1: +hWndfirstWindow
Gui, 1: Menu, MenuBar
Gui, 1: Add, Edit, x5 y5 w120 h21 vCounter0
Gui, 1: Add, Edit, x100 y32 w120 h21 vCounter1
Gui, 1: Add, Edit, x150 y64 w120 h21 vCounter2
Gui, 1: Add, Edit, x200 y96 w120 h21 vCounter3
Gui, 1: Add, Edit, x250 y128 w120 h21 vCounter4
Gui Show, w620 h400, Window
Return
NewCount:
msgBox, 8196, Start New Count, Do you want to start new count?
IfMsgBox No
{
return
}
else
{
Gui, %firstWindow%: +Disabled
Gui, %firstWindow%: Hide
Gui, 2: New, -MinimizeBox -MaximizeBox -SysMenu -Caption +AlwaysOnTop
Gui, 2: +Owner1
Gui, 2: +hWndsecondWindow
Gui, 2: Default
Gui, Add, Edit, x240 y368 w120 h21 vfirstNumber, 1
Gui, Add, Button, x100 y100 vButtonNewCount gStartNewCount, Start
Gui, %secondWindow%: Show, w455 h400 x800 y100, Start a new count
}
Return
StartNewCount:
numberChosen:=0
Gui, 2: Submit, NoHide
GuiControlGet, numberChosen, 2:, firstNumber
GuiControl, 1:, Counter0, %numberChosen%
Gui, 1: -Disabled
Gui 2: Destroy
Gui, 1: Default
Gui, %firstWindow%: Show
Goto BeginCount
return
BeginCount:
GuiControlGet, number, 1:, Counter0
while (i<1000)
{
contNumEdit:=1
while(contNumEdit<5)
{
GuiControl, , Counter%contNumEdit%, %number%
number++
contNumEdit++
sleep 1000
}
}
return
GuiEscape:
GuiClose:
ExitApp
I also try this alternative code, with an aditional condition to the loop, and with both GUIs creating and destroying each other, but the bug persists if you start the countings one after another quickly, and from a lower number:
Code: Select all
; Generated by AutoGUI 2.6.2
#SingleInstance Force
#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
Menu FileMenu, Add, New count, NewCount
Menu MenuBar, Add, &File, :FileMenu
Gui, 1: New
Gui, 1: +hWndfirstWindow
Gui, 1: Menu, MenuBar
Gui, 1: Add, Edit, x5 y5 w120 h21 vCounter0
Gui, 1: Add, Edit, x100 y32 w120 h21 vCounter1
Gui, 1: Add, Edit, x150 y64 w120 h21 vCounter2
Gui, 1: Add, Edit, x200 y96 w120 h21 vCounter3
Gui, 1: Add, Edit, x250 y128 w120 h21 vCounter4
Gui Show, w620 h400, Window
Return
NewCount:
msgBox, 8196, Start New Count, Do you want to start new count?
IfMsgBox No
{
return
}
else
{
condition:=0
Gui, %firstWindow%: +Disabled
Gui, %firstWindow%: Destroy
Gui, 2: New, -MinimizeBox -MaximizeBox -SysMenu -Caption +AlwaysOnTop
Gui, 2: +hWndsecondWindow
Gui, 2: Default
Gui, Add, Edit, x240 y368 w120 h21 vfirstNumber, 1
Gui, Add, Button, x100 y100 vButtonNewCount gStartNewCount, Start
Gui, %secondWindow%: Show, w455 h400 x800 y100, Start a new count
}
Return
StartNewCount:
numberChosen:=0
Gui, 2: Submit, NoHide
GuiControlGet, numberChosen, 2:, firstNumber
Menu FileMenu, Add, New count, NewCount
Menu MenuBar, Add, &File, :FileMenu
Gui, 1: New
Gui, 1: +hWndfirstWindow
Gui, 1: Menu, MenuBar
Gui, 1: Add, Edit, x5 y5 w120 h21 vCounter0
Gui, 1: Add, Edit, x100 y32 w120 h21 vCounter1
Gui, 1: Add, Edit, x150 y64 w120 h21 vCounter2
Gui, 1: Add, Edit, x200 y96 w120 h21 vCounter3
Gui, 1: Add, Edit, x250 y128 w120 h21 vCounter4
GuiControl, 1:, Counter0, %numberChosen%
Gui 2: Destroy
Gui, 1: Default
Gui 1: Show, w620 h400, Window
Goto BeginCount
return
BeginCount:
condition:=1
GuiControlGet, number, 1:, Counter0
while (number<1000) and (condition=1)
{
contNumEdit:=1
while(contNumEdit<5)
{
GuiControl, , Counter%contNumEdit%, %number%
number++
contNumEdit++
sleep 1000
}
}
return
GuiEscape:
GuiClose:
ExitApp