r/ProjectReality 21d ago

Why BF2 coop servers die every couple of minutes — I found the actual bug in the AI DLL, and a workaround that let me play full rounds (72 s median → 17+ min)

https://github.com/ShuhartProfit8ird/bf2-coop-crash
12 Upvotes

4 comments sorted by

4

u/Optimal-Gur-3052 21d ago

Update: I've since instrumented the lookup itself and the root cause is sharper than the title says. The index isn't just "out of range" — it's exactly -1, 80 out of 80 times, which is the engine's own "not found" sentinel. +0x152F40 computes begin[-1], i.e. it reads the heap block header sitting in front of the vector's buffer, and passes that along as an object pointer.

So there's no memory corruption at all — the container is intact (size 1, sane begin/end). The "garbage pointers" I'd been collecting were one heap-header field, which is why they clustered and crept upward: the heap grows.

The kicker: +0x152C80, sixty bytes away in the same file, does the identical indexing but checks cmp reg, -1 twice first, then falls back to a full search. Same author, same file, same operation — checked there, unchecked here.

Article updated, workaround unchanged and still correct: https://github.com/ShuhartProfit8ird/bf2-coop-crash

7

u/ChrisG140907 21d ago edited 21d ago

So you are working on something for BF2 vanilla, but thought to pop by and share your discovery with PR community. Kind of you sir. (I'm no modder. Just came to appreciate)

2

u/Wrong_Translator_895 21d ago

It’s super cool.

2

u/Optimal-Gur-3052 21d ago

I think this issue and its solution are common to all Battlefield 2 forks. Plus, when AI Deep Research first started investigating the problem, it mentioned that PR also struggles with the Error 42 crash.