Skip to content

LineShape in iOS #212

@mememto

Description

@mememto

Hi to everyone and thanks in advance. I've made LineShape class for iOS but i'm experiencing some kind of problems. The class seems to work fine, but whenever I call shapesRenderer->removeAllShapes(); i get the following exception:

pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

Not sure of what is causing this. Any help would be appreciated since it's been years since the last time i used C++ :/ By the way sorry for the indentation, not sure of how to do this :/

.HPP
class LineShape : public AbstractMeshShape {
private:
void computeOrientationParams(const Planet *planet);
protected:
Mesh* createMesh(const G3MRenderContext* rc);
public:
float _width;
Color* _color;
Vector3D* _cartesianStartPos;
Geodetic3D* _geodeticEndPos;

`LineShape(Geodetic3D* startPosition,`
         `Geodetic3D* endPosition,`
         `AltitudeMode altitudeMode,`
         `float width,`
         `const Color& color) :`
`AbstractMeshShape(startPosition, altitudeMode),`
`_cartesianStartPos(),`
`_geodeticEndPos(endPosition),`
`_width(width),`
`_color(new Color(color))`
`{}`

`~LineShape() {`
    `delete _color;`
    `delete _cartesianStartPos;`
    `delete _geodeticEndPos;`
`}`

std::vector<double> intersectionsDistances(const Planet* planet, const Vector3D& origin, const Vector3D& direction) const;
};

.CPP
void LineShape::computeOrientationParams(const Planet *planet) {

_cartesianStartPos = new Vector3D(planet->toCartesian(getPosition()));
Vector3D cartesianEndPos(planet->toCartesian(*_geodeticEndPos));
Vector3D line = cartesianEndPos.sub(*_cartesianStartPos);
setScale(1, 1, line.length());
Vector3D normal = planet->geodeticSurfaceNormal(*_cartesianStartPos);
setPitch(line.angleBetween(normal).times(-1));
Vector3D north2D = planet->getNorth().projectionInPlane(normal);
Vector3D projectedLine = line.projectionInPlane(normal);
setHeading(projectedLine.signedAngleBetween(north2D, normal));

}

Mesh* LineShape::createMesh(const G3MRenderContext* rc) {
FloatBufferBuilderFromCartesian3D* vertices = FloatBufferBuilderFromCartesian3D::builderWithoutCenter();

vertices->add(0.0f, 0.0f, 0.0f);
vertices->add(0.0f, 0.0f, 1.0f);

`if (_cartesianStartPos == NULL)`
    `computeOrientationParams(rc->getPlanet());`

`Mesh* mesh = new DirectMesh(GLPrimitive::lines(), true, vertices->getCenter(), vertices->create(), _width, 1, _color);`

`delete vertices;`

`return mesh;`

}

std::vector<double> LineShape::intersectionsDistances(const Planet* planet, const Vector3D& origin, const Vector3D& direction) const {

`std::vector<double> intersections;`
`return intersections;`

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions