The manual states that pointers can change after calling wait(). Me and you are the only pointers guaranteed to be unchanged.

Wait() returns from a function. I think it is possible that the pointer and the memory area are losing scope after this and it's possible that the memory area is overwritten later.

Maybe you could try creating the panel in a function which doesn't use wait() and pass the panel pointer to another function that uses wait() like in your example, like dependency injection.