Fix crash on invalid script threads