SetTimer and hotkey-activated popup menu in same script can cause crash

Issue #32 closed
Winter Laite created an issue

The code to test is probably too long, my apologies. To duplicate the error reported, repeatedly hit the hotkey (here, Win-Z) followed by escape. Eventually the program will crash. Sometimes it will take 10 to 15 repetitions to crash it, sometimes only one or two.

MyMenu := Menu()
MyMenu.Add("Item 1", "MenuHandler")
MyMenu.Add("Item 2", "MenuHandler")
MyMenu.Add()  ; Add a separator line.

; Create another menu destined to become a submenu of the above menu.
Submenu1 := Menu()
Submenu1.Add("Item A", "MenuHandler")
Submenu1.Add("Item B", "MenuHandler")

; Create a submenu in the first menu (a right-arrow indicator). When the user selects it, the second menu is displayed.
MyMenu.Add("My Submenu", Submenu1)

MyMenu.Add()  ; Add a separator line below the submenu.
MyMenu.Add("Item 3", "MenuHandler")  ; Add another menu item beneath the submenu.

MenuHandler(Item, *) {
    MsgBox("You selected " Item, "ITEM SELECTED")
}

MyGui := Gui(, "Menu Stuff")
MyGui.Opt("+Resize")

MyGui.Add("Edit", "w200 h200", "Where's the beef?")

CheckBoxText := MyGui.Add("Text", "w200", "Checkbox test")
CheckBoxText.SetFont("cBlue s10")
CheckBoxOne := MyGui.Add("CheckBox", "w200", "If this text is long, it will wrap automatically")
CheckBoxOne.OnEvent("Click", "CheckBoxOneClicked")

MousePosText := MyGui.Add("Text", "x10 y+10 cBlue s10 w200", "Uses SetTimer to show mouse position")
CoordText := MyGui.Add("Text", "x10 y+10 cLime", "") 
SetTimer("UpdateOSD", 200)
UpdateOSD()  ; Make the first update immediate rather than waiting for the timer.

MyGui.Show()

#z::MyMenu.Show()  ; i.e. press the Win-Z hotkey to show the menu.

CheckBoxOneClicked() {
    MsgBox("You clicked me, you scorpion!")
    TrayTip("TrayTipTest", "I will see myself out, thanks!")
}

UpdateOSD()
{
    Result := MouseGetPos()
    CoordText.SetFont("bold s20")
    CoordText.Text := ("X: " Result["X"] " Y: " Result["Y"])
}

I tried commenting out the TrayTip, but the process described to to reproduce the bug still crashes Keysharp eventually.

Comments (4)

  1. Matt Feemster repo owner

    I am finding this can reliable crash if I press “F3”, so I will investigate that.

  2. Log in to comment