wasname321 Posted yesterday at 03:25 Share Posted yesterday at 03:25 Running a replay with -serializationtest=N segfaults at turn N+1 for me, in every game with Petra AIs I tried. For example skirmishes/acropolis_bay_2p with two Petra AIs and N = 200, on a clean release build of main 47f5fb4f (no local changes). The commits since then don't touch the simulation code. Backtrace, shortened: ``` JS::shadow::Zone::needsIncrementalBarrier (this=0x0) js::gc::PreWriteBarrierImpl JS::Heap<JS::Value>::~Heap ICmpTemplateManager::~ICmpTemplateManager (m_CachedInstance) CCmpTemplateManager::Deallocate CComponentManager::ResetState CComponentManager::~CComponentManager CSimulation2Impl::Update (the secondary simulation is rebuilt every turn) ``` What I think happens: 1. The serialization test destroys the previous turn's secondary CComponentManager every turn. 2. ~CComponentManager first removes its extra GC roots tracer, and ResetState() clears m_TraceCache, so the components' cached JS instances aren't traced any more. 3. ResetState() then deletes the components in reverse order. Deleting the AIManager destroys the AI's script interface, and Context::UnRegisterRealm calls JS::FinishIncrementalGC if an incremental GC is running. MaybeIncrementalGC() at the end of each turn usually leaves one running. 4. That GC sweeps the cached instances of the components that haven't been deleted yet. 5. The next destructor, the TemplateManager's JS::Heap<JS::Value> m_CachedInstance, runs a write barrier on the dead cell. Finishing any incremental GC at the start of ~CComponentManager, before anything stops being traced, fixed it for me: ``` CComponentManager::~CComponentManager() { JSContext* cx = m_ScriptInterface.GetGeneralJSContext(); if (JS::IsIncrementalGCInProgress(cx)) JS::FinishIncrementalGC(cx, JS::GCReason::API); JS_RemoveExtraGCRootsTracer(cx, Trace, (void*)this); ResetState(); } ``` With it, Acropolis Bay ran 100 turns of the serialization test without problems, and a random map game ran 1,000 turns. Something else I noticed while looking at this, though it wasn't the cause: Update assigns a new m_SecondaryTerrain before it replaces the context and component manager that still point to the old terrain. Resetting the component manager first, then the context, then the terrain avoids that. Link to comment Share on other sites More sharing options...
Stan` Posted 23 hours ago Share Posted 23 hours ago Hey @wasname321 I'll answer here, maybe you should create issues and PRs. @hyperion @phosit can you check the 4 topics here ? Link to comment Share on other sites More sharing options...
hyperion Posted 21 hours ago Share Posted 21 hours ago I can look into this one, which are the other 4? Link to comment Share on other sites More sharing options...
wasname321 Posted 14 hours ago Author Share Posted 14 hours ago Hello @Stan`, I tried several times to create an account on Gitea but never received the confirmation email, which is why I posted here. I'll try again and open the issues and PRs there if I manage to. @hyperion thanks! I think the other ones are those three (the fourth topic is this one): Link to comment Share on other sites More sharing options...
Itms Posted 6 hours ago Share Posted 6 hours ago I activated your account manually. 1 Link to comment Share on other sites More sharing options...
hyperion Posted 3 hours ago Share Posted 3 hours ago Ok, here a pr addressing the issue https://gitea.wildfiregames.com/0ad/0ad/pulls/9414 About the other 3, they look they would fall into @phosit and maybe @Vantha area of expertise. So if they have the capacity to check them I'd gladly leave it to them. Link to comment Share on other sites More sharing options...
wasname321 Posted 12 minutes ago Author Share Posted 12 minutes ago Thanks for the PR (#9414) and for activating my account, I opened the other three as issues: #9416 (Petra noBase on Wall Demo), #9417 (Flood) and #9418 (Survival of the Fittest). Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now