访问冲突写入位置0xcccccccc [英] Access violation writing location 0xcccccccc

查看:365
本文介绍了访问冲突写入位置0xcccccccc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去两天,我一直被困在一个违法行为,我似乎不能离开。
我使用了断点和错误的位置,但我只是希望你的一个人会知道这个问题是没有我复制+粘贴所有的代码-.-

For the past 2 days I've been stuck on a violation which I can't seem to get to go away. I've used break points and located where the error is, but I'm just hoping one of you will know what the issue is without me having to copy+paste all my code -.-

我得到



第一次机会异常在0x1027cb1a msvcr100d.dll)在Escape.exe:0xC0000005:访问冲突写入位置0xcccccccc。
Escape.exe中的0x1027cb1a(msvcr100d.dll)未处理的异常:0xC0000005:访问冲突写入位置0xcccccccc。

First-chance exception at 0x1027cb1a (msvcr100d.dll) in Escape.exe: 0xC0000005: Access violation writing location 0xcccccccc. Unhandled exception at 0x1027cb1a (msvcr100d.dll) in Escape.exe: 0xC0000005: Access violation writing location 0xcccccccc.


现在,一个快速的google搜索让我认为有一些奇怪的事情。所有的搜索结果谈论指针实际上不指向任何地方(0xccccccccc是低内存地址?)。

Now, a quick google search makes me think there's something peculiar going on. All the search results talk about pointers not actually pointing anywhere (0xccccccccc is a low memory address?).

我还没有使用指针在我的代码, (粗体):

I'm yet to use pointers in my code but either way I'll paste the function and point out the line the exception gets thrown (in bold):

void mMap::fillMap(){
    for(int i = 0; i <= 9; i++){
        for(int z = 0; z <= 19; z++){
            Tile t1;    // default Tile Type = "NULLTILE"
            myMap[i][z] = t1;
        }
    }
}



现在myMap是一个2d数组类型Tile。我有几天前工作,直到我添加了一些其他类,它都停止工作!

Now myMap is a 2d array of type Tile. I had this working a couple of days ago until I added some other classes and it all stopped working!

推荐答案

一个未初始化的指针,或者存储在已经释放的存储器中的指针。我认为 cccccccc 是第一个, cdcdcdcd 是第二个,但它随编译器/库实现而变化。

Either an uninitialized pointer, or a pointer stored in memory that's been freed. I think cccccccc is the first and cdcdcdcd is the second, but it varies with compiler/library implementation.

对于您的特定代码,可能 myMap 尚未分配,则 myMap [0] [0] 将导致访问尝试 0xcccccccc

For your particular code, probably myMap hasn't been allocated yet, then myMap[0][0] would result in an access attempt to 0xcccccccc.

也可能发生 myMap 是类的开头,类指针未初始化:

It can also happen that myMap is the beginning of your class, and the class pointer was uninitialized:

class mMap
{
     Tile myMap[10][20];
public:
     void f() { myMap[0][0] = 0; }
};

mMap* what;
what->f(); // what is an invalid pointer

这是因为成员函数不是虚函数,什么代码运行和传递对象指针作为隐藏参数。最后,编译器发出一个计算,如:

This happens because the member function is not virtual, so the compiler knows what code to run and passes the object pointer as a hidden parameter. Eventually the compiler emits a calculation like:

this + offsetof(Whatever::myMap) + z * sizeof(myMap[0]) + i * sizeof(myMap[0][0])

,未初始化, 0xcccccccc 。显然, offsetof 部分为零, i z 通过你的循环第一次都是零,所以你得到 0xcccccccc + 0 + 0 + 0 作为内存地址。

this, being uninitialized, is 0xcccccccc. Evidently the offsetof part is zero, and i and z are both zero the first time through your loop, so you get 0xcccccccc + 0 + 0 + 0 as the memory address.

要调试这个,使用调用堆栈并找到调用 fillMap 的函数。然后检查那个用于成员访问( - > )的指针来自哪个函数。

To debug this, use the call stack and find the function that called fillMap. Then check in that function where the pointers used for member access (->) came from.

这篇关于访问冲突写入位置0xcccccccc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