断点当前不会被击中。没有debbuger的目标代码类型的可执行代码

时间:2017-01-30 07:27:59

标签: debugging visual-c++ directx-11

简介:代码在发布模式下无效。在Debug中工作。

这显示在我的一个断点上:

The breakpoint will not currently be hit. No executable code of the debbuger's target code type is

代码点是:

void Font::operator<<(std::string s)
{
    this->printf(s); // this line
}

此方法的调用如下:

float oneframe;
oneframe = (double)elapsed/ 1000000.0;

float ffps =1. / oneframe;
int fps = ffps;
char txt[200];
sprintf(txt, "%d FPS", fps);
font << txt; // displays text

Printf是:

void Font::printf(std::string s)
{
    UINT lines = 0;
    std::vector<float> offsetX;
    float offsetY=0;
    UINT length = s.size();
    XMMATRIX M = XMMatrixScaling(m_scaling.x, m_scaling.y, m_scaling.z)*
        XMMatrixTranslation(m_translation.x, m_translation.y, m_translation.z);
    float fontLength=0;
    float fontHeight = 60.0f / windowHeight;
    float fontWidth = 60.0f / windowWidth * 0.6f;

    m_deviceContext->VSSetShader(m_vertexShader, 0, 0);
    m_deviceContext->IASetInputLayout(m_inputLayout);
    m_deviceContext->PSSetShader(m_pixelShader, 0, 0);
    m_deviceContext->PSSetShaderResources(0, 1, &m_texture);
    m_deviceContext->PSSetSamplers(0, 1, &m_sampler);
    m_deviceContext->OMSetDepthStencilState(m_dsOff, 1);

    if (m_anchor != TOP_LEFT) 
    {
        float offset = 0;
        for (int i = 0; i < length; i++)
        {
            offset += m_kerning*widthMap[s[i]];
            if (s[i] == '\n' || s[i] == '\r' || i == length - 1)
            {
                offsetX.push_back(offset);
                offset = 0;
            }
        }
    }
    for (int i = 0; i < length; i++)
    {
        XMFLOAT3 TL(-1, 1, 0), BR(1, -1, 0);
        XMVECTOR vTL, vBR;
        if (s[i] == '\n' || s[i] == '\r')
        {
            fontLength = 0;
            lines++;
            continue;
        }
        switch (m_anchor)
        {
        default:
        case TOP_LEFT:
            vTL = XMVector3TransformCoord(XMLoadFloat3(&XMFLOAT3(fontLength, -m_leading*lines, 0)), M);
            vBR = XMVector3TransformCoord(XMLoadFloat3(&XMFLOAT3(fontWidth + fontLength, -m_leading*lines - fontHeight, 0)), M);
            break;
        case TOP_RIGHT:
            vTL = XMVector3TransformCoord(XMLoadFloat3(&XMFLOAT3(fontLength - offsetX[lines], -m_leading*lines, 0)), M);
            vBR = XMVector3TransformCoord(XMLoadFloat3(&XMFLOAT3(fontWidth + fontLength - offsetX[lines], -m_leading*lines - fontHeight, 0)), M);
            break;
        case BOTTOM_LEFT:
            offsetY = m_leading*offsetX.size();
            vTL = XMVector3TransformCoord(XMLoadFloat3(&XMFLOAT3(fontLength, -m_leading*lines+ offsetY, 0)), M);
            vBR = XMVector3TransformCoord(XMLoadFloat3(&XMFLOAT3(fontWidth + fontLength, -m_leading*lines - fontHeight+ offsetY, 0)), M);
            break;
        case BOTTOM_RIGHT:
            offsetY = m_leading*offsetX.size();
            vTL = XMVector3TransformCoord(XMLoadFloat3(&XMFLOAT3(fontLength - offsetX[lines], -m_leading*lines + offsetY, 0)), M);
            vBR = XMVector3TransformCoord(XMLoadFloat3(&XMFLOAT3(fontWidth + fontLength - offsetX[lines], -m_leading*lines - fontHeight + offsetY, 0)), M);
            break;
        case CENTER:
            {
                offsetY = m_leading*offsetX.size() / 2;
                float halfOffsetx = offsetX[lines] / 2;
                vTL = XMVector3TransformCoord(XMLoadFloat3(&XMFLOAT3(fontLength - halfOffsetx, -m_leading*lines + offsetY, 0)), M);
                vBR = XMVector3TransformCoord(XMLoadFloat3(&XMFLOAT3(fontWidth + fontLength - halfOffsetx, -m_leading*lines - fontHeight + offsetY, 0)), M);
                break; 
            }
        }
        XMStoreFloat3(&TL, vTL);
        XMStoreFloat3(&BR, vBR);
        assert(updateBuffer(TL, BR, fontMap[s[i]]));
        UINT stride, offset;
        stride = sizeof(SimpleVertex);
        offset = 0;
        m_deviceContext->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset);
        m_deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
        m_deviceContext->Draw(6, 0);
        fontLength += m_kerning*widthMap[s[i]];
    }
    m_deviceContext->OMSetDepthStencilState(m_dsOn, 1);
}

这是奇怪的地方。我在发布模式下收到此通知。上面的代码在Debug中完全有效。无论出于何种原因,当我切换到Release时它不起作用。我检查了发送给函数的txt变量,它有文本。对我而言,似乎代码已经以某种方式被优化或者其他东西。

我还删除了Debug和Release文件夹中的所有内容,并进行了全新的Build。没有。我已经测试了可执行文件而没有从VS运行,结果相同。 Release中的调试显示txt中有文本,但由于调试器似乎浮在font << txt上,我无法确定会发生什么。

1 个答案:

答案 0 :(得分:0)

我确实找到了答案。在结尾附近的printf中使用assert。断言不在Release中运行。仅在调试中。