haxball / haxball-issues

115 stars 43 forks source link

Bug when changing stadium inside onStadiumChange #375

Closed iamrenan closed 6 years ago

iamrenan commented 6 years ago

So, I made a script for the room. I loaded it all and called room.setCustomStadium(Maps.BOUNCE) after room init in the code, then again later in the code with

room.onStadiumChange = (newStadiumName, byPlayer) => {
        room.setCustomStadium(Maps.BOUNCE);
}

Thing is, when I did that, the script broke and never finished. Firefox told me with these exact words "hey, this is taking too long bro. Stop this script or it'll never finish. amen" and after I stopped it, this message shows up:

Error: Script terminated by timeout at:
f@https://html5.haxball.com/v2k5hkN7/__cache_static__/g/vendor/json5.min.js:5:54
p@https://html5.haxball.com/v2k5hkN7/__cache_static__/g/vendor/json5.min.js:6:243
p@https://html5.haxball.com/v2k5hkN7/__cache_static__/g/vendor/json5.min.js:7:55
p@https://html5.haxball.com/v2k5hkN7/__cache_static__/g/vendor/json5.min.js:7:251
p@https://html5.haxball.com/v2k5hkN7/__cache_static__/g/vendor/json5.min.js:7:55
JSON5.parse</<@https://html5.haxball.com/v2k5hkN7/__cache_static__/g/vendor/json5.min.js:7:492
ag@https://html5.haxball.com/v2k5hkN7/__cache_static__/g/headless-min.js:78:1
setCustomStadium@https://html5.haxball.com/v2k5hkN7/__cache_static__/g/headless-min.js:56:269
room.onStadiumChange@debugger eval code:218:5
x.Tg/t.Ae@https://html5.haxball.com/v2k5hkN7/__cache_static__/g/headless-min.js:61:260
apply@https://html5.haxball.com/v2k5hkN7/__cache_static__/g/headless-min.js:96:268
we@https://html5.haxball.com/v2k5hkN7/__cache_static__/g/headless-min.js:40:480
Ib@https://html5.haxball.com/v2k5hkN7/__cache_static__/g/headless-min.js:41:374
c/<@https://html5.haxball.com/v2k5hkN7/__cache_static__/g/headless-min.js:54:58

Should I stop doing it this way or is it a bug? It only happens if I set a stadium after init and then set it again inside onStadiumChange apparently.

basro commented 6 years ago

You are creating an infinite loop. setCustomStadium changes the stadium which causes onStadiumChange to be called.

You could check that the byPlayer.id is not 0 to avoid this.