Sign in to follow this  
Followers 0
erebus

Sleep error?

8 posts in this topic

I searched the forum a bit but with no luck.. Here is my code:

Func DisplayBanners()
; Search for the JPG banners
    $search = FileFindFirstFile($path & "*." & $type)

; Check if the search was successful
    If $search = -1 Then
        MsgBox(16, $app & " " & $ver, "No " & $type & " files were found in " & $path & ". " & $app & " cannot proceed.")
        Terminate()
    EndIf

; Start displaying banners
    While 1
        $file = FileFindNextFile($search)

        If $file = "." Or $file = ".." Then ContinueLoop
        If @error Then
            FileClose($search)
            DisplayBanners()
        EndIf
    
        SplashImageOn($app & " " & $ver, $file, 160, 600, @DesktopWidth-165, @DesktopHeight-635, 3)
        
        If $fade>0 And $fade<255 Then
            WinSetTrans($app & " " & $ver, "", $fade)
            If @error Then
                MsgBox(16, $app & " " & $ver, "Transparency isn't supported by your OS. Please use the value '255' in the configurarion file. " & @LF & $app & " cannot proceed.")
                Terminate()
            EndIf
        EndIf

        Sleep($delay)
    WEnd
EndFunc

You see this "Sleep" function at the end of the code so as to allow the program delay before every SplashImageOn. The problem is that my program runs fine but after some time (more than an hour for sure) it produces the following error:

Line 0 (File "blah blah")

Sleep($delay)

Error: Recursion level has been exceeded - AutoIt will quit to prevent stack overflow.

Maybe I have missed something here, but I can't figure out what is it...

Thank you.

Share this post


Link to post
Share on other sites



You are in the recursion game.

DisplayBanners is calling DisplayBanners.

The logic inside DisplayBanners must have a way to return. In your case there is nothing so the recursion will occurs and you will reach the recursion maximum limit which produce the error.

Share this post


Link to post
Share on other sites

I can see your point.

However that is why I wrote this part of the code as a function, so as to call it again when I have no more files to display.

I used to have another similar problem yesterday with "invalid type handlers" which was solved by adding a FileClose($search) where it should be.

My question now (since I can't see how to solve this): Can I avoid this recursion somehow? The only thing I want is when I have no more files to read to run the function again so to start over. So probably the problem resides here:

If @error Then
            FileClose($search)
            DisplayBanners()
        EndIf

Any ideas?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Ok it seems that it works fine now. Just added this in my code:

While 1

DisplayBanners()

WEnd

So as to call it forever. Thanks for your answers guys, helped me a lot.

Edited by erebus

Share this post


Link to post
Share on other sites

However that is why I wrote this part of the code as a function, so as to call it again when I have no more files to display.

Use this.

while 1
    DisplayBanners("C:\pics\", "jpg")
wend

Func DisplayBanners($path, $type)

; Search for the JPG banners
    $search = FileFindFirstFile($path & "*." & $type)
; Check if the search was successful
    If $search = -1 Then
        MsgBox(16, $app & " " & $ver, "No " & $type & " files were found in " & $path & ". " & $app & " cannot proceed.")
        Terminate()
    EndIf

; Start displaying banners
    While 1
        $file = FileFindNextFile($search)

        If $file = "." Or $file = ".." Then ContinueLoop
        If @error Then
            FileClose($search)
            exitloop        
        EndIf
    
        SplashImageOn($app & " " & $ver, $file, 160, 600, @DesktopWidth-165, @DesktopHeight-635, 3)
        
        If $fade>0 And $fade<255 Then
            WinSetTrans($app & " " & $ver, "", $fade)
            If @error Then
                MsgBox(16, $app & " " & $ver, "Transparency isn't supported by your OS. Please use the value '255' in the configurarion file. " & @LF & $app & " cannot proceed.")
                Terminate()
            EndIf
        EndIf

        Sleep($delay)
    WEnd
EndFunc

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Haha, exactly what I thought right now!

Thank you very much /dev/null, I really appreciate it. :)

Share this post


Link to post
Share on other sites

Haha, exactly what I thought right now!

Thank you very much /dev/null, I really appreciate it. :evil:

<{POST_SNAPBACK}>

well, you have been faster :)

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

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  
Followers 0