读取字符串的字符错误 - VC ++

时间:2016-04-28 05:05:44

标签: pointers visual-c++ kinect

我得到了#34;错误读取字符串错误的字符"在运行时。它不是用try catch处理的,

void process(const BYTE* pBodyIndexBuffer){
m_pCoordinateMapper->MapCameraPointToDepthSpace(m_pJoints[JointType_ShoulderLeft].Position, &p);
            dx = static_cast<int>(p.X + 0.5);
            dy = static_cast<int>(p.Y + 0.5);
            try
            {
                if (p.X < 500 && p.X >= 0 && p.Y <= 410 && p.Y >= 0)
                {
                    pPoint = pBodyIndexBuffer[dx + (dy*cDepthWidth)];
                    while (1) {
                        if (pPoint == 0xff) break;
                        pPoint = pBodyIndexBuffer[dx + (dy * cDepthWidth)];
                        dx -= 1;
                        dy -= 1;
                        p.X -= 1;
                        p.Y -= 1;
                        OutputDebugString(L"Moved \n");

                    }
                }

                m_pBodyEdgeswidth[ShoulderLeft] = getDistance(m_pJoints[JointType_ShoulderLeft].Position, p, distance);
            }
            catch (const std::exception&)
            {
                OutputDebugString(L"Error Occured");
            }
}

我提供了部分代码。 这是我面临的问题,

enter image description here

请解释如何解决此问题。

但有时它会毫无错误地开始运行。 我的传球方式是,

BYTE *bodyIndex = NULL; 
cm->getBodyIndexStream(&bodyIndex);
if(bodyIndex) process(bodyIndex);

提前致谢。

1 个答案:

答案 0 :(得分:1)

您需要将有效的非空缓冲区传递给getBodyIndexStream。您正在传递null缓冲区,它满足编译器并且肯定会在运行时失败。它就像:

int* ptr = NULL;
// Set value
*ptr = 120; // crash