Chaingun makes two sounds firing single bullet

The chaingun in the Doom games, like its predecessor in Wolfenstein 3D, normally fires an even number of bullets each time the firing key or button is pressed. When only one bullet remains in the player's supply, that bullet is deducted and a single shot is fired, as expected &mdash; but as the engine does not check whether the ammunition has run out when producing the necessary pair of firing noises (which are DSPISTOL), the sound is still played twice as if two shots had been fired.

Some source ports have fixed this bug. However, some DM players pointed out that this changes the gameplay, because you can tell if your opponent has run out of ammo if their chaingun emits an odd number of shot sounds.

The cause of the bug can be found in. The function starts the chaingun sound and immediately after, checks if the player has no ammo. It can simply be fixed by moving the line under the, so the sound is started only after this check.

void A_FireCGun ( player_t* player, pspdef_t* psp ) {       S_StartSound (player->mo, sfx_pistol); if (!player->ammo[weaponinfo[player->readyweapon].ammo]) return; P_SetMobjState (player->mo, S_PLAY_ATK2); player->ammo[weaponinfo[player->readyweapon].ammo]--; P_SetPsprite (player,                     ps_flash,                      weaponinfo[player->readyweapon].flashstate                      + psp->state                      - &states[S_CHAIN1] ); P_BulletSlope (player->mo); P_GunShot (player->mo, !player->refire); }

Demo files

 * [[Media:d229chgn.lmp|The chaingun sound bug]] (file info) on Level 29: The Living End in Doom II