Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075922 Posts in 44152 Topics- by 36120 Members - Latest Member: Royalhandstudios

December 29, 2014, 03:46:10 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Bugfixes that have astounded you
Pages: [1]
Print
Author Topic: Bugfixes that have astounded you  (Read 1210 times)
ThemsAllTook
Moderator
Level 10
******


Alex Diener


View Profile WWW
« on: July 30, 2013, 10:47:30 AM »

Have you ever had a time where your program is doing something seemingly imposible, then been blown away by the explanation once you got to the bottom of it? Let's share our experiences with crazy bugfixes here!


Why Am I Shooting So Slowly?

Two years ago I was working on a game for PCs and possibly mobile devices. I was tracking down a bug where the character's rate of fire was lower than it was supposed to be, but only when shooting toward a wall up close, and even then only sometimes. Eventually I found that I had to have defeated all enemies in a room for the bug to trigger...weird, right?

Lots of printfs and much hair pulling later, I found the culprit. In the interest of being a good citizen for battery life, I'd implemented a system that put the game loop to sleep when nothing was happening, and kind of forgotten about it. When enemies were gone, there was no AI tick to keep the game loop running. A moving projectile would also do it, but if it hit a wall before the next shot cooldown, the only thing that was allowing the cooldown counter to advance was key repeat events, which would step the game loop once each.

My Word!


Why Is My Audio Code Crashing?

Another one just from the other day: I was building libogg and libvorbis for both 32-bit and 64-bit Linux. I got my compiler settings right, copied the includes and libraries over to the appropriate place, and tried out some audio I/O code. Fine for 64-bit, crashes for 32-bit, deep inside libvorbisfile. Hmm... Dig in a bit, and some memory corruption is happening in between a libvorbis function and some calls to libogg. Not good! Surely these libraries have been thoroughly tested, and I wasn't really doing anything unusual with them. My 32-bit build used to work before I made a 64-bit one.

I take a closer look at the struct that's getting corrupted, and print out its address and the address of other things on the stack near it. Hmm, there's a struct right next to it in memory that's getting written to, but there are no arrays in it to overflow... I print out their sizeof()s. Smaller than expected! The last two fields of one of them are ogg_int64_t, which has a sizeof of 4. That's not enough bytes! What's ogg_int64_t defined as? long? Shouldn't that be int64_t, or long long?

It turns out that the libogg headers are different between 32-bit and 64-bit builds on Linux. long is 64 bits wide on x86_64, but only 32 bits wide on i386. I happened to be copying the headers after having built the 64-bit version and used them for both, so libogg saw different type sizes than libvorbis did. When libvorbis passed a struct with 32-bit ogg_int64_ts to libogg, libogg expected it to be larger and wrote past the end of it. The 32-bit header defines ogg_int64_t as long long, so I'm just using that one for both now. Kind of a hack, but at least it fixes it.


Let's hear some others. I'm sure you guys have some good ones to tell!
Logged
Conker534
Guest
« Reply #1 on: July 30, 2013, 11:09:58 AM »

Haha I have a stupid one.

I was having kurtss playtest a build of mine, to check what FPS he was getting, he was getting 40 FPS spikes every few minutes, so I decided before I moved on, I would figure out why he (and others) were having such issues.

I spent hours cleaning up code and reorganizing the game, but nothing seemed to work until I got to my shop keeper, the way she works is she checks what time it is, and if her store is able to open she will spawn 3 seeds and then wait for the end of the day to close shop. Well anyways she ended up putting out 5000 seeds because I forgot to write if hour=7 & minute=0{instance_create(x,y,seed)}, i only had if hour=7, so for the entire hour 7 she would constantly spawn 30 seeds a second, until I had 5000. It was so stupid. haha
Logged
Dr. Cooldude
Level 10
*****



View Profile
« Reply #2 on: July 30, 2013, 12:00:12 PM »

I don't have access to the code right now, but I once had a bug in my tilemap code that made the entire world rotated towards the right. It took me 2 hours until I found out that I somehow mixed the X/Y coordinates in the loop that was drawing all the tiles.

I felt stupid after that. But at the same time I was learning. Tongue
Logged
ChevyRay
Level 2
**



View Profile WWW Email
« Reply #3 on: July 30, 2013, 12:16:03 PM »

In Zombocalypse 2, I was getting a crazy bug where about 1k-2k kills in, you'd start getting hurt FOR NO REASON when no zombies were nearby.

This bug haunted me for weeks, I could not figure out where the ghost zombies were coming from! I tried hunting through the update loop for invisibility triggers, wondered if I hit some rendering cap that I didn't know about, but no dice.

