segfault bisected

Since it would be criminal for me to be highly productive and successful for any more than a day or two at a time I (or my code maybe) decided today was as good a day as any for a segfault. To make matters worse for some reason “make && sudo make install” wasn’t good enough and the error didn’t crop up until after I had made about 5 different git commits. More on the segfault and how I found it after the jump.

As I was saying. For one reason or another the segfault didn’t turn up until I did a complete “./autogen.sh … sudo make install” and as such I made quite a large number of little changes throughout most of my code by the time I found the segfault. With the aid of gdb, Ddd and my log output I pinned the bug somewhere around program start, and I figured the problem arose from my addition of a random number generator as copied from Minisec. I “git checkout”ed my second most recent commit, where I hadn’t added the RNG code, and discovered the segfault was still there. Being a little fed up I decided to try “git bisect”, which I have used once before. I rolled back to yesterday, when I knew the program compiled, and to my surpise the segfault arose with the first commit of the day. It turns out that while stumped over getting the ruleset from the game with Game::getGame()->getRuleset(); I added a call to setRuleset(this); into my Risk.cpp constructor. I ended up figuring out I could simply dynamic_cast the returned Ruleset from getRuleset to Risk* instead of fussing over setting the ruleset, but neglected to remove the call, which at the time appeared to do nothing at all. Having fixed my flub I was back to non-segfaulting bliss.

As you might have guessed I did work out my “getRuleset” problem with a dynamic_cast. From what I can tell my Planet::doOnceATurn() should now properly update the maximum number of reinforcements for a planet and display it to the user as a quantity minable. I hope I can speak with llnz about getting the server to let me set “minable” to some other more applicable word, maybe something like “recruitable?”

As for other housekeeping; I pulled out ALL of my static map declarations into a temporary file residing on the git server. In their stead I have added a simple map of 2 constellations with 2 planets/systems each. As I spoke about yesterday it was just too big of a hassle trying to change/test code with 42 objects and somewhere near 100 edges. Now I only have to worry about 4 planets with 4 edges, much easier.

I also incorporated about 5 configuration options into a sample.config as well as assigning some defaults in the code. I’ve given the option to adjust the following:

  • max_players
    - Didn’t so much add this one as I just put it in the sample config file
  • risk_rfc_rate - This option determines the number of territories required to award a block of reinforcements. I.e a rate of 3 means you need 3 planets to get a reinforcement.
  • risk_rfc_number - The number of reinforcements you get when you fill a block as specified in risk_rfc_rate.
  • risk_rfc_start - The total number of reinforcements a player starts with
  • risk_randomly_assign_territories (true/false) - This option switches on random assignment of territories on join. The number of territories a player receives is 1/max_players. (I’m trying to get the random assignment working properly as we speak!)
  • risk_default_planet_armies - If planets are being randomly assigned then this option specifies how many reinforcements those planets will have.

As it stands right now I expect I will be spending tomorrow going over some other ruleset code and my own to get random assignment of planets down. I attempted to do so using only what I have learned so far, with no other code for reference. I think I’m close, and I’m going to declare it a good try. I also “tried” to implement a getWinner function in RiskTurn. That function may also be another close but no cigar funciton, only difference is getting a winner isn’t holding me back from programming moves, while owning territories is :P