LibCore: IDAllocator should never vend ID 0

This was tripping up CObject which interprets timer ID 0 as "no timer".
Once we got ID 0 assigned, it was impossible to turn it off and it
would fire on every event loop iteration, causing CPU churn.
This commit is contained in:
Andreas Kling 2020-01-05 15:11:49 +01:00
parent c410644c90
commit 1da31ce8ae
Notes: sideshowbarker 2024-07-19 10:20:35 +09:00

View file

@ -16,6 +16,9 @@ public:
int r = rand();
for (int i = 0; i < 100000; ++i) {
int allocated_id = r + i;
// Make sure we never vend ID 0, as some code may interpret that as "no ID"
if (allocated_id == 0)
++allocated_id;
if (!m_allocated_ids.contains(allocated_id)) {
m_allocated_ids.set(allocated_id);
return allocated_id;