-
Notifications
You must be signed in to change notification settings - Fork 46
Retrieving weights of a rational BSpline surface causes crashing #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
yes it is likely to do with the pointer as outlined here https://pybind11.readthedocs.io/en/stable/advanced/smart_ptrs.html#smart-pointers (the part where they point out returning a raw pointer that breaks the code). although, i thought there were other places in the pyOCCT codebase that returned raw pointers without issue. Might have to find some of these places and if they all crash, then we'll need to find a way to fix returning raw pointers in general. For this specific case, we could alter the source code to this: cls_Geom_BSplineSurface.def("Weights", [](Geom_BSplineSurface &self) {TColStd_Array2OfReal weights(1, self.NbUPoles(), 1, self.NbVPoles()); self.Weights(weights); return weights; }); This just calls the other method behind the scenes, but with the same signature as the one causing the issue. |
The conservative thing to do might be just skip any function that returns a pointer for now and handle this type of thing on a case-by-case basis until a more general and proper solution can be found 🤔 |
I think that in the case of weights it would be nice to replicate a behavior similar to what happens in C++, i.e. it returns |
I have a suggestion in accordance with my prior comment which does not require C++17: cls_Geom_BSplineSurface.def("Weights", [](Geom_BSplineSurface& self) -> py::object {return self.Weights() ? py::cast(*self.Weights()) : py::none();}); |
@russelmann thanks, that seems to do the trick for this case. Opened #84 |
Calls to method
const TColStd_Array2OfReal* Geom_BSplineSurface::Weights() const
crash while the same operation runs fine using the alternative signaturevoid Geom_BSplineSurface::Weights(TColStd_Array2OfReal& W) const
.This might be caused by the fact that the return type is a pointer unlike with other similar methods, such as
const TColgp_Array2OfPnt& Geom_BSplineSurface::Poles() const
which return a reference and do not cause any problems.I think the same problem occurs with rational BSpline curves. Let me know if a code snippet for this case would be useful too.
The text was updated successfully, but these errors were encountered: