Adding to a vector

EQ2Emulator Development forum.

Moderator: Team Members

Post Reply
User avatar
Gangrenous
Posts: 812
Joined: Sun Apr 24, 2016 6:54 am
Characters: Dinsmoor

Adding to a vector

Post by Gangrenous » Wed Dec 28, 2016 2:13 pm

I understand the most efficient way of adding to a vector is with a push_back. What if I want to add to the beginning of a vector? I should be able to do this with insert from what I read. If I do this, even with it locked, I get a nice error a few seconds later. Specifically I want to add to movement_loop. I have been reading about vectors and somewhat understand the workings, but not completely. Any idea what I cold be doing wrong here?

The exact error is...

Code: Select all

*** Error in `/home/eq2/src/source/WorldServer/eq2world': double free or corruption (fasttop): 0x00007fffa859a3a0 ***

Program received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffd27fc700 (LWP 16940)]
0x00007ffff6497067 in raise () from /lib/x86_64-linux-gnu/libc.so.6
Resident Dirty Hippy

User avatar
Gangrenous
Posts: 812
Joined: Sun Apr 24, 2016 6:54 am
Characters: Dinsmoor

Re: Adding to a vector

Post by Gangrenous » Wed Dec 28, 2016 3:39 pm

Okay, I think I have it working but I am not certain why this does not work.

Code: Select all

	MovementData* data = new MovementData;
	data->x = x;
	data->y = y;
	data->z = z;
	data->speed = speed;
	data->delay = delay*1000;
	if(lua_function)
		data->lua_function = string(lua_function);
	
	movement_loop.insert(movement_loop.begin(), data);
	movement_loop.push_back(data);
This crashes. But if I define a new MovementData as data2 and assign everything, then do a push_back on data2 and not data, no crashes.
Resident Dirty Hippy

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests