Unexpected behaviour with customscenenedes and vector

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
bonsalty
Posts: 120
Joined: Thu Dec 10, 2009 1:30 pm
Location: Budapest,Hungary

Unexpected behaviour with customscenenedes and vector

Post by bonsalty »

I have a wrapper class for drawing lines:

Code: Select all

class Line : public VertexBuffer{
int id;
public:
	Line():VertexBuffer(){id=-1;}
	void AddLine(double x1, double y1,double z1, double x2,double y2, double z2);
	virtual void render();
	void SetID(int ID);
	int GetID();

};
where vertexbuffer class holds the vertices of the line and it is inherited from ISceneNode :

Code: Select all

class VertexBuffer: public scene::ISceneNode {

public:
	Irrlicht_params *params;
	core::aabbox3d<f32> Box;
	vector<video::S3DVertex> vertex;
	video::SMaterial Material;
	BOOL ccw;
	BOOL update;
	int width;
	double posX,posY,posZ,scaleX,scaleY,scaleZ;

	double red,green,blue,gamma,nX,nY,nZ;


	VertexBuffer(): scene::ISceneNode(NULL, NULL,0){...}
	~VertexBuffer(){Remove();}

	void SetScale(double x, double y,double z);
	void SetPosition(double x, double y,double z);
	void SetWidth(int w);
	void SetDefaultColor(double r,double g,double b,double i);
	void SetDefaultN(double nx,double ny,double nz);
	void New(Irrlicht_params *ip);
	void SetPosition(int index, double x, double y, double z);
	void SetColor(int index, double r, double g, double b, double i);
	virtual void OnRegisterSceneNode();

	virtual const core::aabbox3d<f32>& getBoundingBox() const	    
{	   return Box;	}
	virtual u32 getMaterialCount() const{	return 1;	}
	virtual video::SMaterial& getMaterial(u32 i){	return Material;	}	

	void Remove(){
	this->remove();
	vertex.clear();
	}
	Irrlicht_params * Params();
	protected:
	void AddVertex(double x,double y,double z);
	
};

The purpuse of the Line class is adding any number of lines to the scene, easely with AddLine(). All vertex are drawn automaticly in the render() process called by irrlicht. The code seems fine and its ok.

PROBLEM:

The strange thing happens after I put the Line class in a deque or vector.
vector <Line> line;

Imagine I want to draw a contourmap. I put the lines of each altitude/ level into a vector element. 10 levels mean 10 vector elements holding the polylines. When I remove only one level of contourlines, in other words one element from the Line vector, Irrlicht seems to stop rendering the other elements of the vector . Despite 9 level of lines are seen properly in the debuger, only 5 levels gets rendered . I have no clue why this happens.

Interestingly using pointers in the vector :

Code: Select all

vector < * Line> line;
seems to solve the problem.

What the hack is up with the customscenenode. What method is used when removing a node, why does only pointer vectors work?
Tomi
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I'm retty sure that this is not a bug in Irrlicht, hence move it to the problem forums.
Post Reply