Fix some (mostly Savegame-related) Crashes

Somehow I must have added that
savefile->WriteFloat( spreadCrouchFactor );
twice when merging the Ruiner/Rivensin changes into the SDK.. damn.
(As it's only read once, all data read from the savegame after it
 will be garbage)

I had a crash when creating a Savegame in idAnimState::Save(),
because animator was NULL - so I added a check for that.

The rest has been found with GCC address sanitizer (ASan)
This commit is contained in:
Daniel Gibson 2018-11-18 06:07:22 +01:00
parent cf83d7a579
commit 53ab8e1031
4 changed files with 12 additions and 6 deletions

View file

@ -81,7 +81,10 @@ void idAnimState::Save( idSaveGame *savefile ) const {
savefile->WriteObject( self ); savefile->WriteObject( self );
// Save the entity owner of the animator // Save the entity owner of the animator
savefile->WriteObject( animator->GetEntity() ); if(animator != NULL) // DG: don't crash if it's NULL
savefile->WriteObject( animator->GetEntity() );
else
savefile->WriteInt(0);
savefile->WriteObject( thread ); savefile->WriteObject( thread );

View file

@ -4934,11 +4934,15 @@ bool idPlayer::DropWeapon( bool died, bool selectNext ) { //ivan - bool selectNe
} }
// set the appropriate ammo in the dropped object // set the appropriate ammo in the dropped object
const idKeyValue * keyval = item->spawnArgs.MatchPrefix( "inv_ammo_" ); const idKeyValue * keyval = item->spawnArgs.MatchPrefix( "inv_ammo_" );
idStr inclipOrigKey;
if ( keyval ) { if ( keyval ) {
//item->spawnArgs.SetInt( keyval->GetKey(), ammoavailable ); //ivan - commented out //item->spawnArgs.SetInt( keyval->GetKey(), ammoavailable ); //ivan - commented out
idStr inclipKey = keyval->GetKey(); idStr inclipKey = keyval->GetKey();
inclipOrigKey = inclipKey;
inclipKey.Insert( "inclip_", 4 ); inclipKey.Insert( "inclip_", 4 );
inclipKey.Insert( va("%.2d", currentWeapon), 11);//new inclipKey.Insert( va("%.2d", currentWeapon), 11);//new
// DG: the following line seems to cause keyval to be deleted (via idList<idKeyValue>::Resize())
// that's why I copied the old key to inclipOrigKey and use that below in ivans code
item->spawnArgs.SetInt( inclipKey, inclip ); item->spawnArgs.SetInt( inclipKey, inclip );
} }
@ -4946,13 +4950,13 @@ bool idPlayer::DropWeapon( bool died, bool selectNext ) { //ivan - bool selectNe
//was: if ( !died ) { //was: if ( !died ) {
if ( died ) { if ( died ) {
//don't call WeaponStolen on weapon in this case bacause OwnerDied will be called instead (so it will be in scripts too). //don't call WeaponStolen on weapon in this case bacause OwnerDied will be called instead (so it will be in scripts too).
if ( keyval ) item->spawnArgs.SetInt( keyval->GetKey(), ammoavailable ); if ( !inclipOrigKey.IsEmpty() ) item->spawnArgs.SetInt( inclipOrigKey, ammoavailable );
}else{ }else{
//ivan end //ivan end
// remove from our local inventory completely // remove from our local inventory completely
inventory.Drop( spawnArgs, item->spawnArgs.GetString( "inv_weapon" ), -1 , &dropAmmoInItem ); //ivan - dropAmmoInItem added inventory.Drop( spawnArgs, item->spawnArgs.GetString( "inv_weapon" ), -1 , &dropAmmoInItem ); //ivan - dropAmmoInItem added
if ( keyval ) item->spawnArgs.SetInt( keyval->GetKey(), dropAmmoInItem ? ammoavailable : 0 ); //ivan if ( !inclipOrigKey.IsEmpty() ) item->spawnArgs.SetInt( inclipOrigKey, dropAmmoInItem ? ammoavailable : 0 ); //ivan
weapon.GetEntity()->ResetAmmoClip(); weapon.GetEntity()->ResetAmmoClip();

View file

@ -476,8 +476,7 @@ void idWeapon::Save( idSaveGame *savefile ) const {
savefile->WriteFloat( dynamicSpreadValue ); savefile->WriteFloat( dynamicSpreadValue );
savefile->WriteFloat( spreadBaseValue ); savefile->WriteFloat( spreadBaseValue );
savefile->WriteFloat( spreadVelocityFactor ); savefile->WriteFloat( spreadVelocityFactor );
savefile->WriteFloat( spreadCrouchFactor ); savefile->WriteFloat( spreadCrouchFactor );
savefile->WriteFloat( spreadCrouchFactor );
//ivan end //ivan end

View file

@ -84,7 +84,7 @@ void idWinding2D::ExpandForAxialBox( const idVec2 bounds[2] ) {
continue; continue;
} }
plane = Plane2DFromPoints( p[i], p[j], true ); plane = Plane2DFromPoints( p[i], p[j], true );
if ( i ) { if ( numPlanes ) { // DG: was if(i), but if we continued above at i=0, numPlanes is still 0 and numPlanes-1 is invalid...
if ( GetAxialBevel( planes[numPlanes-1], plane, p[i], bevel ) ) { if ( GetAxialBevel( planes[numPlanes-1], plane, p[i], bevel ) ) {
planes[numPlanes++] = bevel; planes[numPlanes++] = bevel;
} }