我試圖建立谷歌的液體樂趣圖書館,但在使用mingw的窗戶上我得到了一個seg故障,我有點難住。編譯失敗的方法在mingw中編譯段錯誤,但在linux上不是gcc。
void b2ParticleSystem::CreateParticlesStrokeShapeForGroup(
const b2Shape *shape,
const b2ParticleGroupDef& groupDef, const b2Transform& xf)
{
float32 stride = groupDef.stride;
if (stride == 0)
{
stride = GetParticleStride();
}
float32 positionOnEdge = 0;
int32 childCount = shape->GetChildCount();
for (int32 childIndex = 0; childIndex < childCount; childIndex++)
{
b2EdgeShape edge;
if (shape->GetType() == b2Shape::e_edge)
{
edge = *(b2EdgeShape*) shape;
}
else
{
b2Assert(shape->GetType() == b2Shape::e_chain);
((b2ChainShape*) shape)->GetChildEdge(&edge, childIndex);
}
b2Vec2 d = edge.m_vertex2 - edge.m_vertex1;
float32 edgeLength = d.Length();
while (positionOnEdge < edgeLength)
{
b2Vec2 p = edge.m_vertex1 + positionOnEdge/edgeLength * d;
CreateParticleForGroup(groupDef, xf, p);
positionOnEdge += stride;
}
positionOnEdge -= edgeLength;
}
}
postionOnEdge + = stride;如果我發表評論說它會成功編譯,那麼會導致問題,但顯然會在運行時創建無限循環。對於爲什麼它只會在明行中導致seg故障,甚至將行更改爲positionOnEdge + = 0.0f,我都有點想法。導致它出現段錯誤。
編譯期間的任何崩潰都是一個編譯器錯誤。如果您將調用上方的'positionOnEdge + = stride'行移至'CreateParticleForGroup',會發生什麼情況? – 1201ProgramAlarm
感謝這個想法,不幸的是將它移動出來導致同樣的問題。我認爲這很可能是一個編譯器bug,因爲它在linux上可以正常工作。但我希望有人可以有一些工作。對我來說,看起來很奇怪,只有那條線導致了一個問題,因爲這是一個基本的操作。 – Ben
只是爲了好奇;將該行更改爲'b2Vec2 p = edge.m_vertex1 +(positionOnEdge * d)/ edgeLength;' – Loreto