fix segfault cause by listener being removed when resource is destroyed