NMS Posted July 2 Posted July 2 I'm trying to figure out the best way for me to handle unexpected crashes in my script which right now is a bit over 20000 lines (decompiled). What I'm using is simply calling a function FunctionName('FunctionName') that reads the name of the function in EVERY function inside the script. However aside from writing data later on, I'd like to visually show the function being updated in real-time when specific windows that reads this data is open. Obviously since this function runs an insane amount of times every 0.10 seconds, it leads to label flicker and most importantly the number being practically blurred out (see the attached screenshot of how it actually looks in my program). I did attach a quick example however it doesn't reproduce the exact result since it's quite small in comparison. Is there any way to somehow show this string? I tried using an input control instead but that didn't work. I'm not even sure if this is possible with the amount of updates it does. On average it does 681 updates a second on idle:) This is how it looks in my script: expandcollapse popup#include <GUIConstantsEx.au3> Global $hGUI = GUICreate("Example", 400, 400) Global $idLabel = GUICtrlCreateLabel("", 100, 100, 85, 25) GUISetState(@SW_SHOW, $hGUI) While 1 One() Two() Three() Four() Five() Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($hGUI) ExitLoop EndSwitch WEnd Func One() FunctionName('One') EndFunc Func Two() FunctionName('Two') EndFunc Func Three() FunctionName('Three') EndFunc Func Four() FunctionName('Four') EndFunc Func Five() FunctionName('Five') EndFunc Func FunctionName($TempFunctionName) Local Static $TempLastFunction If $TempLastFunction <> $TempFunctionName Then GUICtrlSetData($idLabel, $TempFunctionName) $TempLastFunction = $TempFunctionName EndFunc
ioa747 Posted July 3 Posted July 3 (edited) Func FunctionName($TempFunctionName) Local Static $TempLastFunction If $TempLastFunction <> $TempFunctionName Then GUICtrlSetData($idLabel, $TempFunctionName) $TempLastFunction = $TempFunctionName ConsoleWrite("$TempFunctionName=" & $TempFunctionName & @CRLF) ; or try to give some time e.g. ;~ Sleep(50) EndFunc Edit: Although it logically tells you which line it crashes on. use the (only with SciTE4AutoIt3) #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/mo #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** this will production a MyScriptName_stripped.au3 file (a single file with all the other includes embedded) so you can understand in which line it crashes on Edited July 3 by ioa747 Edit I know that I know nothing
argumentum Posted July 3 Posted July 3 5 hours ago, NMS said: handle unexpected crashes If it crashes without an error MsgBox or any clue other than a hard crash and, the script is rather large and, you'd like to know what was the last function..., I'd IPC the info to another script that would hold that data in it's side of the IPC. Maybe this does the trick. Otherwise, log to file ? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted July 3 Posted July 3 (edited) 2 hours ago, argumentum said: Maybe this does the trick. actually, that is too slow. FileMap writing is way faster expandcollapse popup#include <FMIPC.au3> ; https://www.autoitscript.com/forum/topic/193277-ipc-udf-via-filemapping-20180404/ _FMIPC_Create("MyFileMappingForWatchDogUniqueName") If @error Then Exit 10 + @error; "MyFileMappingForWatchDogUniqueName" exists #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $g_Form, $g_idEdit, $sGuiTitle = "WatchDog - Last airbender" gui() Func gui() Local $_W = 400, $_H = 300 $g_Form = GUICreate($sGuiTitle, $_W, $_H, 100, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP)) Local $Label = GUICtrlCreateLabel("Last func: ", 5, 7, 60, 17, $SS_RIGHT) GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT) $g_idEdit = GUICtrlCreateEdit("", 0, 20, $_W, $_H - 20, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY)) GUICtrlSetData(-1, "...waiting...") GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM) GUISetState(@SW_SHOW) EndFunc ;==>gui Exit mainLoop() Func mainLoop() Local $sRead, $sSec = @SEC While 1 If $sSec <> @SEC Then $sSec = @SEC $sRead = _FMIPC_Read() If $sRead Then GUICtrlSetData($g_idEdit, $sRead) EndIf Switch GUIGetMsg() Case 0 ; nothing Case $GUI_EVENT_CLOSE GUIDelete() Exit EndSwitch WEnd EndFunc ;==>mainLoop and on the script you'd add the writer/dump : expandcollapse popup#include <FMIPC.au3> ; https://www.autoitscript.com/forum/topic/193277-ipc-udf-via-filemapping-20180404/ #include <GUIConstantsEx.au3> Global $g_iCrashAt = 1000 Global $hGUI = GUICreate("Example", 400, 400) Global $idLabel = GUICtrlCreateLabel("", 100, 100, 85, 25) GUISetState(@SW_SHOW, $hGUI) Global $g_iCounter = 0, $g_iLastCounter, $iSec = @SEC While 1 If $iSec <> @SEC Then $iSec = @SEC $g_iLastCounter = $g_iCounter ConsoleWrite($g_iCounter & @CRLF) $g_iCounter = 0 EndIf One() Two() Three() Four() Five() Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($hGUI) ExitLoop EndSwitch WEnd Func One() FunctionName('One') If Random(0, $g_iCrashAt, 1) = $g_iCrashAt Then Exit 101 ; fake crash EndFunc ;==>One Func Two() FunctionName('Two') If Random(0, $g_iCrashAt, 1) = $g_iCrashAt Then Exit 102 ; fake crash EndFunc ;==>Two Func Three() FunctionName('Three') If Random(0, $g_iCrashAt, 1) = $g_iCrashAt Then Exit 103 ; fake crash EndFunc ;==>Three Func Four() FunctionName('Four') If Random(0, $g_iCrashAt, 1) = $g_iCrashAt Then Exit 104 ; fake crash EndFunc ;==>Four Func Five() FunctionName('Five') If Random(0, $g_iCrashAt, 1) = $g_iCrashAt Then Exit 105 ; fake crash EndFunc ;==>Five Func FunctionName($TempFunctionName) Local Static $TempLastFunction, $iSelfPid = @AutoItPID $g_iCounter += 1 If $TempLastFunction <> $TempFunctionName Then GUICtrlSetData($idLabel, $TempFunctionName) _FMIPC_Write("MyFileMappingForWatchDogUniqueName", $iSelfPid & @TAB & $g_iLastCounter & " " & @SEC & "." & @MSEC & @TAB & $TempFunctionName, 2) EndIf $TempLastFunction = $TempFunctionName EndFunc ;==>FunctionName without slowing your script much. Edited July 3 by argumentum added fake crash Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
NMS Posted July 3 Author Posted July 3 @ioa747 I'm not sure what was supposed to happen as nothing did... @argumentum I was thinking about using IPC and did in fact try after I posted this thread but I ran into an issue where the last bits of data never seemed to have traveled to the child script that watches which was fairly strange. I used StdinWrite() and ConsoleRead() respectively. I'll look into your script as well, thank you.
ioa747 Posted July 3 Posted July 3 12 minutes ago, NMS said: I'm not sure what was supposed to happen as nothing did... relative to which? with ConsoleWrite("$TempFunctionName=" & $TempFunctionName & @CRLF) with Sleep(50) or with #Au3Stripper_Parameters=/mo I know that I know nothing
Developers Jos Posted July 3 Developers Posted July 3 (edited) 10 hours ago, NMS said: which right now is a bit over 20000 lines (decompiled). what do you mean by this? Edited July 3 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
NMS Posted July 3 Author Posted July 3 4 hours ago, ioa747 said: relative to which? with ConsoleWrite("$TempFunctionName=" & $TempFunctionName & @CRLF) with Sleep(50) or with #Au3Stripper_Parameters=/mo With Stripper parameters. Sleep is a no go in my case. 3 hours ago, Jos said: what do you mean by this? In a script form it's 20000+ lines, if compiled which is how I normally run it, it's around 50000 I believe. Can't remember the exact amount.
ioa747 Posted July 3 Posted July 3 With Stripper parameters (only with SciTE4AutoIt3) For it to make sense, you need to have an error message that tells you which line the error is on. The process is, you put the directives as I described above, and you click to compile, along with the compiled program it also gives you the _stripped.au3 file I know that I know nothing
KaFu Posted July 3 Posted July 3 Create a simple GUI like this and let it run. GUICreate("Debugger_Output_GUI", 400, 200) GUICtrlCreateEdit("", 10, 10, 380, 180) GUISetState() While 1 Switch GUIGetMsg() Case -3 ; $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd In the script to debug add trace lines in SciTE via "Tools > Trace: Add Trace Lines". Search and replace ConsoleWrite('>Error code: ' & @error & @CRLF & @CRLF & '@@ Trace( with ControlSetText('Debugger_Output_GUI', '', 'Edit1', '>Error code: ' & @error & @CRLF & @CRLF & '@@ Trace( in your code and then run it. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
KaFu Posted July 3 Posted July 3 Upsa, that was not about the flicker at all 🙂. For that I learned that input controls do not flicker as labels do, maybe the update of these is slower? #include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <WindowsConstants.au3> HotKeySet("{ESC}","_Exit") GUICreate("Example") $c_Label = GUICtrlCreateLabel("",10,10,100,20) $c_Input = GUICtrlCreateInput("",10,40,100,20, $ES_READONLY, $WS_EX_TRANSPARENT) GUISetState(@SW_SHOW) While Sleep(10) $iTimer = TimerInit() GUICtrlSetData($c_Label,$iTimer) GUICtrlSetData($c_Input,$iTimer) WEnd Func _Exit() Exit EndFunc ioa747 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
NMS Posted July 3 Author Posted July 3 2 hours ago, ioa747 said: With Stripper parameters (only with SciTE4AutoIt3) For it to make sense, you need to have an error message that tells you which line the error is on. The process is, you put the directives as I described above, and you click to compile, along with the compiled program it also gives you the _stripped.au3 file 1 hour ago, KaFu said: Create a simple GUI like this and let it run. GUICreate("Debugger_Output_GUI", 400, 200) GUICtrlCreateEdit("", 10, 10, 380, 180) GUISetState() While 1 Switch GUIGetMsg() Case -3 ; $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd In the script to debug add trace lines in SciTE via "Tools > Trace: Add Trace Lines". Search and replace ConsoleWrite('>Error code: ' & @error & @CRLF & @CRLF & '@@ Trace( with ControlSetText('Debugger_Output_GUI', '', 'Edit1', '>Error code: ' & @error & @CRLF & @CRLF & '@@ Trace( in your code and then run it. To both of these suggestions I figured out that since I run SciTE-Lite I don't have that functionality. I remember trying to run the full version couple of years ago however I ran into some error which I couldn't resolve so I gave up. 53 minutes ago, KaFu said: Upsa, that was not about the flicker at all 🙂. For that I learned that input controls do not flicker as labels do, maybe the update of these is slower? #include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <WindowsConstants.au3> HotKeySet("{ESC}","_Exit") GUICreate("Example") $c_Label = GUICtrlCreateLabel("",10,10,100,20) $c_Input = GUICtrlCreateInput("",10,40,100,20, $ES_READONLY, $WS_EX_TRANSPARENT) GUISetState(@SW_SHOW) While Sleep(10) $iTimer = TimerInit() GUICtrlSetData($c_Label,$iTimer) GUICtrlSetData($c_Input,$iTimer) WEnd Func _Exit() Exit EndFunc In my case edit control did much better than input one. The issue was likely very low update rate (hard to tell). So still not perfect. Nevertheless, I figured the fix for the flicker/blur would be very difficult if not impossible to solve so I'll likely stick to IPC once I resolve couple of things there. Thanks!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now