ondras / rot.js

ROguelike Toolkit in JavaScript. Cool dungeon-related stuff, interactive manual, documentation, tests!
https://ondras.github.io/rot.js/hp/
BSD 3-Clause "New" or "Revised" License
2.32k stars 254 forks source link

Simple scheduler schedules items after removal #187

Closed sil-quirk closed 3 years ago

sil-quirk commented 3 years ago

Reproduction: use the example code, modify by adding the single line marked below:

var scheduler = new ROT.Scheduler.Simple();

/* generate some actors */
for (var i=0;i<4;i++) {
    scheduler.add(i+1, true); /* true = recurring actor */
}       

/* simulate several turns */
var turns = [];
for (var i=0;i<20;i++) {
    var current = scheduler.next();
    turns.push(current);
    // THIS LINE ADDED
    if (i === 4) scheduler.remove(3);
}       

console.log("\nGenerated order of actors:");
console.log(turns.join(" ") + " ...");

Any i which is 0 mod 4 will replicate; 3 gets an additional turn after removal.

ondras commented 3 years ago

Nice find! Thanks, @sil-quirk .

ondras commented 3 years ago

@Syntacticlosure, I have a feeling that this bug has been introduced with MinHeap. Would you please take a look? :)

Syntacticlosure commented 3 years ago

I am sorry to hear about bugs found in the code which i contributed. During last several months, I was in hospital and docters diagnosed me with crohn's disease. So I suggested finding anyone else to fix this bug or rolling back to older version of scheduler.

ondras commented 3 years ago

Hi all,

@sil-quirk, I believe I fixed the issue. Please try updating to the latest version (2.1.5).

@Syntacticlosure hope you will get better soon! (I am quite familiar with Crohn, so I at least wish your symptoms are mild.)

sil-quirk commented 3 years ago

Hi, I agree it appears to be fixed now, I'm happy with the issue being closed.