Skip to content

Changed to pass the shared_ptr by reference.

LEE Sing Chun requested to merge singchun/iMSTK:UPSCounterOnLinux into master

Problem: The UPS callback function crashed on Linux when it is called, which is reproducible.

Hunch: printUPS pass std::shared_ptr by value, which is create a new instance of std::shared_ptr. Later it is passed by reference into the callback Lambda function. After printUPS scope ends, the reference becomes invalid.

Resolution:

  1. Pass the std::shared_ptr by reference, so that the Lambda function get a reference of the original shared_ptr in the parent scope.

  2. Pass the capture by value to the Lambda function, so that it owns another shared_ptr of the UPSCounter.

  3. is applied. So long as the parent scope's shared_ptr will be destroyed after the UPSCounter, the reference in the callback will retain valid.

Merge request reports