I just had the same problem but I notice something else:
- If the variable is a member of the class: The function fails.
- If the variable is a pointer (allocated with a new): The function works....