Open mememto opened 7 years ago
Hi @mememto
It doesn't look like a G3M issue.
BTW, taking a very quick overview, the problem seems to be that _cartesianStartPos pointer is not initialized to NULL and it has a dangling pointer.
And please google for "xcode add exception breakpoint". It's very helpful to know where the exception is thrown.
Hi @DiegoGomezDeck. Thanks for your tip, i will check in some hours and let you know something.
Hi again @DiegoGomezDeck. I've initialized _cartesianStartPos to NULL, but the same thing happens. To get deep into the issue this is how i use LineShape:
- (void) paintLines {
if (points != nil && points.count > 0) {
shapesRenderer->removeAllShapes();
for (int i = 0; i < points.count - 1; i++) {
Geodetic3D *origin = new Geodetic3D(Angle::fromDegrees(((CLLocation *)[points objectAtIndex:i]).coordinate.latitude), Angle::fromDegrees(((CLLocation *)[points objectAtIndex:i]).coordinate.longitude), 0);
Geodetic3D *end = new Geodetic3D(Angle::fromDegrees(((CLLocation *)[points objectAtIndex:(i+1)]).coordinate.latitude), Angle::fromDegrees(((CLLocation *)[points objectAtIndex:(i+1)]).coordinate.longitude), 0);
Shape *line = new LineShape(origin, end, RELATIVE_TO_GROUND, 10, Color::fromRGBA(1.0f, 0.0f, 0.0f, 1.0f));
shapesRenderer->addShape(line);
}
[self paintPoints];
}
}
This method is called several times, since the number of CLLocation elements inside points array is increased or decreased depending on user. My objective is to draw a multi-line. If there are at least two CLLocation elements inside points array, the for loop creates one new ShapeLine and add it to shapesRenderer:
shapesRenderer = builder.createShapesRenderer();
builder.addRenderer(shapesRenderer);
This works fine. The problem takes place when one CLLocation element is added to points array and the paintLines method is called again. This time, the shapesRenderer->removeAllShapes();
triggers an malloc_error_break exception complaining about delete _flatColor;
line in AbstractMesh.cpp file. Any suggestions? Thanks in advance =)
One more thing, commenting the delete _flatColor
line seems to fix the issue, but i'm not sure of how this will affect other things 😣
Anyway, the result is not as promising as i thought. Here is a screenshot of the "multi-line". Only the first segment seems visible, the others are strangely cut:
Mesh* mesh = new DirectMesh(GLPrimitive::lines(), true, vertices->getCenter(), vertices->create(), _width, 1, _color);
You're passing object hold in _color and also deleting it from the constructor. DirectMesh assumes it's the owner of _flatColor pointer and handles its deletion.
Anyway, the result is not as promising as i thought. Here is a screenshot of the "multi-line". Only the first segment seems visible, the others are strangely cut:
Sure, you're drawing straight lines and the earth surface has a curvature. Disabling depth test helps sometimes.
Thanks for your help @DiegoGomezDeck
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;
std::vector<double> intersectionsDistances(const Planet* planet, const Vector3D& origin, const Vector3D& direction) const;
};
.CPP void LineShape::computeOrientationParams(const Planet *planet) {
}
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);
}
std::vector<double> LineShape::intersectionsDistances(const Planet* planet, const Vector3D& origin, const Vector3D& direction) const {
}