Skip to content

Fixed crash on testmaps/test_lotsaimps#721

Merged
DanielGibson merged 1 commit intodhewm:masterfrom
klaussilveira:fix/ai-segfault
Jan 6, 2026
Merged

Fixed crash on testmaps/test_lotsaimps#721
DanielGibson merged 1 commit intodhewm:masterfrom
klaussilveira:fix/ai-segfault

Conversation

@klaussilveira
Copy link
Contributor

root->children[0] and root might be null here, which causes a crash in certain scenarios when playing testmaps/test_lotsaimps.

@DanielGibson
Copy link
Member

Have you tried figuring out why that happens?
I.e. why is FindOptimalPath() called with root = NULL?
If I understand the code correctly, root is from root = BuildPathTree( ... ); in idAI::FindPathAroundObstacles().
BuildPathTree() does

root = pathNodeAllocator.Alloc();
root->Init();
...
return root;

So the code in that function is already completely broken if pathNodeAllocator.Alloc() returns NULL, really surprised that it doesn't crash there already

@klaussilveira
Copy link
Contributor Author

I did not gdb into it. In my specific casing, testing test_lotsaimps, root->children[0] was null.

I added the root check because I've noticed that BFG has it: https://github.com/id-Software/DOOM-3-BFG/blob/master/neo/d3xp/ai/AI_pathing.cpp#L900

@DanielGibson
Copy link
Member

DanielGibson commented Jan 6, 2026

Ok - root->children[0] being NULL is possible, the root check in BFG still makes no sense to me.

I haven't really understood that code, but probably one could skip a lot of code if the root returned by BuildPathTree() doesn't have any children (by checking that case right after the BuildPathTree() call and returning false if there are no children - Upd: But OTOH it also seems possible that root->children[0] is set to NULL in PrunePathTree()).. but checking for NULL before dereferencing root->children[0] certainly is the simpler, less invasive solution and done by BFG as well - you could've mentioned that the code originates there.

@klaussilveira
Copy link
Contributor Author

klaussilveira commented Jan 6, 2026

@DanielGibson
Copy link
Member

Can you remove the root != NULL parts?
That makes the changes more minimal, which makes porting mods easier (of this I was just reminded when applying the "HeXen: Edge Of Chaos" changes to the dhewm3-sdk: every change to the gamecode is a potential merge conflict, so keeping them minimal reduces friction)

@klaussilveira
Copy link
Contributor Author

That makes sense. Just pushed it.

@DanielGibson
Copy link
Member

Thanks - can you also adjust the commit message? ;)

@klaussilveira
Copy link
Contributor Author

Done.

@DanielGibson DanielGibson merged commit 7415700 into dhewm:master Jan 6, 2026
4 checks passed
@DanielGibson
Copy link
Member

Awesome, thanks a lot!

@klaussilveira klaussilveira deleted the fix/ai-segfault branch January 6, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants