Every time i call a function to exit all players from a vehicle, SRCDS stops to work !

Hello al,

Again i have a problem, but a big one this time ! SRCDS stops to work every time i call the function VC2:EjectPassengers(veh).

Here is the function’s code :



function VC2:EjectPassengers(veh)
	if (veh:GetDriver() != NULL) then veh:GetDriver():ExitVehicle() end
	
	print("test") //SRCDS reachs this line
	for k, v in pairs(veh.PassengerSeats) do
                //SRCDS stops to work here
		if (IsValid(v)) then
			if (v:GetDriver() != NULL) then
				v:GetDriver():ExitVehicle()
			end
		end
	end
end


The crash dumps (i tested 3 times to see if it’s realy linked to my function) : http://dlsrv.sldt-team.net/public_dl.php?file=srcds.zip

Exception code : 0xC0000005
Translated from my french Visual Studio, it’s an access violation.

In the console log in those crash dumps I don’t see the “test”, neither do I see a single player joining your server.

Don’t use != NULL, use IsValid( ent ).

do PrintTable(veh.PassengerSeats) and see if that works.

Yes i know, that’s because RealisticRoleplay handles all connects/disconnects, and visibly, the messages it prints aren’t visible in crash reports.

I’ll try what you said.

EDIT : Normaly veh.PassengerSeats is a table witch normaly contains pointers to entities (“prop_vehicle_prisoner_pod”)

[editline]17th February 2015[/editline]

Ok that’s ok i tried what you said, it didn’t work, the server still crashes, same circonstencies.

The new code :



function VC2:EjectPassengers(veh)
	if (IsValid(veh:GetDriver())) then veh:GetDriver():ExitVehicle() end
	
	print("test")
	PrintTable(veh.PassengerSeats)
	for k, v in pairs(veh.PassengerSeats) do
		if (IsValid(v)) then
			if (IsValid(v:GetDriver())) then
				v:GetDriver():ExitVehicle()
			end
		end
	end
end


Crash dump : http://dlsrv.sldt-team.net/public_dl.php?file=srcds.mdmp

Screenshot of the crash : http://dlsrv.sldt-team.net/public_dl.php?file=srcds.png
The screen shows the last lines of logs before the server crashs.

[editline]17th February 2015[/editline]

Nobody ?!

Nobody has any idea about the problem ?

I’ll try to do some more testing, but i think it’s the GetDriver() or ExitVehicle which is causing the crash.

I made some tests, visibly calling this function results in a crash after about 1~2 seconds.

Still nobody ?!

[editline]17th February 2015[/editline]

I’m still in waiting for an answer…

I’m still waiting for an answer, SRCDS still crashes !

Try running empty for loop:



function VC2:EjectPassengers(veh)
	if (IsValid(veh:GetDriver())) then veh:GetDriver():ExitVehicle() end
	
	print("test")
	for k, v in pairs(veh.PassengerSeats) do
	end
end

Try running



function VC2:EjectPassengers(veh)
	if (IsValid(veh:GetDriver())) then veh:GetDriver():ExitVehicle() end
	
	print("test")
	for k, v in pairs(veh.PassengerSeats) do
		if (IsValid(v)) then
		end
	end
end

Try running:



function VC2:EjectPassengers(veh)
	if (IsValid(veh:GetDriver())) then veh:GetDriver():ExitVehicle() end
	
	print("test")
	for k, v in pairs(veh.PassengerSeats) do
		if (IsValid(v) && IsValid(v:GetDriver())) then
		end
	end
end

WTF !? With nothing in the for loop it crashs !!!

[editline]18th February 2015[/editline]

Ok the


 if (IsValid(veh:GetDriver())) then veh:GetDriver():ExitVehicle() end 

is causing the crash.

You’re doing something wrong otherwise. That should not cause crashing.

Oh my bad, lemme just whip out my big book of answers for your issue.

Printout the veh:GetDriver() in that hook before calling ExitVehicle() and see what it gives you in the console.

Maybe check if it’s valid and player?

It’s strange either way. If the result isn’t a valid player, then the ExitVehicle() function should just be nil, and it would result in a simple lua error. But that doesn’t happen; instead, the server crashes completely. No matter how you twist it, Yuri is not 100% at fault here. If the .exe crashes from a simple command like that (with no infinite while loop or the like), the problem has to lie deeper.

/uselesspost

This outputs [Player][1][[YJB] Yuri]

I know what is going to happen here. This will go to the github of gmod as a pull request no?

Minimal code to reproduce on vanilla would be very helpful.

Is VC2:EjectPassengers called from within an PlayerExitVehicle hook?

Not exactly it’s called when the vehicle explodes so in damage hook. You know ? Add a physics collide callback, then call GM:EntityTakeDamage on the vehicle. Then if the health of the vehicle is less or equal to 0, destroy running lights, create an explosion on the engine, ignite it and at least call VC2:EjectPassengers, and say goodbye server…

[editline]19th February 2015[/editline]

It’s crashing too on singleplayer, but i have a different message : instead of hl2.exe has stopped working, the game closes and a message appears on my screen :
“Engine Error”
“ED_Alloc: no free edicts”

Why are you calling GM:EntityTakeDamage on the vehicle? Do you mean Entity:TakeDamage?

Why do you even try to boot the players of the vehicles? Removing the vehicle itself ( and seats ) will automatically boot them from the vehicle.

If i wanted to remove the vehicle then there would be no questions like that.

Removing a destroyed vehicle is good for half-rp gamemodes. But i want to make a SERIOUS RP gamemode.

I’m calling GM:EntityTakeDamage. If you want the damage code, here you go :



//This code is run at the end of the big vehicle initialization loop. This loop check every vehicle and add (if the vehicle needs one) a table containing all customization elements. This is the only loop my mod_vc2 have.
v:AddCallback("PhysicsCollide", function(veh, data)
						local dmginfo = DamageInfo()
						dmginfo:SetAttacker(data.HitEntity)
						local vel = data.OurOldVelocity:Length()
						if (vel > 1000) then
							vel = vel / CONVERSION_UNITS_TO_KPH
							vel = vel / 10
							dmginfo:SetDamage(vel)
							print(vel)
							hook.Run("EntityTakeDamage", v, dmginfo)
						end
					end)