Quick SetUserData and GetUserData Question

I have a shape and I'd like to remember its initial location by saving its vertex data to the fixture's userdata...

Code:
b2PolygonShape* poly = (b2PolygonShape*)fixture->GetShape();
int32 vertexCount = poly->GetVertexCount();
b2Vec2 vertices[b2_maxPolygonVertices];
for (int32 i = 0; i < vertexCount; ++i){
   vertices[i] = b2Mul(xf, poly->GetVertex(i));
}

fixture->SetUserData(vertices);


…but when I later go to retrieve the vertices array I can't seem to get the array back. i would think it would work something like the following…

Code:
b2Vec2 old_vertices[b2_maxPolygonVertices];
old_vertices  = fixture->GetUserData();


…but i can't seem to get old_vertices to be what the fixtures original shape vertices were.

all guidance appreciated! (btw the xf transform is from code above the snippets i've pasted - i'm using the transformed vertices array for other stuff and it's all working great - just can't seem to save off and retrieve a vertex array via userdata)

i know i probably have to cast what i get back from getuserdata but my limited c++ skills are failing me - as have a couple hours on stackoverflow and trying just about every casting variation i could dream up. 😮
You're declaring your vertices array on the stack. When you exit that function, that memory gets freed and the user data points at garbage.
But userdata is a property of the fixture - and isn't the point of setuserdata that it should *copy* the vertices array into the fixture so I can later call that fixture's getuserdata to retrieve it?
Userdata is a void pointer. You're right that it should copy something, but that isn't the contents of the array, it's the pointer to the array. Box2D has no way of knowing what's pointed by userdata.
awesome! that clears up so much! thank you 😀

would you happen to know if there's a way to get the untransformed(?) vertex array for a shape without saving its initial data via userdata as i was attempting? i basically would just like to know the shape's original vertices locations and i think i may be making this harder than it needs to be.
The shape should be keeping its original vertices, so you could do like you did in your first code snippet without the b2Mul.
Good point. I just tried that and the untransformed coordinates are way too small - I think what I need is actually the initial *transformed* coordinates 🙄

I don't think box2d remembers body's initial xf's, so I'm gonna try saving the them in a std vector thingy...

Original thread: https://box2d.org/forum/viewtopic.php?t=3927