ParticleEmitter BadCoder( CUtlLinkedList overflow! ( exhausted index range ) ) Fix!

Hey all, I released some code here and there for this fix. The old one didn’t support use3D which someone told me about and the new version supports it. I finally got around to testing the new version and found it was broken. IsValid doesn’t work on Emitters.

Anyway, here’s the code, it needs to be run CLIENTSIDE. It should fix the bug with improper management of ParticleEmitter which will cause your game to crash. This is seen as a native bug in some game-modes.

If you had an old version of this, remove IsValid, IsValid doens’t work for Emitters. Other than that, this is a drop-in solution to fix the linked list issue which is caused by bad coding.

[lua]//
// Safe ParticleEmitter Josh ‘Acecool’ Moser
//
// This should be placed in a CLIENT run directory - such as addons/acecool_particleemitter_override/lua/autorun/client/_particleemitter.lua
// – http://forum.facepunch.com/showthread.php?t=1309609&p=42275212#post42275212
//
if ( !PARTICLE_EMITTER ) then PARTICLE_EMITTER = ParticleEmitter; end
function ParticleEmitter( _pos, _use3D )
if ( !_GLOBAL_PARTICLE_EMITTER ) then
_GLOBAL_PARTICLE_EMITTER = { };
end

if ( _use3D ) then
	if ( !_GLOBAL_PARTICLE_EMITTER.use3D ) then
		_GLOBAL_PARTICLE_EMITTER.use3D = PARTICLE_EMITTER( _pos, true );
	else
		_GLOBAL_PARTICLE_EMITTER.use3D:SetPos( _pos );
	end

	return _GLOBAL_PARTICLE_EMITTER.use3D;
else
	if ( !_GLOBAL_PARTICLE_EMITTER.use2D ) then
		_GLOBAL_PARTICLE_EMITTER.use2D = PARTICLE_EMITTER( _pos, false );
	else
		_GLOBAL_PARTICLE_EMITTER.use2D:SetPos( _pos );
	end

	return _GLOBAL_PARTICLE_EMITTER.use2D;
end

end[/lua]

The bug is due to Garry’s Mod not removing the previous emitter. Calling Finish will not remove the particle emitter. The particle emitter appears to be left dangling in memory thus causing the overflow.

Thanks for this, recently ran into this issue with an addon I was coding.

I’ve been doing some looking into this… because it isn’t just caused by this, even though this is a cause. I found out whenever render.SuppressEngineLighting( boolean suppressLighting ) is ran it’s only a matter of time before everything goes invisible.

I’ve posted a bug report on the Garry’s Mod Git Hub page.

is there a way to work around this, like crafty use of think hooks say?

Umm that is the whole point of this thread, the code in the OP is the work around.

Just a heads up that acecool has filed 3 successful DMCA notices against my workshop addons and 2 other addons that contain this fix.

Can we seriously just ban this guy already?

Did you forget to put in: “// Safe ParticleEmitter Josh ‘Acecool’ Moser” and then write in huge bold letters “CREDIT TO THE ACECOOL COMPANY”.

What addons?

Zombie Survival, Extreme Football Throwdown, Awesome Strike: Source, Retro Teamplay and Hover Gear Legacy.
Retro Teamplay and Hover Gear Legacy, never even had this emitter fix.

Ptown2 posted here about Hover Gear Legacy being taken down.

Can you post direct links?

Updated post with direct links.

All unbanned. The code isn’t licensed or even restricted to be used.

EDIT: Just in case proof is needed/Acecool edits first post:

Thank you so much. <3

Josh “Acecool” Moser

what a totes legend

stop cyber bullying him please!!!

Hey, watch out, he’ll report you to the FBI even though you don’t live in America.

I stole your public code.

You’ll even have to explain to your local police why you’ve been “threatening to kill” some 30 year old man in America.