Jump to content

C stack overflow


Recommended Posts

Posted

What does C stack overflow mean?
I get this error when running this code:

addEventHandler ("onVehicleExit", getRootElement (),
	function (thePlayer)
		if (getElementModel(source) == 596 or 523) then
			local passenger = getVehicleOccupant (source, 1)
			if passenger then
				removePedFromVehicle(passenger)
			end
		end
	end
)

 

Posted (edited)

I think the problem is the way you are trying to get the matching model id.

In my opinion this would be a much simpler solution for this problem:

local vehicleModelIDs = {
  	[596] = true,
  	[523] = true,
  }

addEventHandler ("onVehicleExit", getRootElement (),
	function (thePlayer)
		if vehicleModelIDs[getElementModel(source)] then
			local passenger = getVehicleOccupant (source, 1)
			if passenger then
				removePedFromVehicle(passenger)
			end
		end
	end
)

This way adding and removing vehicle ids in the future will be easier. Let me know if it works or not.

Edited by Dzsozi (h03)

Your signature image is too large.

Removed

  • Moderators
Posted

 

if passenger and passenger ~= thePlayer then

Stack overflows are mostly happening when you created an infinity loop of function calls. A player leaves the vehicle triggering the event, which will remove a player, which will trigger the event, which will remove a player, which will trigger the event, which will remove a player, which will trigger the event, which will remove a player... ?

Note: The player is still inside of the vehicle when the event is triggered.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...