c++ - "Access violation reading location 0x0000000c"错误

标签 c++

代码片段:

-将实例插入对象管理器

Object* o;
for(int i=0; i<10; i++) 
{
    o = new Tile(32*i, 0);
    o->ID = i+2;
    o_manager.Create(i+2,o);
}
o = new Player(50.,50.);
o->ID = 1;
o_manager.Create(1,o);

-将实例从管理器插入四叉树

CollisionDetector = new QuadTree(0, bounds);
for(std::map<unsigned int, Object*>::iterator it = Instances.begin(); it !=  Instances.end(); it++)
{
  std::cout << it->second->COL << std::endl;
  if(it->second->COL) //probable place of error
  {
     std::cout << "Object (" << it->first << ")... ";
     CollisionDetector->insert(it->second);
  }
  std::cout << "inserted into QuadTree" << std::endl;
}

我遇到了一个问题,我完全不知道其原因。我有一个对象管理器类,在其中放置了 11 个实例(放入 map 容器中)。然后,每一步都会将带有碰撞标志的实例传递给四叉树列表。

执行后,我收到错误:“访问冲突读取位置 0x0000000c”

根据我从标准输出获得的信息,将第 11 个实例插入四叉树时出现错误(标准输出打印标志值,但不打印“对象(ID)...”)。当我将实例数量减少到 10 个或更少时,一切正常。

如果有任何建议,我将不胜感激,因为我不知道在哪里可以找到解决方案。 抱歉我的英语不好,我不是母语人士。

最佳答案

“我有一个对象管理器类,我在其中放置了 11 个实例(到 map 容器中)。”

但这只是 10 个实例:

for(int i=0; i<10; i++) 

如果这不能解决您的问题,您应该发布更多代码。

关于c++ - "Access violation reading location 0x0000000c"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15682009/

相关文章:

c++ - 在unordered_map中存储大对象效率低吗?

c++ - #include <> 和 #include ""

c++ - 在常数时间内提取子 vector

c++ - 使用 addch 获得意想不到的字符

c++ - C++ 中是否有生产就绪的无锁队列或哈希实现

c++ - 高效安全地分配唯一 ID

c++ - 如何从 Bison 行动访问类(class)成员

c++ - 我在 Visual Studio 中运行一个 Qt C++ 项目并得到 "the program can not start because QtCored4.dll"is missing

c++ - 使用 QLineEdit 获取密码

c++ - 为什么我的 C++ 类不能使用 Qt?