Jump to content

Function causing Stack Overflow in some uses...


Recommended Posts

Hello all,

I'm writing a regression testing suite for some of the software for my company. I've written some tailored functions with error handling for use with these scripts. I'm running into a problem with a particular function I wrote (a combo box select) with one particular combo box that it doesn't have with any other combo box. Here's the function:

Func _ComboBoxSelect($Window_Name, $ControlID, $MaxOptions = 10, $Selection = 1)
    Dim $Test_Results[4]                                                                        ;Initialize the results array
    $Test_Results[0] = "Combo Select"                                                           ;Write the type "Combo Select" to the results array
    $Test_Results[1] = $ControlID                                                               ;Write the control ID to the results array
    $Test_Results[2] = $Selection                                                               ;Write the given selection to the results array
    $Test_Results[3] = "Window doesn't exist."                                                  ;Set the failed value. This will be overwritten if the function passes.
    If WinExists($Window_Name) = 0 Then Return $Test_Results                                    ;If the window doesn't exist, return the results array containing the error
    $Test_Results[3] = "The combo box selection failed."                                        ;Write the new error. This will be overwritten if the function passes.
    For $i = 1 To $MaxOptions                                                                   ;Start a For loop. It will send the proper amount of {UP}s to the combo box to reset it
        If ControlSend($Window_Name,"",$ControlID,"{UP}") = 0 Then Return $Test_Results         ;Send {UP} to the combo box to reset the list and if it fails, return the results array
    Next                                                                                        ;Perform the next iteration of the For loop
    For $i = 1 To $Selection - 1                                                                ;Start a For loop. It will send the proper amount of {DOWN}s specified by the user
        If ControlSend($Window_Name,"",$ControlID,"{DOWN}") = 0 Then Return $Test_Results       ;Send {DOWN} to the combo box and if it fails, return the results array
    Next                                                                                        ;Perform the next iteration of the For loop
    $Test_Results[3] = 1                                                                        ;Write 1 to the results array
    Return $Test_Results                                                                        ;Return the passed results array
EndFunc   ;==>_ComboBoxSelect

Now, I've written a few hundred regression scripts using this function and all have worked just fine. However, I'm running into a problem with two combo boxes where suddenly this function is causing Stack Overflows which crash the software. They are the same type of combo box, same naming scheme, same everything. But I can't figure out why this is suddenly a problem. I've tried running the other scripts, and they work just fine. I doubt that any of you can answer definitively, as you don't have the whole code, nor the software I'm testing. I guess I'm just looking for some ideas I can use to help troubleshoot this problem.

Thanks all!

-Fett

P.S. The native combo box select function doesn't seem to work with these combo boxes, which is why I had to use the work around method of sending Up's and Down's.

[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]
Link to comment
Share on other sites

I can't see from what you've posted why you should get stack overflow, but whenever I have had stack overflow it's been because I was recursively calling a function unintentionally. Say if you have a function to handle a change to a some component X, and in that function you change something in X.

Maybe there some loop which your program goes through that you didn't plan. Try adding some debugging lines to see how often the function is called and wherer it gets to. (I realize that you have probably already done that but just in case.)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

After some further testing, it appears the only the two ControlSend lines are causing the problem. If I comment them out and run the script, no Stack Overflow. If they are commented in, Stack Overflow. Maybe there's something wrong with ControlSend manipulating the combo boxes? I've never had a problem before, so I don't know why it'd be a problem.

Thanks for the continued help!

-Fett

[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]
Link to comment
Share on other sites

So you say that the program that your script "manipulates" gets the Stack-overflow...right?

Correct. There's a possibility it could be the native software is the problem. I was just really hoping the solution was in AutoIt as the engineers won't have time to find this problem in the native software for a while, but we are needing the regression script ASAP.

-Fett

[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]
Link to comment
Share on other sites

So you say that the program that your script "manipulates" gets the Stack-overflow...right?

I didn't realize that. Now I have nothing helpful to say.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I coded a delay option into the function:

Func _ComboBoxSelect($Window_Name, $ControlID, $MaxOptions = 10, $Selection = 1, $SendDelay = 5)
    Dim $Test_Results[4]                                                                        ;Initialize the results array
    $DefSendDelay = Opt("SendKeyDelay")                                                         ;Retrieve the current Send Key Delay value to use at the end of the function
    $Test_Results[0] = "Combo Select"                                                           ;Write the type "Combo Select" to the results array
    $Test_Results[1] = $ControlID                                                               ;Write the control ID to the results array
    $Test_Results[2] = $Selection                                                               ;Write the given selection to the results array
    $Test_Results[3] = "Window doesn't exist."                                                  ;Set the failed value. This will be overwritten if the function passes.
    If WinExists($Window_Name) = 0 Then Return $Test_Results                                    ;If the window doesn't exist, return the results array containing the error
    $Test_Results[3] = "The combo box selection failed."                                        ;Write the new error. This will be overwritten if the function passes.
    Opt("SendKeyDelay",$SendDelay)                                                              ;Set the Send Key Delay value to the given number
    For $i = 1 To $MaxOptions                                                                   ;Start a For loop. It will send the proper amount of {UP}s to the combo box to reset it
        If ControlSend($Window_Name,"",$ControlID,"{UP}") = 0 Then                              ;Send {UP} to the combo box to reset the list and if it fails, then
            Opt("SendKeyDelay",$DefSendDelay)                                                   ;Reset the Send Key Delay value
            Return $Test_Results                                                                ;Return the Test Results
        EndIf
    Next                                                                                        ;Perform the next iteration of the For loop
    For $i = 1 To $Selection - 1                                                                ;Start a For loop. It will send the proper amount of {DOWN}s specified by the user
        If ControlSend($Window_Name,"",$ControlID,"{DOWN}") = 0 Then                            ;Send {DOWN} to the combo box and if it fails, then
            Opt("SendKeyDelay",$DefSendDelay)                                                   ;Reset the Send Key Delay value
            Return $Test_Results                                                                ;Return the Test Results
        EndIf
    Next                                                                                        ;Perform the next iteration of the For loop
    $Test_Results[3] = 1                                                                        ;Write 1 to the results array
    Opt("SendKeyDelay",$DefSendDelay)                                                           ;Reset the Send Key Delay value
    Return $Test_Results                                                                        ;Return the passed results array
EndFunc   ;==>_ComboBoxSelect

And for this function, I tested moving the combo box selections at one selection per second, much slower than I can do it manually. Despite the slowness, the program still Stack Overflows and dies. I think I'm going to be forced to accept that this is a problem in the native software. (Not AutoIt's fault) Thanks for the suggestions guys. I guess I should add that the Stack Overflow doesn't occur until I hit the "Ok" button in the software, at which point it trips the error and dies.

-Fett

Edited by fett8802
[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...