Fix crash on attach/detach in the same tick
Merge pull request #427 from pietern/attach-detach

Fix crash on attach/detach in the same tick