访问冲突写入位置0x000001C0

时间:2013-12-30 23:32:30

标签: c++ visual-c++ cocos2d-x

我正在研究这个问题并且遇到了一个我无法解决的问题。

我在标题

中得到了这个
class PGEnemy : Public CCSprite
{
private:

    int pHP;
    int pLoot;
    int pAttack;
    int pSpeed;

    PGEnemy();
    ~PGEnemy();

public:

    bool setSpeed (int speed);

    static PGEnemy* factory(eType type); //create an enemy
    void init(int type); //read info from json (json cpp)

};

在代码中我得到了这个

void PGEnemy::init(int type)
{

    try
    {
    Reader reader;
    Value initial;
    unsigned long size = 0;

    unsigned char *config_doc = CCFileUtils::sharedFileUtils()->getFileData("enemy.json", "r", &size);

    bool parsingSuccessful = reader.parse((char*)config_doc, initial);

    string s = TO_STRING(type);

    cout << s << endl;

    if(parsingSuccessful)
    {
        this->pHP = initial[TO_STRING(type)]["hp"].asInt();
        this->pLoot = initial[TO_STRING(type)]["loot"].asInt();
        this->pAttack = initial[TO_STRING(type)]["attack"].asInt();
        this->pSpeed = initial[TO_STRING(type)]["speed"].asInt();
    }
    }
    catch (exception)
    {


    this->pHP = 100*type;
    this->pAttack = 100*type;
    this->pSpeed = 100*type;
    this->pLoot = 100*type;


    }
    //*/
}

在做this->pHP = initial[TO_STRING(type)]["hp"].asInt();的那一刻 或者我将在这些整数中放置一个值的任何其他东西(即使在catch中),它会因错误而崩溃

  

Access violation writing location 0x000001C0.

来自使用json的开源代码,文件Json_value.cpp

Value::asInt() const
{
   switch ( type_ )
   {
   case nullValue:
      return 0;
   case intValue:
      JSON_ASSERT_MESSAGE( value_.int_ >= minInt  &&  value_.int_ <= maxInt, "unsigned integer out of signed int range" );
      return Int(value_.int_);
   case uintValue:
      JSON_ASSERT_MESSAGE( value_.uint_ <= UInt(maxInt), "unsigned integer out of signed int range" );
      return Int(value_.uint_);
   case realValue:
      JSON_ASSERT_MESSAGE( value_.real_ >= minInt  &&  value_.real_ <= maxInt, "Real out of signed integer range" );
      return Int( value_.real_ );
   case booleanValue:
      return value_.bool_ ? 1 : 0;
   case stringValue:
   case arrayValue:
   case objectValue:
      JSON_FAIL_MESSAGE( "Type is not convertible to int" );
   default:
      JSON_ASSERT_UNREACHABLE;
   }
   return 0; // unreachable;
}

最“不知道”的是,当我只是尝试this->pHP = anyIntegerValue

时,错误也发生了
PGEnemy* PGEnemy::factory(eType type)
{
    PGEnemy* enemy = (PGEnemy*)CCSprite::create("Target.png");
    enemy->init(type);
    return enemy;
}

0 个答案:

没有答案
相关问题