Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kernel.RunAllAgents() crashes if an agent is removed #430

Open
garfieldnate opened this issue Feb 2, 2024 · 0 comments
Open

kernel.RunAllAgents() crashes if an agent is removed #430

garfieldnate opened this issue Feb 2, 2024 · 0 comments

Comments

@garfieldnate
Copy link
Collaborator

garfieldnate commented Feb 2, 2024

Soar's run command is a kernel-level command, but internally it anchors on one agent, any agent, to do some kind of bookkeeping that I don't understand. When a client callsKernel.RunAllAgents(), the SML client library picks the first agent out of m_AgentMap and uses that for the anchoring. If an event handler is used to destroy an agent during the run, the kernel maintains its reference to the agent it anchored on and Soar crashes when the deallocated agent is next referenced.

Adding agents surprisingly works fine for the above usage pattern, but removal will cause a crash if you are unlucky and the random agent to be anchored on is the one that is removed. There are probably other commands with the same issue, and I think refactoring the kernel to not require the one agent anchor might be a large task.

A much safer usage pattern is to manage the list of agents in the client code and call RunSelf() on them in a loop. If an agent is destroyed, the client can then stop calling RunSelf() on that agent in the loop.

Another simple fix for this issue that doesn't require re-architecting your application is to simply replace kernel calls that run all agents with agent calls that do the same thing, using agents that you know will never be destroyed. That is, instead of kernel.RunAllAgents(X), do agent.ExecCommandLine("run -d -i p X)", where you are certain that agent is one that will never be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant