Understand then fix.

So in programming there is kind of a rule something to the effect don't fix it if you don't understand the problem.

The idea being if you don't clearly understand the problem you may only make it worse. Breaking this rule can of course end up not fixing the problem, making the problem worse, or create new problems.

Well the bad news is tonight I broke that rule sorta. I was working on 0.3.0 like a good little programmer and noticed a huge regression. You couldn't see other players on the server. As a matter of fact the server was sending id 0 for all players.

This has worked fine since 0.1.0 so I was of course doing diffs like mad trying to figure out what I had changed that broke it. And naturally I didn't find it. If this was easy I wouldn't learn as much right lol.

So I did my normal thing and threw some cout calls in a few places. I know they have these things called debuggers but hey it's how I role. Plus I don't think the debugger in code blocks works very well.

So anyway I traced it back to one of my enter map functions. The one where it inserts it into the characters collection on a given map. The problem was that it was fine in that function but all functions after it seemed to not get any of the character's properties. So I threw a little cout in that spit out the values from the collection right after insertion.

Sure enough I got nothing but default values. I was calling insert so it shouldn't have been an issue. However I changed the call to access the nonexistent element via the character id and then assign the character.

Now for those of you not familiar with the map class from the standard template library when you use [] to access an element that is not there it creates it. So I used that in this case to get my element created.

The funny thing is that fixed the problem. Why I can't do an insert but using [] and assigning it works I don't know. As for the original problem my best guess is that it was copying the reference into the map and when the function that created the character went out of scope the character was cleaned up.

So if that is the case maybe the assignment forces the copy operator or something. Oh well it works now and I almost understand it. Silly C++ with your endless quarks.

But anyway I'm back on track for 0.3.0. This release will take a while. Not only am I adding a major new piece of functionality but I'm planning on putting out binary releases for multiple platforms. This means running test on all of the target platforms before I do my branch.

That said I have made pretty good progress I have most of the voice chat functionality implemented. Of course I'm working out some bugs (and by bugs I mean it doesn't work at all but doesn't throw any exceptions) but the basics are there.

Alright that is all for now I'm thinking about some cheesy pork rinds mmm salt covered fat with salty fat on top of it nomnomnom.


Popular posts from this blog

VK9 - Milestone8 Completed

VK9 - Milestone13 Completed

VK9 - Milestone16 Completed