spawn_agent doesn't work in MB 1011 in a mission trigger?

Users who are viewing this thread

The infamous stack overflow exception. There is even a famous programming website named after that. :grin:
Let's start with stacks and overflows.
Stack is kind of a data structure to store data in programming. Think about a gun and its magazine. Magazine is the stack. When you putting bullets into magazine you're storing data into the stack and when you shoot the gun you retrieve data from the stack. Assume you don't shoot but keep putting bullets int the magazine. At some point it becomes full and you can't put bullets anymore. That's what we call an overflow in programming. You wanna store some data, but you don't have enough available space in the data structure.
You didn't specify mission template id or pasted some code, so i'm just gonna guess.
One of the most common causes of stack overflow is recursion. Recursion means a function calling itself. Scripts are the closest thing to functions in programming, so think about a script calling itself in its code. When you call scripts with parameters, those parameters are stored in the stack. After script ends, those parameters loses their uses and removed from the stack to create space in the stack. While using recursion, parameters are stored without releasing until recursion ends. With enough amount of recursion, the stack will be filled and you will have a stack overflow exception. You may have a script with causing infinite recursion. That's my first guess.
After you spawn an agent (calling spawn_agent operation) in a mission_template, triggers with ti_on_agent_spawn interval execute. If you call spawn_agent operation here in a wrong way something like this may happen.

- Agent is spawned.
- Spawned agent caused on_agent_spawn trigger to execute.
- Executed trigger spawned another agent.
- Spawned agent caused on_agent_spawn trigger to execute.
- Executed trigger spawned another agent.
- Spawned agent caused on_agent_spawn trigger to execute.
- Executed trigger spawned another agent.
.
.
.

This is some sort of indirect recursion of on_agent_spawn trigger. (It probably stores spawned agent data on stack.) If it's called enough, it'll fill stack and cause overflow. That's my second guess.

Other then these it might be game engine bug or mod is too resource intensive and there isn't enough memory available. (stack takes place in system memory) I hope it helps.
 
Upvote 1
Im literally just putting (spawn_agent, "trp_guide") by itself in a mission trigger that checks once the first second a mission/scene is loaded. I found out if i put it in the conditions block it doesnt crash it and still works, very wierd. any ideas?
 
Upvote 0
Im literally just putting (spawn_agent, "trp_guide") by itself in a mission trigger that checks once the first second a mission/scene is loaded. I found out if i put it in the conditions block it doesnt crash it and still works, very wierd. any ideas?
Sorry for the late reply, i missed your post among other threads.

I think you should really post the code for people to comment properly. It's turning into a guessing contest this way :grin: I'm guessing again. My guess is you placed some can fail statements into the consequences block of that trigger which fails and ends the consequences block prematurely, something left unfinished and code crashes somewhere else that depends on this trigger's consequences block's proper execution to work properly.

Can fail operations must be placed inside try blocks. If not, when they fail, caller trigger or script ends the execution there. Even if it's a script called by another script or a trigger, it ends and caller trigger's or script's rest of the operations after the script call don't execute.
 
Upvote 0
Back
Top Bottom