如何修复此错误读取位置0x00000008时发生访问冲突
How can I fix this error Access violation reading location 0x00000008
在0x00814477处的第一次机会异常。仅限一次。exe:0xC0000005:读取位置0x00000008的访问冲突。0x00814477处未处理的异常,仅限一次。exe:0xC0000005:读取位置0x00000008时发生访问冲突。
//我相信这与NULL和操作系统有关,但我不确定如何修复这个
GameObject::GameObject()
{
sprite = NULL;
pos.x = 0; pos.y = 0;
vel.x = 0; vel.y = 0;
framenum = 0;
numframes = 0;
}
GameObject::~GameObject()
{
if ( sprite != NULL )
SDL_FreeSurface( sprite );
}
void GameObject::LoadImage(std::string filename)
{
sprite = IMG_Load( filename.c_str() );
//clip.x = 0;
//clip.y = 0;
clip.w = sprite->w; //It breaks here
clip.h = sprite->h; // and here
}
此函数调用:
sprite = IMG_Load( filename.c_str() );
很可能返回NULL
。您应该查看相关文档以了解原因,并更正相关错误。
Sprite似乎为null。检查IMG_Load的返回情况。很可能你的文件名不正确。
相关文章:
- 写入位置0x0000000C时发生访问冲突
- 引发异常:读取访问冲突**dynamicArray**为0x1118235.发生
- 链表中写入访问冲突的未知原因
- C++中的openCV Mat访问冲突
- C++尝试深度复制唯一指针时出现内存访问冲突
- C++ 中动态二维数组的访问冲突
- 从嵌套循环中的 std::list 中删除将返回访问冲突
- 写入访问冲突异常
- 在类 12.exe 中0x7B37FF80 (ucrtbased.dll) 引发异常: 0xC0000005:访问冲突读
- 0xC0000005:访问冲突写入位置0xCDCDCDCD动态分配错误
- 读取访问冲突.这0xCDCDCDCD
- 0xC0000005:访问冲突读取位置 0x00000000. 重载 == 运算符的问题
- 插入数组时违反写访问冲突
- 使用 ReadProcessMemory 获取字符串值的访问冲突
- 尝试通过共享指针使用变量时读取访问冲突
- 堆栈上的 C++ 访问冲突写入异常
- 引发异常:写访问冲突. temp 为 nullptr
- 将静态字符数组中的字符分配给动态分配的字符数组 - 访问冲突
- 如何修复此错误读取位置0x00000008时发生访问冲突
- 0xC0000005:访问冲突读取位置0x00000008