Apparently it's dangerous to erase from within a for loop and it was causing crashes on Wayland, but not X11 (oddly).