Important: Please read the Qt Code of Conduct -

QGraphicsScene QPainterPath::arcTo: Adding arc where a parameter is NaN, results are undefined

  • Hello,

    I just started out with QT and have a problem that I can't seem to solve.
    I'm working on Nine Men's Morris and the everything works great, except for a strange bug that creeps up.

    Sometimes, when I click on a Item the GraphicsView turns white and the following error is shown several times in the debug window:

    QPainterPath::arcTo: Adding arc where a parameter is NaN, results are undefined

    The GraphicsView cannot be recovered by resizing, etc., only by restarting the game.

    I've created a MainWindow and with a QGraphicsView and a QGraphicsScene.

    I created 3 seperate QGraphicsItems

    1. A boardLayout which renders the background and does not handle click events.
    2. A Token Item that handles click events, the color of the token, if it's selected, etc.
    3. A BoardPosition Item that is invisible and handles the events when you click on an empty position on the board. Clicking this item causes the error described above.

    MainWindow Code:

    showWin = new WinDialog(this);
    startWindow = new StartDialog(this);
    view = new QGraphicsView(this);
    this->setCentralWidget (view);
    view->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
    view->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
    view->setMinimumSize (1000, 800);
    view->setViewportUpdateMode (QGraphicsView::FullViewportUpdate);
    view->setCacheMode (QGraphicsView::CacheNone);
    view->setRenderHints (QPainter::Antialiasing |  QPainter::TextAntialiasing);
    scene = NULL;
    //this->debugWidget = new DebugWidget(this);
    //this->debugWidget->setMinimumWidth (200);
    this->layout = NULL;
    this->controller = NULL;
    this->whiteTokensSet = 0;
    this->blackTokensSet = 0;


    void MainWindow::Initalize()
    scene = new QGraphicsScene();
    scene->setBackgroundBrush (QBrush(Qt::gray));
    view->setScene (scene);
    this->layout = new BoardLayout();

    float x = 0.081f;
    float y = 0.025f;
    for(int i = 0; i < 7; i++)
        text.append(scene->addText(QString('A'+i)));>setX(x+(i*0.13));>setY(y - 0.008);>setScale(0.003);
    x = 0.072f;
    for(int i = 7; i < 14; i++)
    this->controller = new GameController(this);
    view->fitInView (layout, Qt::KeepAspectRatio);
    points[0] = QPointF(0.085f, 0.085f);
    points[1] = QPointF(0.475f, 0.085f);
    points[2] = QPointF(0.865f, 0.085f);
    points[3] = QPointF(0.215f, 0.215f);
    points[4] = QPointF(0.475f, 0.215f);
    points[5] = QPointF(0.735f, 0.215f);
    points[6] = QPointF(0.345f, 0.345f);
    points[7] = QPointF(0.475f, 0.345f);
    points[8] = QPointF(0.605f, 0.345f);
    points[9] = QPointF(0.085f, 0.475f);
    points[10] = QPointF(0.215f, 0.475f);
    points[11] = QPointF(0.345f, 0.475f);
    points[12] = QPointF(0.605f, 0.475f);
    points[13] = QPointF(0.735f, 0.475f);
    points[14] = QPointF(0.865f, 0.475f);
    points[15] = QPointF(0.345f, 0.605f);
    points[16] = QPointF(0.475f, 0.605f);
    points[17] = QPointF(0.605f, 0.605f);
    points[18] = QPointF(0.215f, 0.735f);
    points[19] = QPointF(0.475f, 0.735f);
    points[20] = QPointF(0.735f, 0.735f);
    points[21] = QPointF(0.085f, 0.865f);
    points[22] = QPointF(0.475f, 0.865f);
    points[23] = QPointF(0.865f, 0.865f);
    for(int i = 0; i < 24; i++)
        boardPositions.append (new BoardPosition(i, points[i].x(), points[i].y(), this->controller));
        this->scene->addItem( (i));
    whiteTokensSet = 0;
    blackTokensSet = 0;
    for(int i = 0; i < 9; i++)
        whiteTokens.append(new GameToken(WHITE, this->controller));>setVisible(false);
        blackTokens.append(new GameToken(BLACK, this->controller));>setVisible(false);
    this->startWindow->close ();
    //this->debugWidget->appendText(QString("Welcome to Nine Men's Morris!"));
    //this->addDockWidget(Qt::LeftDockWidgetArea, this->debugWidget);
    this->resize(QSize(1001, 801));

    BoardPositions Code:
    #include "boardposition.h"
    #include "gamecontroller.h"

    BoardPosition::BoardPosition(int pos, float coordx, float coordy, GameController *controller) :
    boardPos = pos;
    posx = coordx;
    posy = coordy;
    this->controller = controller;

    QRectF BoardPosition::boundingRect() const
    return QRectF(posx, posy, 0.05, 0.05);

    void BoardPosition::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
    QWidget *widget)

    painter->drawRect(QRectF(posx, posy, 0.05, 0.05));


    void BoardPosition::mousePressEvent(QGraphicsSceneMouseEvent *event)


    How could I debug this error, or did I do something entirely wrong?

    Please let me know if you need any other information. (You can cownload the whole code here: )

  • welcome to devnet

    What OS, compiler, IDE, etc are you using?
    When you are running the application in the debugger, are you getting an exception?

  • Thanks!

    I'm using Ubuntu 12.04 x64, Qt-Creator and the gcc that comes with latest ubuntu (4.6 I believe)

    However the same occurs when using Windows7 with Qt-Creator and Visual C++ compiler.

    I don't get any exceptions.

  • Since you do not get exceptions, how do you know that you are introducing nan then?

Log in to reply