Stack Overflow

I noticed on my spacebuild 2 server console, this line:

ERROR: GAMEMODE:‘PlayerSpawn’ Failed: sandbox/gamemode/init.lua:40: stack overflow

Looked like a player was trying to join, but couldn’t. How do I fix this? Or is this on their end?

**Edit: **Who the fuck rated me disagree?

nice to see u again:P

and: its hooking off sandbox, wich when u DONT override the playerspawn it wil error out
so just override the spawn function in ur SB2 init file

Yeah, I’ve been around. You aren’t on my steam list anymore, who knows why. I suppose PM me for the steam name.

Anyhow, how do I override that?

if its in a gamemode use:
function GM:PlayerSpawn(ply) end
or in addon format
timer.Simple(5, function GAMEMODE:PlayerSpawn(ply) end)
extra info, in addon shape i use an timer, since when u just use GM it errors out, and GAMEMODE errors out BEFORE the gamemode stuff is loaded so thats why the timer and its set to 5 seconds so u got enough time to load the gamemode. (can be done in 1 second)

I’m pretty sure theres a fixed version around as this works fine for me, I hosted SB2 briefly and had no issues at all.

correct, theres a fixed version of this on, but just so every one else in all gamemodes can fix this.

You’re calling functions inside functions far too often, it is most likely infinate looping.

Overriding sandbox functions tends to cause this occasionally.

It didn’t do this before a gmod update about a year ago…

After this update the overflow bug started occuring in gamemodes, entities, vgui (derma),…

Sloppy coding is the only cause of it. You getting this error means you need to severely improve your coding style.

I hope you know that it only happened when we didn’t make our own function for something that already existed. Say you didn’t want to modify the Spawn function, then you wouldn’t implement it, since the code for it was already in the base + sandbox code. After the gmod update all of a sudden the overflow occured when you did that for certain functions. So don’t say it’s sloppy coding.

Before the update you could do this without problems

Custom Gamemode derives from Sandbox which derives from Base (any level more would cause similar error)

After the update only this works (without manually overriding functions you shouldn’t have to override)

Sandbox derives from Base (Any gamemode deriving from Sandbox had to implement, usualy just a copy paste of the original Spawn function).

That’s not what I call sloppy coding, that’s what I call a bug…

You can derive a gamemode as many times as you want. There is no limit.

Why have I never had any problems with this besides from when I made a blatent mistake leading to an infinate loop, if what you say is true?

If you override the functions in question you’ll never have an issues. But in SB the PlayerSpawn function never had to be modified, so why would we have to implement it ourself when it was in the base code already?

This gmod update just broke that…

Any custom functions or functions you override (without calling self.BaseClass.function to much, which is what Garry reduced) won’t cause any issues at all…

Let’s make a small example.

  1. Say you add a function called GM:MyCustomFunction() in your gamemode.

  2. Some other gamemode deriving from your gamemode overrides the implementation of your function, but adds a self.BaseClass.MyCustomFunction call => No problem yet

  3. Some other gamemode deriving from gamemode 2 now wants to override that function again, and calling self.BaseClass.My… again, since it only wants to add something to it, not modify it. => Breaks in the current version of Gmod (this is what the Update broke, before this only started happening around Gamemode 4, not 3)