fix: persistent bot thread to eliminate ORC heap corruption #97
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
A new bot thread is created every round via
createThread/joinThread. When thread N dies, its ORC allocator is destroyed, but module-levelseq/stringglobals still reference its heap blocks. Thread N+1 touching those globals causes SIGSEGV inprepareSeqAddUninit/rawDealloc.Current workarounds use fixed-size arrays with silent ceilings:
Solution
Replace thread-per-round with a single persistent bot thread that lives for the process lifetime. Between rounds it blocks on a channel waiting for the next round-start signal. This keeps the allocator alive, eliminating all fixed-array workarounds.
Files
src/robocode_tankroyale_botapi/bot.nim(thread lifecycle, fixed arrays)src/robocode_tankroyale_botapi/event_queue.nim(fixed array)src/robocode_tankroyale_botapi/graphics.nim(fixed array)Fixed in v1.0.2. Bot thread is now persistent across rounds — created once, waits on a channel between rounds. All fixed-array workarounds removed, normal seq/string restored. Validated with 3-round battle test.