Help to erase Line Segs


I am having an issue to figure out how erase some Line Segs. the code below draw a lot of Line Segs in a graphic while it iterate the list, but when i try to remove the node eixo_bot_np it only removes one Line Segs and not all the Line Segs. If anyone could help me how to resolve this i would be greatful.

PT(GraphicsMenu) graphics_menu = (PT(GraphicsMenu)) (GraphicsMenu*) data;
		PT(TimeControl) time_control = TimeControl::get_instance();
		int diaPassado = time_control->get_dia_passado();
		stateHistory::SHList listEvent;
		listEvent = *graphics_menu->get_stateHistory()->get_list(stateHistory::SH_changed_shadow);
		std::list<stateHistory::state>::iterator iterator;
		stateHistory::state test;
		if(flag_btn_sombra == 0 && flag_btn_comeu == 0 && flag_btn_correndo == 0){

		flag_btn_sombra = 1;
		for(iterator = listEvent.begin(); iterator != listEvent.end() ; ++iterator){
			test = *iterator;
			float posicaoX = ((test.hour_event*0.54)/24)+0.03;

			if(test.event_day == (diaPassado - contador)){
				if(graphics_menu->get_chart1() != NULL){
				eixo_bot = new LineSegs("eixo-bot");
				eixo_bot->set_color(0, 1.0, 0.0);
				eixo_bot->draw_to(0.0, 0.0, 0.0);
				eixo_bot->draw_to(0.0, 0.0, 0.54);
				eixo_bot_np = graphics_menu->get_chart1()->get_graphic_np().get_parent().attach_new_node(eixo_bot->create(true));
				eixo_bot_np.set_pos(window->get_render_2d(), posicaoX, 0.0, 0.13);
				if(graphics_menu->get_chart2() != NULL){
				eixo2_bot = new LineSegs("eixo2-bot");
				eixo2_bot->set_color(0, 1.0, 0.0);
				eixo2_bot->draw_to(0.0, 0.0, 0.0);
				eixo2_bot->draw_to(0.0, 0.0, 0.54);
				eixo2_bot_np = graphics_menu->get_chart2()->get_graphic_np().get_parent().attach_new_node(eixo2_bot->create(true));
				eixo2_bot_np.set_pos(window->get_render_2d(), posicaoX, 0.0, -0.77);
		else if(flag_btn_sombra == 1 && flag_btn_comeu == 0 && flag_btn_correndo == 0){
		flag_btn_sombra = 0;

Hi Campos,

This code seems extremely wrong. It also seems to have performance issues.
I guess you didn’t mean to create a LineSegs for each marker of your chart.
You should create the LineSegs outside the loop, and consolidate it after the loop.
Inside the loop you should use move_to / draw_to to draw your markers.
This way you’ll end up with only one node, that you can remove later.

Probably graphics_menu->get_chart1()->get_graphic_np().get_parent() end up with several child nodes with 1 line each. You probably don’t want that. You probably want one node with several line segments (probably a single LineSegs).

When you remove the NodePath, you’re probably removing the last LineSeg only, as you are overhiding the eixo_bot_np each step.

Note that I spammed the word “probably”, because little context was provided.

As you know, I worked in this project also. Not anywhere near this stuff, though. 8)
I understand why it turn out to be that mess, but that is beside the point. :slight_smile:
Anyway, I suggest you to start refactoring (at least the key points) as you gain more experience. :smiley: