Problem with "Cannot access global variables in destructed object"