[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

stackoverflow exception

Posted on 2005-04-27
10
Medium Priority
?
682 Views
Last Modified: 2008-02-20
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?
0
Comment
Question by:whittlephilip
9 Comments
 
LVL 9

Expert Comment

by:Lacutah
ID: 13877993
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13878172
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
 

Author Comment

by:whittlephilip
ID: 13878800
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 96

Expert Comment

by:Bob Learned
ID: 13878822
So, in p2, do you have a call to p1?  If so, then you have your infinite loop.

Bob
0
 

Author Comment

by:whittlephilip
ID: 13879128
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13879350
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
 

Author Comment

by:whittlephilip
ID: 13893414
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
 

Author Comment

by:whittlephilip
ID: 13898880
moderator -- please close out this. I found the solution.
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 13956725
Closed, 250 points refunded.
Netminder
Site Admin
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question