Jump to content
Sign in to follow this  
Pollux

In trouble with GUIGetMsg()...

Recommended Posts

Pollux

Hi all,

I am a newcomer on this forum even if I have been using autoit from a long time now!

First of all thanks for this brilliant project, autoit really saves a lot of time and is now able to do everything!!

I am currently stuck on an windows crash in one of my functions (something like a bad memory read, unhandled exception??)

The issue happened when upgrading to 3.2.12. Before I was using 3.2.8 (not sure...) and never had any problem with the same pieces of code.

The crash depends on the context.

In some parts of the code, the function works, elsewhere it crashes. But where it crashes it is systematic.

Here is the function:

Func WaitForUserAction( $TimeOutSecs = 0 )

$TickInit = _TimeToTicks(@HOUR,@MIN,@SEC)

$TimeOutSecs *= 1000

$StackedStatus = Opt( "GUIOnEventMode" )

Opt( "GUIOnEventMode", 0 )

; flushing the message queue

While 1

$msg = GUIGetMsg()

If $msg = 0 Then ExitLoop

WEnd

While 1

; strange random bug here...

$msg = GUIGetMsg()

If $msg <> 0 And $msg <> $GUI_EVENT_MOUSEMOVE Then

ExitLoop

EndIf

If $TimeOutSecs <> 0 Then

If (_TimeToTicks(@HOUR,@MIN,@SEC) - $TickInit) > $TimeOutSecs Then

ExitLoop

EndIf

EndIf

Wend

Opt( "GUIOnEventMode", $StackedStatus )

EndFunc

The crash always occurs on the 2nd GUIGetMsg() call.

I guess I do not use it properly or I make something not recommended with the GUIOnEventMode option...

If someone has an idea or already encountered the same kind of issue, it would be great!

There also might exist a build-in or UDF function making the same as mine, but without bug!!!

Any idea?

Thanks...

Share this post


Link to post
Share on other sites
Pollux

Hello,

Just coming back with my question... which may be is not precise enough?

Have you already experienced some random crashes of the same type?

Could it come from memory leaks? Is there a way to track them?

Do you think the method to clean the pending message:

While 1

$msg = GUIGetMsg()

If $msg = 0 Then ExitLoop

WEnd

is correct or should be avoided?

Thank you for your help!

Share this post


Link to post
Share on other sites
weaponx

I don't think this piece of code does anything really:

While 1
        $msg = GUIGetMsg()
        If $msg = 0 Then ExitLoop
    WEnd

This seems to work okay.

#include <GUIConstantsEx.au3>
#include <date.au3>
GuiCreate("test")
GUISetState(@SW_SHOW)
WaitForUserAction()
Func WaitForUserAction( $TimeOutSecs = 0 )

    $TickInit = _TimeToTicks(@HOUR,@MIN,@SEC)
    $TimeOutSecs *= 1000

    $StackedStatus = Opt("GUIOnEventMode")
    Opt("GUIOnEventMode", 0 )

    ; flushing the message queue
    While 1
        $msg = GUIGetMsg()
        If $msg = 0 Then ExitLoop
    WEnd

    While 1
        ; strange random bug here...
        $msg = GUIGetMsg()

        If $msg <> 0 And $msg <> $GUI_EVENT_MOUSEMOVE Then
            ExitLoop
        EndIf

        If $TimeOutSecs <> 0 Then
            If (_TimeToTicks(@HOUR,@MIN,@SEC) - $TickInit) > $TimeOutSecs Then
                ExitLoop
            EndIf
        EndIf

    Wend

    Opt( "GUIOnEventMode", $StackedStatus )

EndFunc

Share this post


Link to post
Share on other sites
Pollux

Hi,

Thanks Weaponx for your answer and having taken time to look at it.

I have tried to bypass the issue removing the calls to my WaitForUserAction() function (the place I was sure the problem was happening).

But it stills randomly crashes...

I guess something is going wrong in the code run before, resulting in a delayed crash (sometimes only...).

I am going to investigate and let you know if I find out something.

Thanks again!

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.