2017-11-20 4 views
0

내 생성자는 다음이다 (C++ lib 디렉토리에 대한 래퍼 만들기)System.AccessViolationException : '보호 된 메모리를 읽거나 쓰려고 시도했습니다.

ScaperEngine::ScaperEngine(GrabberType grabberType, bool timing) { 
    switch (grabberType) 
    { 
    case GrabberType::DepthSenseGrabber: 
     this->interface = new pcl::DepthSenseGrabber(""); 
     break; 
    default: 
     throw new std::exception("Grabber type wasn't chosen correctly"); 
     break; 
    } 
    executionPipeline = new ExecutionPipeline(); 
    executionPipeline->setTiming(timing); 
} 

그리고 내가 좋아하는 몇 가지 코드를 가지고 :

void ScaperEngine::StartPipeline() 
{ 
    IPCLNormalCalculator* normalCalculator = new PCLNormalCalculator(normalCalcMaxDepthChangeFactor, normalSmoothingSize); 
    executionPipeline->SetPCLNormalCalculator(normalCalculator); 

가장 이상한 것은 생성자에 executionPipeline를 구축하고 있다는 점이다 0x0000020ef385e830의 메모리에 그 위치를 저장하는 올바른 방법이지만, C# 관리 코드가 StartPipeline을 호출 할 때 executionPipeline 주소가 0xcdcdcdcdcdcdcdcd로 변경되고 Quick Watch에서 해당 변수에 대해 다음 텍스트가 나타납니다. <Unable to read memory>.

아무도 실마리가 있습니까?

감사합니다.

답변

0

표시되는 0xcdcdcdcdcdcdcdcd은 초기화되지 않은 힙 메모리를 나타내는 Visual Studio 디버거의 특별한 기능입니다. 보다 포괄적 인 코드 목록은 this StackOverflow question에서 얻을 수 있습니다. 간단히 말해서, C# 코드가 잘못된 개체에서 StartPipeline()을 호출하는 것처럼 보입니다. 예를 들어 포인터가 힙 메모리의 임의의 위치를 ​​가리 키도록 변경된 경우에 이런 일이 발생할 수 있습니다. C# 코드 (및 런타임)가 ScraperEngine 개체에 대한 포인터를 올바르게 저장하고 도중에 손상되지 않도록하십시오. 덕분에 많이,

+0

나는 대부분의 내가 {ScaperEngine (grabberType, 거짓을)} 다음 ScaperEngine :: ScaperEngine (GrabberType grabberType) 같은 ScaperEngine를 구성하고 있기 때문에, 문제를 발견 –