|
Post by chriscrawford on Jan 3, 2016 9:34:04 GMT -8
I have just found the most terrifying kind of bug a programmer can encounter: a stack bug. Stacks are fragile data structures in which individual data are arranged in order. You push an item onto the stack, then another item, and so on, and the stack grows into a big pile. Later on, you remove items from the stack as needed.
Stacks are powerful data structures, but they have a fatal weakness: you must keep exact count of how many items you have added and how many items you have taken away. This is done with a single integer called a 'stack pointer'. Every time you add something, you increment the stack pointer. Every time you remove something, you decrement the stack pointer.
The trouble comes when you forget to increment or decrement. Then things get out of sequence and the program goes crazy. Normally you don't find out that things are screwed up until lots of other things have gone wrong. Tracking backwards through this mess is a difficult and time-consuming task. Sometimes the havoc wrought by a stack error destroys the trail of evidence leading back to the original cause.
Now, this engine has undergone years of testing, but I'm using a combination of actions that seems to trigger the problem. There's a lot of nested behavior, which is always dangerous. So now I'm stuck with a big, mean, nasty bug.
Woe is me.
|
|
|
Post by chriscrawford on Jan 4, 2016 16:53:03 GMT -8
It took me a day and a half (during which time I did work on other things) to find the problem. This is a classic programming mistake: it's right in front of your face, immediately obvious, and yet I couldn't see it. Can you see it? Even if you don't know the scripting language, you should be able to pick it up with just a little logic. Stumped? Here's the mistake: in the first three terms under AND4, the term is CausalEventHappened, but in the next two terms under the single AND, the term is MainClauseIs. In those two cases, the term should be CausalEventHappened(MainClauseIs(ReactingActor, IWantXXX, ThisSubject)). It should be obvious from the discrepancy between the first three instances and the last two instances. I have a very weak excuse for this mistake on my part. The Sappho scripting language we use is bullet-proof: it is impossible to make a syntax error in Sappho. Except in this one case. I stumbled onto a bug in the scripting language, but I assumed that the language was flawless, so my eyes could not see what was staring me in the face. Back to work on Siboot.
|
|