The CPU pointer is cast using dynamic_cast, but the GPU pointer is cast using a static_cast. The latter needs to be changed to a dynamic_cast.