[英]C++ - Access violation reading location while reading .tga file
I'm writing a .tga reader. 我正在写.tga阅读器。 I can read the header perfectly, and after that I would like to read the data part of the file, but if I get there it gives me the error: 我可以完美地读取标题,然后再读取文件的数据部分,但是如果到达该位置,则会出现错误:
Unhandled exception at 0x76ffa2ce in TGALoader.exe 0xC0000005: Access violation reading location 0xffff0008
The length of the file is 65580
, and I read 65536
after the 18 bytes
length header. 该文件的长度为65580
,在18 bytes
长的标头之后,我读取了65536
。
My current code is (I cut out the non important part): 我当前的代码是(我删去了不重要的部分):
// 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
I can't imagine what can be a problem, so I hope someone can help me. 我无法想象会有什么问题,所以希望有人能帮助我。
Thanks in advance! 提前致谢!
Change 更改
file.read( ( char* )&texture->imgData, imgSize )
by 通过
file.read( ( char* )texture->imgData, imgSize )
texture->imgData
is just a pointer, don't use it a second indirection level texture->imgData
只是一个指针,不要在第二个间接级别使用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.