text: Opened 5 years ago
  Closed 5 years ago
  #2813 closed Bug (Fixed)
  Accessing "last created control" once GUI deleted - AutoIt HardCrash
  Description
  Today I have another day cleanup of old scripts.
  I changed my own UDF files.
  Most scripts that use these UDF is working properly, only one showed a tendency to HardCrash.
  After a few hour searching, I managed to prepare the reproductive script.
  I know that he is in some sense an unusual but in the best way I know of shows where the error is.
  #include <GUIConstantsEx.au3> ConsoleWrite(@CRLF & 'Checking normal behavior' & @CRLF) GUI() ConsoleWrite(@CRLF & 'Checking AutoIt HardCrash' & @CRLF) GUI(True) Func GUI($bTest = False ) Local $hGUI = GUICreate('TITLE', 100, 100) Local $idEdit = GUICtrlCreateEdit('', 1, 1, 99, 99) GUIDelete($hGUI) ConsoleWrite('$bTest = '&$bTest &' @ScriptLineNumber =' & @ScriptLineNumber & @CRLF) If $bTest = True then ; Here you can see AutoIt HardCrash GUICtrlSetResizing(-1, $GUI_DOCKALL) Else GUICtrlSetResizing($idEdit, $GUI_DOCKALL) EndIf ConsoleWrite('$bTest = '&$bTest &' @ScriptLineNumber =' & @ScriptLineNumber & @CRLF) EndFunc ;==>GUI
  Checked on:
  AutoIt 3.3.10.2 and 3.3.13.10
  Attachments (0)
  Change History (4)
  comment:1 follow-up: ↓ 3 Changed 5 years ago by Melba23
  comment:2 Changed 5 years ago by Melba23
  - Summary changed from GUICtrlSetResizing(-1, - last created control - AutoIt HardCrash to Accessing "last created control" once GUI deleted - AutoIt HardCrash
  comment:3 in reply to: ↑ 1 Changed 5 years ago by mLipok
  the actual function used is irrelevant
  Yes you have right, but in my script this was not intentional, just a mistake, in a process of massive change.
  So I describe what happend to me.
  I have Gui wrappers like this:
  _GUI_Question($sQuestion)
  _GUI_Info('$sMessage')
  and my main gui lets call them:
  _GUI_FRAMEWORK_INIT()
  I can add TabItem to existing GUI_FRAMEWORK
  So some controls was created and deleted when _GUI_Question() was called , to ask user for config option when my program starts, and then I missed to initialize _GUI_FRAMEWORK_INIT() before I add new TabItem (I change the place where GUI_FRAMEWORK is initialized).
  Actually I'm making a massive change in my old (but working and still developed) scripts. So that issue, just happens.
  comment:4 the problem is caused by trying to reference the "last created control" once the GUI containing it has been deleted - the actual function used is irrelevant (I have amended the ticket title to reflect this). No doubt the internal reference to this control has been deleted along with the GUI.
  I would argue that using the "-1" shorthand should be avoided wherever possible - which would render the problem moot - and that trying to access controls once the GUI holding them has been deleted is not something that should be done either. But worth a look to see if there is a simple check which would prevent the crash.
  M23