• Too many Emitters?
    6 replies, posted
I am having a huge problem with emitters because after a while the console spams this error: [lua] [ERROR] addons/military snpcs/lua/entities/npc_vj_mili_soviettank_base/shared.lua:23: attempt to index field 'Emitter' (a nil value) 1. func - addons/military snpcs/lua/entities/npc_vj_mili_soviettank_base/shared.lua:23 2. unknown - lua/includes/modules/net.lua:31 ParticleEmitter: Couldn't make emitter! Too many emitters! [/lua] Also it seems like Finish() does nothing... Here is the code: [lua] local ent = net.ReadEntity() if ent:IsValid() then ent.Emitter = ParticleEmitter(ent:GetPos()) ent.SmokeEffect1 = ent.Emitter:Add("particles/smokey",ent:GetPos() +ent:GetForward()*95 +ent:GetRight()*72 +ent:GetUp()*55) ent.SmokeEffect1:SetVelocity( ent:GetForward() * math.Rand(0, 50) + Vector(math.Rand(5, -5),math.Rand(5, -5),math.Rand(5, -5)) + ent:GetVelocity() ) ent.SmokeEffect1:SetDieTime(0.6) ent.SmokeEffect1:SetStartAlpha(100) ent.SmokeEffect1:SetEndAlpha(0) ent.SmokeEffect1:SetStartSize(3) ent.SmokeEffect1:SetEndSize(5) ent.SmokeEffect1:SetRoll(math.Rand(-0.2,0.2)) ent.SmokeEffect1:SetColor(150,150,150,255) ent.SmokeEffect1:SetAirResistance(100) ent.HeatEffect1 = ent.Emitter:Add("sprites/heatwave",ent:GetPos() +ent:GetForward()*95 +ent:GetRight()*72 +ent:GetUp()*55) ent.HeatEffect1:SetVelocity( ent:GetForward() * math.Rand(0, 50) + Vector(math.Rand(5, -5),math.Rand(5, -5),math.Rand(5, -5)) + ent:GetVelocity() ) ent.HeatEffect1:SetDieTime(0.1) ent.HeatEffect1:SetStartAlpha(255) ent.HeatEffect1:SetEndAlpha(255) ent.HeatEffect1:SetStartSize(6) ent.HeatEffect1:SetEndSize(3) ent.HeatEffect1:SetRoll(math.Rand(-50,50)) ent.HeatEffect1:SetColor(255,255,255) //ent.HeatEffect1:Finish() end ent.Emitter:Finish() [/lua] If you could help me that would be great!
Finish does properly clear it now; the issue is if you have an emitter / particle with a collision callback, you need to re-define the emitter if you called finish. Use if ( IsValid( ent ) ) then ... tab/indent the code from that if, detent it when it reaches the end. Also, which line is the error on HearEffect1 or SmokeEffect1? The issue could be with ReadEntity although you do have the IsValid check so that old old bug may have been fixed; for giggles: try writing a number Entity:EntIndex( ) and then when you read it on the other end use local ent = Entity( net.ReadLong( ) ); // long or whatever...
Sorry English not my langouge so I dont really get what you say. Also the error happens on HeatEffect1 and SmokeEffect1. [QUOTE=Acecool;44406901]Finish does properly clear it now; the issue is if you have an emitter / particle with a collision callback, you need to re-define the emitter if you called finish. Use if ( IsValid( ent ) ) then ... tab/indent the code from that if, detent it when it reaches the end. Also, which line is the error on HearEffect1 or SmokeEffect1? The issue could be with ReadEntity although you do have the IsValid check so that old old bug may have been fixed; for giggles: try writing a number Entity:EntIndex( ) and then when you read it on the other end use local ent = Entity( net.ReadLong( ) ); // long or whatever...[/QUOTE]
You really don't need more than 2 emitters to service your entire map / game-mode. Creating one emitter per player is 128 ( up to 256 if you use both 2d and 3d variants ), plus wherever else they are. There is a limit on how many emitters you can spawn ( I'm not sure of the exact number but you can overflow the linked-list data-structure after around 65,000 of them which happens if you don't call :Finish( ) on them if you keep creating new ones, or you don't properly manage them )
I don't think the isuee is this complex, Acecool. ent.Emitter:Finish() is outside the if, so if the entity was not value then ent.Emitter doesn't exist. You can't call ent.Emitter:Finish() when the emitter isn't there. Just move ent.Emitter:Finish() in the if statement.
[QUOTE=Chessnut;44407212]I don't think the isuee is this complex, Acecool. ent.Emitter:Finish() is outside the if, so if the entity was not value then ent.Emitter doesn't exist. You can't call ent.Emitter:Finish() when the emitter isn't there. Just move ent.Emitter:Finish() in the if statement.[/QUOTE] I totally missed that; I think I saw the first finish not noticing it was commented out; !tabbing for the win!
Alright I will try what you say soon and see if works! Also thanks! EDIT: After all I was right, it's not fixed for the current version of Garry's Mod, guess have to wait until next update. Also thanks to everyone who tried to help! [url]https://github.com/Facepunch/garrysmod-issues/issues/941[/url] [QUOTE=Chessnut;44407212]I don't think the isuee is this complex, Acecool. ent.Emitter:Finish() is outside the if, so if the entity was not value then ent.Emitter doesn't exist. You can't call ent.Emitter:Finish() when the emitter isn't there. Just move ent.Emitter:Finish() in the if statement.[/QUOTE]
Sorry, you need to Log In to post a reply to this thread.