2012-12-12 4 views
0

.tga 리더를 쓰고 있습니다. 나는 완벽하게 헤더를 읽을 수 있고, 그 후 나는 파일의 데이터 부분을 읽고 싶지만, 내가 거기에 도착하면 그것은 나에게 오류가 있습니다 : 파일의 길이는 65580 C++ - .tga 파일을 읽는 중 위치를 읽는 중 액세스 위반이 발생했습니다.

Unhandled exception at 0x76ffa2ce in TGALoader.exe 0xC0000005: Access violation reading location 0xffff0008 

입니다

을, 그리고 18 bytes 길이 헤더 다음에 65536을 읽으십시오.

내 현재 코드입니다 (나는 비 중요한 부분을 잘라) : 나는 문제가 될 수있는 것을 상상할 수 없다

// Texture variables  
GLint bitsPP; 
GLsizei width; 
GLsizei height; 
GLubyte *imgData; 
///////////////////////////////////////////////// 

file.seekg(0, std::ios::end); 
std::cout << file.tellg() << "\n"; // 65580 
file.seekg(0, std::ios::beg); 

file.read((char*)&tGAHeader, sizeof(tGAHeader)); 

texture->width = tGAHeader[13] * 256 + tGAHeader[12]; 
texture->height = tGAHeader[15] * 256 + tGAHeader[14]; 
texture->bitsPP = tGAHeader[16]; 

short bytesPP = texture->bitsPP/8; // 4 
unsigned int imgSize = texture->width * texture->height * bytesPP; // 65536 

texture->imgData = new GLubyte[imgSize]; 

file.read((char*)&texture->imgData, imgSize); // Access violation reading location 

을, 그래서 나는 누군가가 나를 도울 수 있기를 바랍니다.

미리 감사드립니다.

답변

3

file.read((char*)texture->imgData, imgSize) 

texture->imgData 단지 포인터가로 변경

file.read((char*)&texture->imgData, imgSize) 

, 그것은

+0

가 대단히 감사합니다 두 번째 간접 레벨을 사용하지 마십시오! 나는 거의 모든 것을 시도했지만 이것이 결코 문제가 될 수 없다고 생각하지는 않았습니다. – matthew3r

관련 문제