stackoverflow exception

I have two subroutines, P1 and P2, which each calling the same dataset. But when I run the program I catch an exception at the Data.DataRow that says:

"StackOverflowException was handled
 An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll

-Trouble shooting tips -
Make sure you do not have an infinite loop or infinite recursion."

It is true that P1 and P2 are meant to be discretely recursive (one click for P1, then another for P2), as when one is finished it calls the other, and perform this action back and forth until the process ends. I'm stumped. Any suggestions how to resolve this issue?
whittlephilipAsked:
Who is Participating?
 
NetminderConnect With a Mentor Commented:
Closed, 250 points refunded.
Netminder
Site Admin
0
 
LacutahCommented:
Sounds like they are infinitly recursive - I would "step" through the code, and find out why they aren't getting to a logical end.  If you would, posting your code for p1 and p2 would help...
0
 
Bob LearnedCommented:
Usually caused by some code in an event handler that forces the event handler to be called again, so you will get into an infinite loop.

Bob
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
whittlephilipAuthor Commented:
I'm working on a tutorial game for a single player (It works beautifully for one person), but now I am trying to incorporate a second person play capability. Here's a snippet of the two routines. The differences between them are small indeed.

    Private Sub p1() <----- p2 is identical except it is p2 ***
        Dim ds As Data.DataSet = TestDataSet <----- p2 is identical ***
        Dim drow As Data.DataRow = ds.Tables("Test").Rows(rndIndex) <----- p2 is identical & this is where the exception occurs *********
        'hiding p 2 stuff
        Me.lblP2.Visible = False
        Me.PictureBox15.Visible = False
        Me.PictureBox18.Visible = False
        Me.PictureBox19.Visible = False
        Select Case iIndex
            Case 1
                If chkT1.Checked Then
                    If drow("TruthA1") Then
                        PictureBox1.BackgroundImage = PictureBox10.BackgroundImage <----- p2 is identical except it is PictureBox11 throughout ***
                        PictureBox15.Visible = False
                        PictureBox19.Visible = True
                    Else
                        PictureBox1.BackgroundImage = PictureBox20.BackgroundImage 'blank2
                        PictureBox15.Visible = False
                        PictureBox18.Visible = True
                    End If
                ElseIf chkT2.Checked Then
                    If drow("TruthA2") Then
                        PictureBox1.BackgroundImage = PictureBox10.BackgroundImage
                        PictureBox15.Visible = False
                        PictureBox19.Visible = True
                    Else
                        PictureBox1.BackgroundImage = PictureBox20.BackgroundImage
                        PictureBox15.Visible = False
                        PictureBox18.Visible = True
                    End If
                ElseIf chkT3.Checked Then
                    If drow("TruthA3") Then
                        PictureBox1.BackgroundImage = PictureBox10.BackgroundImage
                        PictureBox15.Visible = False
                        PictureBox19.Visible = True
                    Else
                        PictureBox1.BackgroundImage = PictureBox20.BackgroundImage
                        PictureBox15.Visible = False
                        PictureBox18.Visible = True
                    End If
                End If
                . . .
      End Select
      call p2() <---- Here I am calling the p2() routine, and from p2() I call the p1() routine. ***

I'm trying to alternate, as discrete events from a single mouse click, between p1 and p2. I simply lack the experience to make it happen.

Philip
0
 
Bob LearnedCommented:
So, in p2, do you have a call to p1?  If so, then you have your infinite loop.

Bob
0
 
whittlephilipAuthor Commented:
Hi Bob,

I didn't quite return to VB6 as I warned. I'm actually using VB Express 2005 beta.
The answer is yes, I have a call to p1 from p2, I realize there lies my problem. With the error message, also highlites both p1 and p2 routines, so I knew there lay the problem. But how to work around it? I tried making the data set/data set rows global but that didn't work for me. Do you have any suggestions?

Thanks
Philip
0
 
Bob LearnedCommented:
I don't quite know what you are trying to accomplish, because I can't see the flow.

My first guess is to use a module-level flag variable that indicates which method to use:

If isPlayerOne Then
  p1
  isPlayerOne = False
Else
  p2
  isPlayerOne = True
End If

And then remove the calls to p1 from p2, and p2 from p1.

Bob
0
 
whittlephilipAuthor Commented:
Hi Bob,

Thanks for the suggestion, but it didn't quite fit what I needed to accomplish. I'll try to explain better. For each picturebox I have two sets of instructions, one for each player that clicks that box. I needed some guidance on how to set logic such that if player 1 clicked the picturebox the program executed the instructions, then automatically switch to player 2's set of instructions.

I accomplished this by setting a logic statement with a boolean flag on the instructions, then elsewhere in my code, setting flag = Not flag. Now after player1 has a turn it automatically switches to player 2's instructions.

I developed a tic tac toe game called math tac toe. The database has over 240 questions with three multiple choice answer, of course only one of the choices is correct. Each of the nine squares on the gameboard are pictureboxes, blank, O, and X. After the player taps on any of the nine squares a random selection is made from the database set and displayed on screen. The player then makes a choice for the correct answer. After the choice is made and submitted, the program queries the database for the truth. If the player's choice is true, an O is placed in the picturebox, else an X is placed there. This program was initially setup for a player to play against themself, and their knowledge of math. Now I have gone a step further and added a second player capability, such that player 1 has a turn as "O" and if the choice is incorrect resets the picturebox to "blank", and automatically switches to player 2's turn "X".

I developed the single player version in VB 6. (http://www.skinnyfrogsoftware.com/MTTDesktop.htm), and now have coverted it to VB.Net Express 2005 with additional features. Its been a painful transition, but worth it. Thanks for your support.

Philip
0
 
whittlephilipAuthor Commented:
moderator -- please close out this. I found the solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.