Question

I have this very annoying issue, whenever i call a function:

void renderGame::renderMovingBlock(movingBlock* blockToRender){
    sf::Shape blockPolygon;
    sf::Shape blockLine = sf::Shape::Line(blockToRender->getLineBegin().x,blockToRender->getLineBegin().y,blockToRender->getLineEnd().x,blockToRender->getLineEnd().y, 3.f,movingBlockLineColor);

    for(auto i = blockToRender->getVertexArray()->begin(); i!=blockToRender->getVertexArray()->end(); ++i){
        blockPolygon.AddPoint(i->x, i->y,  movingBlockBlockColor);
    }

    renderToWindow->Draw(blockLine);
    renderToWindow->Draw(blockPolygon);
}

Which is a simple function, it takes a pointer to an object and uses SFML to render it on the screen. It's a simple polygon that moves on a rail.

getVertexArray() returns a pointer to the object's vector of vertices, renderToWindow is a pointer to sf::RenderWindow

The very weird issue i have is that i can call this function it won't return from it, VC++ breaks and points me to:

int __cdecl atexit (
        _PVFV func
        )
{
        return (_onexit((_onexit_t)func) == NULL) ? -1 : 0;
}

I'm getting weird behavoir here, i can stop this function right before exiting by calling the Display() function and system("pause"), it'll display everything perfectly fine, but one step further and it breaks.

I'll add that i'm sending a dynamically allocated object, when i set a regular one everything's fine. It's weird, when i debug the program then the polygon and line have the right coordinates, everything displays properly, but it just can't return from the function.

Was it helpful?

Solution

If a function will not return sounds like you messed up the stack somewhere previously - this is most likely an out-of-bounds write.

Or possibly because you are ending up in atexit there could have been an uncaught exception thrown.

Either way - welcome to the joys of programming - now you have to find an error which probably happens long before your function gets stuck

You could try some tools like valgrind (if its available for windows) or some other bounds checkers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top