pcl icon indicating copy to clipboard operation
pcl copied to clipboard

[octree] use PCL_ERROR instead of assert

Open keineahnung2345 opened this issue 3 years ago • 2 comments

In release build, assert is ignored, this PR replaces them with PCL_ERROR.

keineahnung2345 avatar Jul 08 '22 08:07 keineahnung2345

I wouldn't change all asserts to ifs and PCL_ERROR. In functions that are called often, I would keep the assert for performance reasons. E.g. in addPointsFromInputCloud and addPointIdx, I would keep the check for valid indices in the assert (similar to std::vector::operator[] which also doesn't perform bounds-checking when not in debug mode). Another question would be, how to continue when an error is detected in an if statement. Often, we can just stop executing the function, but in some places, we should decide for some default (return) value, or how to notify the program of the error. In some places, an assert plus an if statement might make sense, or throwing an exception. We probably have to decide each case individually, I will try to make specific suggestions later. I found interesting to read:

  • https://stackoverflow.com/questions/12062365/is-using-assert-in-c-bad-practice
  • https://stackoverflow.com/questions/1081409/why-should-i-use-asserts
  • https://stackoverflow.com/questions/8114008/when-should-we-use-asserts-in-c

mvieth avatar Jul 11 '22 12:07 mvieth

@mvieth Any updates?

keineahnung2345 avatar Aug 29 '22 05:08 keineahnung2345