Eventually in the shower (as usual) it hit me, AHA! I FUCKING KNOW!

Since the game just plays to the left/right, enemies consider "distance" between them and the player to only be on the x-axis. Then, when the player is near enough on the x-axis, they will attack him. This HAD to be the culprit! So either enemies were off the top of the screen and attacking me from above, or under the ground and attacking me from below.

It eventually turned out that the shotgun knockback would cause a bug that caused the enemies to zap below the ground, but even though they were falling endlessly into the void below, they'd still walk towards me on the x-axis and attack me, despite being thousands of miles away.

TL;DR - My game's zombies pulled one on me and learned to attack me from forever away off screen where I couldn't see them.
Logged

Unity Patterns - Tools & Resources for Unity Developers
FlashPunk - 2D Flash Game Engine
Cunnah
Level 0
***



View Profile WWW Email
« Reply #4 on: July 30, 2013, 03:02:04 PM »

I had an odd one, I was working on a procedural world gen program in Unity. I took it slow, first ensuring I could input height data to a terrain object. I then started implementing different Perlin noise functions to craft the terrain to my likening.

The next stage was to assign splat maps to the terrain. The first thing I thought to do was to assign a rock texture to slopes over a certain incline. Easy enough Unity's terrain system has a useful function for checking the steepness. It returns an value from 0 to 90. 0 equals flat 90 equals vertical. Splat maps are defined as a normalised number 0 to 1. A little bit of maths and I get a function that should assign the correct texture to the correct parts.

Run and compile and nothing is right. There are rock textures being drawn but they aren't on slopes and are quite random. First check is to make sure I hadn't flipped a co-ordinate around... nope. Ok so there must be some junk getting into the calculation somewhere as it is doing something.

Two days later and I still can't get anything to work then just by chance the perlin noise created a feature that looked a little like a smiley face (still no idea what the chances are) and low and behold there on the flip side was a rocky face goading me. So it must be flipped co-ordinates. I go back to the code and still nothing that looks like it is flipped, it was then I decided to deliberately flip the co-ordinates on the height gen... Yeah, for some reason everything in unity goes from left to right, bottom to top, with the sole exception being terrain height data which goes from bottom to top then left to right! WHAT THE HELL UNITY!?
Logged

Check out ADVENTURE! Dev blog, or my forum blog.
Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW Email
« Reply #5 on: July 30, 2013, 07:30:03 PM »

My favorites are the ones that are not my fault.

While developing Franchise, I had several mysterious crashes that I hunted down for months.  It turned out they were caused by a bug in the compiler.

Similarly, on the Windows build I kept getting bizarre flickering on some of my interface elements.  Much to my surprise, it was caused by a video driver bug.  I had another issue that I posted a thread about here somewhere, alt+Enter was causing my game to do very odd things.  Once again, video driver bug.
Logged

Franchise - The restaurant wars begin!

What would John Carmack do?
Klaim
Level 10
*****



View Profile WWW
« Reply #6 on: July 31, 2013, 02:59:41 AM »

While developing Franchise, I had several mysterious crashes that I hunted down for months.  It turned out they were caused by a bug in the compiler.

I found several bugs in compiler and standard library while developing my current game. One took several days to figure that indeed it was not my code the problem. Once I figured it was a compiler bug I asked by email to one of the responsible for the compiler and they confirmed I was not seeing something isolated, but they didn't know that bug was there! They fixed it without knowing in the following version.

One old bug that I still remember, years ago in a game code, was a crash that appeared only when I did some combination of key pressed. It was easy to reproduce but totally insane as using a break point showed that the crash occured somewhere in the audio part of the code but I couldn't figure why the hell the audio data was wrong. One particular clue was that adding or removing code, recompiling or changing comments would make the bug disappear or crash in another part of  the audio system. Totally insane!
Then it occurred to me that maybe there was some kind of buffer overwrite. I was right: after several days of replacing all raw arrays by more "protected" arrays (std::array if you use C++), re-inspecting each loop and each data buffer, I found that the problem was actually in the input system, the keyboard state buffer update loop was writing past the buffer size. Surprisingly, the audio system was always built in memory just after the the input system, which explains all the symptoms.
From this day I never used raw arrays again. (and never seen again this kind of problem)


