graph construction

hello
i have a bad_alloc at memory location in the debug ,please can you tell me where i cheated
this is where the problem is
/////////////////////////////
printf("Constructing clips... ");

// construct edge clips
for (size_t eid = 0; eid < edges.size(); eid++)
{
printf("edge(%d) ", eid);

Motion *clip = NULL;

Edge &e = edges[eid];
Node &nsrc = nodes[e.src];
Node &ndst = nodes[e.dst];

if (nsrc.motionIdx != ndst.motionIdx || e.length != ndst.frameIdx - nsrc.frameIdx) // transition between two motions
{
printf("src(%d, %d) dst(%d, %d) %d\n", nsrc.motionIdx, nsrc.frameIdx, ndst.motionIdx, ndst.frameIdx, e.length);
try
{
Transition *tran = new Transition(library->getMotion(nsrc.motionIdx), nsrc.frameIdx, library->getMotion(ndst.motionIdx), ndst.frameIdx, e.theta, e.x0, e.z0);
clip = tran->getBlendedMotion();
delete tran;
}
catch (std::exception &e)
{
printf("%s\n", e.what());
exit(-1);
}
}
else // forward edge
{
printf("forward src(%d, %d) dst(%d, %d) %d\n", nsrc.motionIdx, nsrc.frameIdx, ndst.motionIdx, ndst.frameIdx, e.length);
Motion *motion = library->getMotion(nsrc.motionIdx);
clip = new Motion(e.length + 1, library->getSkeleton());
if (e.length != ndst.frameIdx - nsrc.frameIdx)
{
printf("Error: edges[%d].length != nodes[%d].frameIdx - nodes[%d].frameIdx\n", eid, e.dst, e.src);
}

for (int i = 0, j = nsrc.frameIdx; i < e.length + 1; i++, j++)
{
clip->SetPosture(i, *motion->GetPosture(j));
}
}

clips.push_back(clip);
}

printf("done.\n");

reset();

printf("Generating motion graph: done.\n");
}

thank you for your help
> this is where the problem is
good, you managed to enclose it, now make a minimal example that does reproduce it.


About your memory allocation
http://www.cplusplus.com/forum/general/138037/
Specifically:
1
2
clip = tran->getBlendedMotion();
delete tran;

If tran->getBlendedMotion() returns a pointer to a member of tran, then after line 2, clip points to unallocated memory.
Topic archived. No new replies allowed.