Jump to content

Gui Input Control Crashing Autoit


Recommended Posts

Hi the following code causes autoit to crash

Release + beta - Autoit / tried each - both crash.

Could some one confirm if getting same result.

reduced code for testing only.

Idea is user clicks button asking for a few digit input. Closes after x seconds.

#include <GuiConstants.au3>
GuiCreate("MyGUI", 392, 323,(@DesktopWidth-392)/2, (@DesktopHeight-323)/2 )

$Button_1 = GuiCtrlCreateButton("Test", 60, 50, 70, 40)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_1
        test()
    Case Else
    ;;;
    EndSelect
WEnd
Exit

func test()
    $testbox=GUICtrlCreateInput("Test",200,70,100,25)
    Sleep(3000)
    GUICtrlDelete($testbox)
EndFunc

Type something into the box, it closes automatically after 3 seconds then press TEST button again to repeat , BANG autoit crashes.

Is my code doing something illegal here? Or is this a bug.

Thanks

HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to comment
Share on other sites

#include <GuiConstants.au3>
GuiCreate("MyGUI", 392, 323,(@DesktopWidth-392)/2, (@DesktopHeight-323)/2 )

$Button_1 = GuiCtrlCreateButton("Test", 60, 50, 70, 40)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_1
        test()
    EndSelect
WEnd
Exit

func test()
    Dim $testbox ; <-- You have to do this to nullify the control completely
    $testbox=GUICtrlCreateInput("Test",200,70,100,25)
    Sleep(3000)
    GUICtrlDelete($testbox)
EndFunc

Now it doesnt crash...

C ya

Link to comment
Share on other sites

#include <GuiConstants.au3>
GuiCreate("MyGUI", 392, 323,(@DesktopWidth-392)/2, (@DesktopHeight-323)/2 )

$Button_1 = GuiCtrlCreateButton("Test", 60, 50, 70, 40)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_1
        test()
    EndSelect
WEnd
Exit

func test()
    Dim $testbox; <-- You have to do this to nullify the control completely
    $testbox=GUICtrlCreateInput("Test",200,70,100,25)
    Sleep(3000)
    GUICtrlDelete($testbox)
EndFunc

Now it doesnt crash...

C ya

<{POST_SNAPBACK}>

hgeras

Nope still crashes !...

Thx for your time though

HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to comment
Share on other sites

  • Moderators

#include <GuiConstants.au3>
GuiCreate("MyGUI", 392, 323,(@DesktopWidth-392)/2, (@DesktopHeight-323)/2 )

$Button_1 = GuiCtrlCreateButton("Test", 60, 50, 70, 40)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_1
        test()
    EndSelect
WEnd
Exit

func test()
    $testbox=GUICtrlCreateInput("Test",200,70,100,25)
    GUISetState(); you added a new GUI control, but never set the state for the GUI again
    Sleep(3000)
    GUICtrlDelete($testbox)
EndFunc

Edit: Fixed misspelled word.

Edited by ronsrules

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Or this might be better... dunno (not really a gui nut :whistle: )

func test()
    $testbox=GUICtrlCreateInput("Test",200,70,100,25)
    GUICtrlSetState($testbox,""); you added a new guictrl, but never set the state for the gui again
    Sleep(3000)
    GUICtrlDelete($testbox)
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Now this code works 100%...

#include <GuiConstants.au3>
GuiCreate("MyGUI", 392, 323,(@DesktopWidth-392)/2, (@DesktopHeight-323)/2 )

$Button_1 = GuiCtrlCreateButton("Test", 60, 50, 70, 40)
Dim $testbox
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_1
        test()
    EndSelect
WEnd
Exit

func test()
    
    $testbox=GUICtrlCreateInput("Test",200,70,100,25)
    Sleep(3000)
    Guictrlsetdata($testbox,"Test");<-- Add this before deleting the control
    GUICtrlDelete($testbox)
    
EndFunc

The crash happens when the control has different data when it was first made and then deleted.... So if you Create input ,be sure to return it in its creation data.In that case , when it was made it had "Test" for data. If you write in the input "12345" then it will crash next time you press button.So you set the data in the input right before deleting it again to "Test".If the creation value was "" then you should put "" again before deleting....

C ya

Edited by hgeras
Link to comment
Share on other sites

Now this code works 100%...

#include <GuiConstants.au3>
GuiCreate("MyGUI", 392, 323,(@DesktopWidth-392)/2, (@DesktopHeight-323)/2 )

$Button_1 = GuiCtrlCreateButton("Test", 60, 50, 70, 40)
Dim $testbox
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_1
        test()
    EndSelect
WEnd
Exit

func test()
    
    $testbox=GUICtrlCreateInput("Test",200,70,100,25)
    Sleep(3000)
    Guictrlsetdata($testbox,"Test");<-- Add this before deleting the control
    GUICtrlDelete($testbox)
    
EndFunc

The crash happens when the control has different data when it was first made and then deleted.... So if you Create input ,be sure to return it in its creation data.In that case , when it was made it had "Test" for data. If you write in the input "12345"  then it will crash next time you press button.So you set the data in the input right before deleting it again to "Test".If the creation value was "" then you should put "" again before deleting....

C ya

<{POST_SNAPBACK}>

@ron / no go ron, i tried that already.

Well done hgeras, that did it.

Thank you both for sharing the problem.

@developers, no mention of this in documentation, can it be added.? Or is this just unique failure in the dirty method im using?

Hardcopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to comment
Share on other sites

  • Moderators

ahh... lol, add the one word "Test", well at least I set hgeras on the right path :whistle: , glad it works for ya.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...