Another one: I remember one day (even before) working on some 3D code using Ogre. The bug was that the physical screen would switch to black "no-input" if I turn the camera in a particular angle and get back to normal if I moved away from that angle.
That was particularly shocking because the screen was a CRT so if you remember how "violent" the switch-off and resolution change were, having that in the middle of a 3D game was particularly strange.
I quit after some time being totally astounded by this problem. Some friends come and we decide to play Unreal. Then the same bug occur in the same way!
It's then I figured that the problem was general, so I checked drivers but I was up to date (and I didn't have the bug after the update that was long ago).
As a last chance to figure out what is happening I decided to check the graphic card itself, maybe it was burnt.
I open the box and discover that the graphic card had only half or it's outlet plugged in the port....


(happend just after I moved my computer from another place)
Logged

http://www.klaimsden.net | Game : NetRush | Digital Story-Telling Technologies : Art Of Sequence
Evan Balster
Level 10
*****


I live in this head.


View Profile WWW Email
« Reply #7 on: July 31, 2013, 09:22:42 AM »

I've done a lot of programming, wrestled with memory corruption and graph traversals and all that, but somehow this stupid anecdote from nine years ago, when I was 14, stands out in my mind.

I was using Game Maker's new 3D functionality and the mere concept of making a 3D game was utter fantasy to me.  I was programming on the infinite plane, I liked to think.  The first of my "3D engines" was pretty awful, and the level editor featured one type of block for each of 16 elevations, complete with super-duplicated code.  Outside the "room", the floors fell away to a distant, cracked landscape rendered in novice pixel art.

The second one I wrote was a bit nicer and had its own (horrible) editor.  This one allowed axis-aligned blocks at arbitrary positions and sizes to be made.  After finishing in the editor, you could save your work and boot up the "game", which featured a spherical character exploring these platforms inside a great big sky-dome with a deadly ocean beneath.  To compensate for the difficulty of building, I added a button which spawned a small block underneath the character.  This was immediate fun as I could build great paths and stairways through the air.  I eventually discovered, bizarrely, that approaching the apex of the sky-dome caused distant objects to increasingly disappear until the world seemed to turn inside out.  This seemed totally surreal and I investigated at length before deciding it was an issue with Game Maker and contacting the developer.  It ended up being something like this:

Code:
d3d_set_projection(xf, yf, zf, xt, yt, zt, xu, yu, zu, fov, zn, zf);

I used "zf" twice and it made the Z-far clip plane equal the "Z-from" which represented camera elevation, which happened to be zero at the dome's peak.  So, I was astounded because I was inexperienced.  I'll try to remember a more genuinely epic bug for my next post, though.
Logged

Creativity births expression.  Curiosity births exploration.
Our work is as soil to these seeds; our art is what grows from them...


Wreath, SoundSelf, Infinite Blank, Cave Story+, <plaid/audio>
randomshade
Level 1
*


Fastzelda


View Profile WWW Email
« Reply #8 on: July 31, 2013, 10:11:59 AM »

Manifestation: Colliding with certain objects resulted in both objects being hurled into oblivion.

Bug: Coefficient of restitution was some stupidly awful high value. Relatively easy to find, but spent tons of time trying to track down how/why. All of the data looked correct.

Source: Was looking at the data in Google Docs where things seemed normal. However, one of the values for a few objects was getting exported to CSV as simply "." despite Google Docs showing it as "0".

Lesson: Always look at the "real" data.
Logged

Endurion
Level 2
**



View Profile WWW Email
« Reply #9 on: July 31, 2013, 10:50:53 AM »

Get Žem DX (C64): Pacman labyrinth like levels are created randomly from rectangles and vertical or horizontal lines. To make sure they were all connected the origin of the next primitive was laid to always clip the previous primitive. And it worked fine.

Just in about every 100th screen there was a gap that the player couldn't travel about. Due to the (not pseudo) random nature I couldn't store a start seed to reproduce it easily.

I traced the drawn primitives in memory, shuffled, rewrote and reshuffled the primitive code, but to no avail.

Until finally it occurred to me: During a test phase I had disabled the right wall of a rectangle, so only the upper, left and bottom border were drawn. And due to the line primitive types this didn't come apparent visually at all.

Logged
Impmaster
Level 10
*****


Scary, isn't it?


View Profile WWW Email
« Reply #10 on: August 01, 2013, 02:59:10 PM »

Due to the fact that I didn't know arrays started with zero, I tried to make the first layer of my game solid, with the other layers not solid. Instead, everything EXCEPT the place I wanted was solid. So, going through walls, and blocked by air it was.
Logged

Do I need a signature?
nikki
Level 10
*****


View Profile Email
« Reply #11 on: August 02, 2013, 05:12:35 AM »

console.log('test');
someFunction();

with the log call, there is no bug, take it out and a bug appears.

 
Logged
TaftsBathtub
Level 0
**


