Jump to content
Sign in to follow this  
CyberSlug

Critical Sections...

Recommended Posts

I've run into some potential problems with the way hotkeys preempt GUI code.....

Example Psuedo-code which could/would crash on occasion with "Array variable subscript badly formatted." Error

HotKeySet("{Delete}", "RemoveSelectedControl")
;...
Dim $InfoAboutControls[4096]
Global $HandleForCurrentControl
;...


While 1
    $msg = GuiGetMsg()
  ;....
    
  ;---Code to process moving a control (drag-n-drop)---
    If $HandleForCurrentControl > 0 Then;Make sure we have a valid control handle
  ; ***** oops user pressed Delete key and we get pre-empted
  ; ***** user removed the selected control.
  ; ***** Returning from the RemoveSelectedControl function and resuming here:
        GuiCtrlSetPos($InfoAboutControls[$HandleForCurrentControl], $newLeftPosition, $newTopPosition)
    EndIf
WEnd

Func RemoveSelectedControl()
    $HandleForCurrentControl = -1
EndFunc

EDIT: fixed typos :lmao:

If we had some mechanism of denoting a critical section around the If-statement, the problem should be avoided.

Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

I've run into some potential problems with the way hotkeys preempt GUI code.....

Example Psuedo-code which could/would crash on occasion with "Array variable subscript badly formatted." Error

HotKeySet("{Delete}", "RemoveSelectedControl")
;...
Dim $InfoAboutControls[4096]
Global $HandleForCurrentControl
;...
While 1
    $msg = GuiGetMsg()
  ;....
    
  ;---Code to process moving a control (drag-n-drop)---
    If $HandleForCurrentControl > 0 Then;Make sure we have a valid control handle
  ; ***** oops user pressed Delete key and we get pre-empted
  ; ***** user removed the selected control.
  ; ***** Returning from the RemoveSelectedControl function and resuming here:
        GuiCtrlSetPos($InfoAboutControls[$HandleForCurrentControl], $newLeftPosition, $newTopPosition)
    EndIf
WEnd

Func RemoveSelectedControl()
    $HandleForCurrentControl = -1
EndFunc

EDIT:  fixed typos  :lmao:

If we had some mechanism of denoting a critical section around the If-statement, the problem should be avoided.

Should be easy enough. Just a EnterCriticalSection() and LeaveCriticalSection() set of functions that disable adlib/hotkeys/onevents.

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...