简体   繁体   中英

Compilation segmentation fault in mingw but not gcc on linux.

I'm trying to build google's liquid fun library, but on windows using mingw I'm getting a seg fault that I'm a little stumped on. Compilation fails in this method

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;
    }
}

The postionOnEdge += stride; line is what's causing issues if I comment that out it will compile successfully, but obviously would create an infinite loop when running. I've kind of run out of ideas as to why it would cause a seg fault only in mingw even changing the line to positionOnEdge += 0.0f; causes it to segfault.

Congratulations: you have found a bug in your compiler. No matter what your source code contains, a compiler should not crash with a segfault, itself.

Beyond formally reporting this bug, there's very little that can be done. You could try figuring out exactly what makes the compiler go off the rails to try to work your way around the bug, but this would be a guessing game, at best.

You claim you've isolated the compilation crash to:

positionOnEdge += stride;

Try changing the code, in some form or fashion. Maybe "positionOnEdge = positionOnEdge + stride;" will be palatable to the compiler. Maybe replacing it with a function call to some external function, passing both variables by reference and performing the addition in some external function, will do the trick.

And, of course, you can always check that you have the most recent and up-to-date version of the compiler. If not, upgrade, and hope that the current version of your compiler already fixed the bug.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM