Fix sprite loading race condition (fixes #593)