Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27203

VS 2012 Stack Overflow in a game that plays itself

$
0
0
So I've been developing an american football game. In the game, the offense chooses a type of play, the defense chooses a play, then the code takes over. My problem is that when the computer is calling the plays for both the offense and the defense, after 5-6 "plays" I get a stack overflow. The problem started when I first put in the code for the compute to call defense against a computer offense.

The code is comprised of many Public and Private Subs calling each other. When a human is controlling the offense or defense, he chooses plays by pushing buttons or pressing keys, but the computer's decisions come from various if-thens in subs that culminate with things like this:

Code:


        If cpuspiker = 1 Then
            vcpuotimespike()
        ElseIf cpucoacher = 1 Then
            vocoaching()
        ElseIf cpucoacher = 3 Then
            Run.Visible = True
            PASS.Visible = True
            SPECIAL.Visible = True
        Else
        End If

So after a play is run:

  • If a human controls the defense, they select it with a keypress, and that keypress then runs the above code to either go to another sub (if the computer coaches the offense) or make the RUN PASS and SPECIAL buttons pop up (if a human controls the offense)


  • If the computer controls the defense, they use a series of if-thens to determine the type of defense, then runs the above code to either go to another sub (if the computer coaches the offense) or make the RUN PASS and SPECIAL buttons pop up (if a human controls the offense)


If there's a human involved pressing buttons and keypresses, I can go a full overtime game with HUNDREDS of plays with no problem. If it's CPU vs CPU going from sub to sub, it generally runs well for 6 plays before a stack overflow.

How can I fix this? It's almost like I need to pause the code like when waiting for a keypress to give all the subs time to exit... The call stack generally looks like this when it dies:

Name:  callstack.png
Views: 43
Size:  70.8 KB

I'd share with you some more code, but I have thousands of lines of it. Man am I lost... :confused:

Thank you for your help. You guys are a tremendous resource.
Attached Images
 

Viewing all articles
Browse latest Browse all 27203

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>