View Profile Email
« Reply #12 on: August 02, 2013, 02:53:56 PM »

I had one in C++ that boiled down to something like this:

Code:
class Tornado
{
   public:
      Tornado(midpoint): _midpoint(_midpoint){}
      float _midpoint;
}

This leads to undefined behavior in C++, so sometimes it would crash, sometimes I would add more debug statements and it would be fine.  I had pretty much every warning flag enabled with gdb, but it had no complaints.
Logged
Klaim
Level 10
*****



View Profile WWW
« Reply #13 on: August 02, 2013, 03:27:24 PM »

I had one in C++ that boiled down to something like this:

Code:
class Tornado
{
   public:
      Tornado(midpoint): _midpoint(_midpoint){}
      float _midpoint;
}


This leads to undefined behavior in C++, so sometimes it would crash, sometimes I would add more debug statements and it would be fine.  I had pretty much every warning flag enabled with gdb, but it had no complaints.

Got the same few months ago. As I was using a static analysis  tool and neither the compiler nor the static analysis tool catch this one, I sent a mail to the static analysis tool company who upgraded the tool and now it catch it. It's nasty: I found another one earlier this week using the static analysis tool.
Logged

http://www.klaimsden.net | Game : NetRush | Digital Story-Telling Technologies : Art Of Sequence
ralphchapin
Level 0
*


View Profile WWW
« Reply #14 on: August 02, 2013, 04:40:46 PM »

I'd been curious about multi-threading for years.  Finally had some time and decided to jump in with both feet and wrote a game that would keep 100+ threads going at once.  It was a strange new world.  These are my big three:

1.) 
Code:
   int i = k;
    int j = i * i;

"j" got a value of 35 Shocked  My all time MT favorite.  Fortunately I had checks in the code, looking for another bug, or I never would have seen it.  Something changed "i" between the two references.

2.)  Got this one all the time:
Code:
   if (player != null)
        player.Reset();

gives a null pointer exception!  Something nulled "player" between the two references.  A 1 in a billion chance, but in testing I must have been giving it a billion chances every five minutes or so.

3.)  The last problem was more subtle.  Items being dragged across the screen would freeze for short periods, or for long periods, or just stop moving.  Also, lines marking planned moves would remain in place long after the moves were canceled, disappearing minutes later if at all.

I read somewhere that even when I didn't care about synchronization I needed memory barriers or one thread might never see changes made by another.  I cleaned up my code just to be PC (carefully eyeballing each of thousands of lines of code), and, to my surprise, from then on the dragged objects move smoothly and the movement lines disappeared promptly (almost always).
« Last Edit: August 02, 2013, 04:51:55 PM by ralphchapin » Logged
doihaveto
Level 1
*



View Profile
« Reply #15 on: August 06, 2013, 05:18:39 AM »

6 years ago I was working on a system that wrote some data to a bunch of files on Amazon S3 (which was pretty brand new at the time), then later a batch processor ran and processed them. The problem was that we'd occasionally get errors about missing files on S3, even though when I checked them manually, they were always there.

After some digging, it turned out that we were reading them just after they got written and closed, so they didn't get a chance to "propagate" yet. The server that was getting the read request didn't yet know that such a file existed in the cloud, but a few seconds later (when I checked manually) it already got updated.

And that's how I eventually learned about eventual consistency in distributed databases. Smiley
Logged

DantronLesotho
Level 1
*



View Profile
« Reply #16 on: August 06, 2013, 05:59:01 AM »

I was working on an earlier version of my terraria-like and put an algorithm for water behavior, coded some other landscape things, made up a weapon, and started testing. Without warning my character would be walking along and sometimes a tidal wave would rush into the screen, shoot my character up through the ceiling, and cause an outofbounds exception. I had no idea what was causing it because the issue didn't appear when I had worked on the water code itself. It turned out that after working on one other part of the landscape, I forgot that I changed the water behavior to reproduce and stack on itself, but I left out the part where the lower tile would absorb some of the volume, so it would just stack on itself indefinitely until it errored out. I was so relieved to find that one; the tidal wave scared the daylights out of me when it first happened.
Logged

"Somewhere, something incredible is waiting to be known." -Carl Sagan
ThemsAllTook
Moderator
Level 10
******


Alex Diener


View Profile WWW
« Reply #17 on: August 06, 2013, 09:13:10 AM »

Without warning my character would be walking along and sometimes a tidal wave would rush into the screen, shoot my character up through the ceiling, and cause an outofbounds exception.

That's FANTASTIC. Grin
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic