Random srcds crashes (Tried to use a NULL entity!)

I see no reason for this crash. Out of nowhere, srcds.exe stops working. The last line before the crash?


gamemodes/base/gamemode/player.lua:198: Tried to use a NULL entity!

What? I only got this crash when spawning combines using this code, and it’s not the first combines that spawn, it’s like the 4th or so time they spawn:
[lua]function CopWaves()
local cop1 = ents.Create( “npc_combine_s” )
local cop2 = ents.Create( “npc_combine_s” )
local cop3 = ents.Create( “npc_combine_s” )
local cop4 = ents.Create( “npc_combine_s” )
if ( !IsValid( cop1 ) ) then return end
if ( !IsValid( cop2 ) ) then return end
if ( !IsValid( cop3 ) ) then return end
if ( !IsValid( cop4 ) ) then return end
cop1:SetKeyValue( “additionalequipment”, “weapon_ar2” )
cop2:SetKeyValue( “additionalequipment”, “weapon_smg1” )
cop3:SetKeyValue( “additionalequipment”, “weapon_shotgun” )
cop4:SetKeyValue( “additionalequipment”, “weapon_smg1” )
cop1:SetPos( Vector( 2011.597046, -1195.060425, -79.968750 ) );cop1:Spawn()
cop2:SetPos( Vector( -528.179138, -1839.761597, -79.968750 ) );cop2:Spawn()
cop3:SetPos( Vector( 676.210327, -2300.611084, -79.968750 ) );cop3:Spawn()
cop4:SetPos( Vector( 676.250327, -2350.811084, -79.968750 ) );cop4:Spawn()
end[/lua]

Help…?

Try to determine whether this happens when you set the key value, or set the position.

Neither. What happens is, they start spawning, and approx 30-40 seconds after that, not when one spawns, but seemingly out of nowhere at a random time, srcds crashes with that lua error.

can you start the server up with -developer and then cause the crash. That might give you a better error message to work from.

Some entities have issues and will cause a crash if they are not Activate’ed…

This isn’t much different than what you have except using a helper function, and activating them.


//
// Our cop spawning function... Could be normalized further to set angles, the entity type, etc...
//
function SpawnCop( _pos, _equipment )
	// Create the cop
	local _ent = ents.Create( "npc_combine_s" );

	// If it isn't valid, we may be at the entity limit, or the entity type doesn't exist
	if ( !IsValid( _ent ) ) then return; end

	// If they have equipment, lets add it..
	if ( _equipment ) then
		if ( isstring( _equipment ) then
			_ent:SetKeyValue( "additionalequipment", _equipment );
		elseif ( istable( _equipment ) ) then
			_ent:SetKeyValue( "additionalequipment", table.concat( _equipment, ", " ) );
		end
	end

	// Set model?
	-- _ent:SetModel( "" ); -- ??

	// Set the position and angle..
	_ent:SetPos( _pos || vector_origin );
	_ent:SetAngles( angle_zero );

	// Spawn and activate them...
	_ent:Spawn( );
	_ent:Activate( );

	// Return the entity in case we want to do something else outside of the function...
	return _ent;
end


//
// Spawn 4 cops...
//
function CopWaves( )
	SpawnCop( Vector( 2011.597046, -1195.060425, -79.968750 ), "weapon_ar2" );
	SpawnCop( Vector( -528.179138, -1839.761597, -79.968750 ), "weapon_smg1" );
	SpawnCop( Vector( 676.210327, -2300.611084, -79.968750 ), "weapon_shotgun" );
	SpawnCop( Vector( 676.250327, -2350.811084, -79.968750 ), "weapon_smg1" );
end

Edit: If they’re crashing AFTER they’re spawned, after some time as you say… is it when they are about to start shooting, or when they are about to do an action? That would be similar to prop_vehicle_airboat crash where if Activate isn’t called and a player tries starting it ( if spawned with engine off ) that it crashes the server… Activate may be the issue, but then again it may be something else.

I forgot to mention, there is another thing odd about that function with the cops… you see, I have an isHeisting variable. Now, on 99% of functions I use and if isHeisting, it ALWAYS works. However, if I make my CopWaves be like this:
[lua]
function CopWaves()
if isHeisting then
local cop1 = ents.Create( “npc_combine_s” )
local cop2 = ents.Create( “npc_combine_s” )
local cop3 = ents.Create( “npc_combine_s” )
local cop4 = ents.Create( “npc_combine_s” )
if ( !IsValid( cop1 ) ) then return end
if ( !IsValid( cop2 ) ) then return end
if ( !IsValid( cop3 ) ) then return end
if ( !IsValid( cop4 ) ) then return end
cop1:SetKeyValue( “additionalequipment”, “weapon_ar2” )
cop2:SetKeyValue( “additionalequipment”, “weapon_smg1” )
cop3:SetKeyValue( “additionalequipment”, “weapon_shotgun” )
cop4:SetKeyValue( “additionalequipment”, “weapon_smg1” )
cop1:SetPos( Vector( 2011.597046, -1195.060425, -79.968750 ) );cop1:Spawn()
cop2:SetPos( Vector( -528.179138, -1839.761597, -79.968750 ) );cop2:Spawn()
cop3:SetPos( Vector( 676.210327, -2300.611084, -79.968750 ) );cop3:Spawn()
cop4:SetPos( Vector( 676.250327, -2350.811084, -79.968750 ) );cop4:Spawn()
end
end[/lua]
The cops refuse to spawn what so ever, even when other things with isHeisting work fine. No errors.
I will post more info when it crashes with -developer.

Got some more info.

The last frame I saw when it crashed:

Fault module name is datacache.dll

So I’ve died many times in that. It seems that when I die sometimes it crashes. As you can see I had very little hp in the screenshot. Well, it appears as if a combine was about to kill me. Player death by certain combines = crash? I don’t think so because I died at LEAST 30 times before that by combine, and killed over 100 combines.

mdmp: http://www.filedropper.com/srcds2117156crash2014925t184736c0