Funny bug

Well today I had funny bug debugging my code :





The code I was debugging looks like this (it's code that I cleaning right now) :

//////////////////////////////////////////////////////////////////////////
void CGuiShapeEditor::flushHandlers( void )
{
    bool resetSelection = (m_handlers.size() != m_shape->getPointsCount());
 
    m_handlers.resize(m_shape->getPointsCount());
 
    for (uint32 i=0; igetPointsCount(); ++i)
    {
        SHandler& handle = m_handlers[i];
 
        handle.idx = i;
        handle.point = handle.pointBase = m_backgroundRect.topLeft()+QPointF(m_shape->getPoint(i).x*m_backgroundRect.width(), m_shape->getPoint(i).y*m_backgroundRect.height());
 
        setHandlerSelect(handle, resetSelection ? false : handle.select);
    }
}
 
//////////////////////////////////////////////////////////////////////////
void CGuiShapeEditor::setHandlerSelect(SHandler& a_handler, bool state)
{
    SelectedVec::Iterator it=qFind(m_selected.begin(), m_selected.end(), a_handler.idx);
 
    bool selected = (it != m_selected.end());
 
    if (selected != state)
    {
        if (state)
        {
#           m_selected.push_back(a_handler.idx);
        }
        else
        {
            *it = m_selected.back();
            m_selected.pop_back();
        } 
 
        a_handler.select = state;
    }
 
    flushHandler(a_handler);
}

So nothing special. My debugger was where # is. Small change in watch windows show problem:


Bug is really easy to fix because it was uninitialized variable. But anyway this logic is funny:

(true != true) == true.



Comments

Popular posts from this blog

Query commands execution

W.U. 0x20

Lets play : Good code / Bad code