ents.Create sometimes crashes with server Engine Error !Get

This code called from a timer (if that’s important) causes server crashes every so often:



for k, page in pairs(pages) do
	if k > spawnablepages() then break end
	local ent = ents.Create("evil_page")  // crashes here
	ent:SetPos(page.pos)
	ent:SetAngles(page.ang)
	if MapInfo.pagemodel then
		ent:SetModel(MapInfo.pagemodel)
	end
	ent:Spawn()
end


The mdmp says:



0. Create - [C]:-1
      1. begin - gamemodes/evil/gamemode/sv_gamesys.lua:220 <-- line ents.Create is on
        2. (null) - gamemodes/evil/gamemode/sv_gamesys.lua:511 <-- function that calls begin


And if it is necessary, the evil_page code:



AddCSLuaFile()

DEFINE_BASECLASS("base_anim")

ENT.PrintName = "Slender Page"
ENT.Author = "Jonascone"

function ENT:Initialize()
	if CLIENT then 
		self:SetMaterial("")
		return
	end
	if MapInfo.pagemodel then
		self:SetModel(Model(MapInfo.pagemodel))
	else
		self:SetModel(Model("models/slender/sheet.mdl"))
	end
	self:PhysicsInit(SOLID_VPHYSICS)
	self:SetMoveType(MOVETYPE_VPHYSICS)
	self:SetSolid(SOLID_VPHYSICS)
	local phys = self:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:Wake()
		phys:EnableMotion(false)
	end	
end

function ENT:Draw()
	self:DrawModel()
	if CLIENT then
		if LocalPlayer():IsMonster() or LocalPlayer():IsProxy() or LocalPlayer():IsInfected() then
			self:SetNoDraw(true)
		else
			self:SetNoDraw(false)
		end
	end
end

function ENT:Use(ply, caller)
	if CLIENT then return end
	if self.taken then return end
	if ply:GetEyeTraceNoCursor().Entity != self then return end
	if ply:IsMonster() or ply:IsProxy() or ply:IsInfected() then return end
	ply:EmitSound(Sound(string.format("player/footsteps/gravel%s.wav", math.random(1, 4))), 100.0, math.random(120, 160))
	self.taken = true
	Game.Gametypes.Pages.pagetaken(ply)
	self:Remove()
end

hook.Add("PreDrawHalos", "Page Halo", function()
	if LocalPlayer():IsMonster() or LocalPlayer():IsProxy() or LocalPlayer():IsInfected() then return end
	halo.Add(ents.FindByClass("evil_page"), Color(20, 128, 20), 1, 1, 1)
end)


I didn’t read the entire thing, so I could be wrong. But it could be because you’re creating entities way too fast.

try dis:



for k, page in pairs(pages) do
	if k > spawnablepages() then break end
	timer.Simple(.1 * k, function()
		local ent = ents.Create("evil_page")  // crashes here
		ent:SetPos(page.pos)
		ent:SetAngles(page.ang)
		if MapInfo.pagemodel then
		ent:SetModel(MapInfo.pagemodel)
		end
		ent:Spawn()
	end)
end


Nope

https://puu.sh/yfqJr/236862e92a.png

edit:
oddly enough it wasn’t the page that crashed this time:



  Server
    0. Create - [C]:-1
      1. SetupHands - lua/includes/extensions/player.lua:223
        2. (null) - gamemodes/base/gamemode/player.lua:268
          3. Spawn - [C]:-1
            4. SpawnAll - gamemodes/evil/gamemode/sv_gamesys.lua:421 <-- iterates over player.GetAll() and Spawn()s them
              5. (null) - gamemodes/evil/gamemode/sv_gamesys.lua:516


Create the entities in a

GM:InitPostEntity hook

None of the entities are ever created before InitPostEntity or during InitPostEntity. Always at least 30 seconds after.

Your server overrides http://wiki.garrysmod.com/page/scripted_ents/Get or http://wiki.garrysmod.com/page/weapons/Get or basically deletes one of them.

[editline]5th November 2017[/editline]

Or the weapons or scripted_ents libraries are getting deleted, such as you have weapons = whatever somewhere in your code and it is not localized.

I forgot to localize a variable called weapons. That was it thanks