pcl
pcl copied to clipboard
[octree] use PCL_ERROR instead of assert
In release build, assert is ignored, this PR replaces them with PCL_ERROR.
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 Any updates?