2016-05-17 15 views
-3

変数をd.dwellerModelのmy loadDweller()関数に格納しようとすると、このエラーが発生します。私は '// Error'という行をマークしました。このコードではこれまでのようなエラーは発生していませんが、このコードを変更していないため、クラス定義のヘッダー/コード(以下に含まれています)の一部を変更したと仮定しています。与えられた助言/助けを前もって感謝します!BunkerBuilder.exeの0x0070C75Cのファーストチャンス例外:0xC0000005:アクセス違反の書き込み場所0xCCCCCC04

エラーがスローされた機能:

class dweller 
{ 
public: 
dweller(); 
//private:   //Make the following variables private once all direct access has been changed over to function access 
string firstName; 
string lastName; 

bool isMale;   //true = NPC is male, false = NPC is female 
var::coord2 pos;  //The NPC's position 

//bool hasJob;   //If the NPC has a job 
string jobType;   //What the NPC's job is 
int machine;   //The vector ID of the machine the NPC is assigned to (in the map vector list) 

bool isSelected;  //Whether or not this NPC is selected by the player 

int maxHealth;   //The maximum health of the NPC 
int currHealth;   //The current health of the NPC 

int strength; 
int stamina; 
int agility; 
int intelligence; 

vector<item> inventory; 
float maxInvVolume;   //The maximum volume that the inventory can hold (the sum of the volumes in the inventory must be less than this) 

model dwellerModel; 

float armLURot;     //The current angle that the NPC's upper left arm is at 
float armLLRot;     //The current angle that the NPC's lower left arm is at 
float armRURot;     //The current angle that the NPC's upper right arm is at 
float armRLRot;     //The current angle that the NPC's lower right arm is at 
var::coord2 toolPosOnHand;  //The coordinates that the tool should be centered at on the 'dominantHand' model_segment 

model_segment* dominantHand; //A pointer to the hand that single-handed items will be assigned to 
model_segment* nonDominantHand; //A pointer to the hand that the secondary position of two-handed items will be assigned to 
model_segment* itemLoc;   //A pointer to the model of the item that has been assigned to the dominant hand 
bool holdingItem; 
item heldItem; 

public: 

void draw();   
void update(); 
bool setInvVolMax(float _maxVol); 
float getInvVolMax(); 
bool addToInventory(item _item); 
bool removeFromInventory(int inventoryID); //Removes the item at 'inventoryID' in the 'inventory' vector 
bool equipItem(item _item); 
bool equipItem(int inventoryID); //Equips the item at 'inventoryID' in the 'inventory' vector 
bool unequipItem(); 
void setGender(bool isMale); 
void setGender(string gender); //Male or Female 
void executeTask(string _task); 
void executeTask(string _task, var::coord2 _pos); 
void executeTask(string _task, var::coord2 _pos, block _target); 
void executeTask(string _task, var::coord2 _pos, item _target); 
void executeTask(string _task, var::coord2 _pos, dweller _target); 
void executeTaskEffect(string _effect); 
}; 

class model 
{ 
public: 
    model(); 

    model_segment root; 
    vector<anim_container> animations; 

    bool runAnimations = true; 
    void draw(var::coord2 position, float rotation); 
    void update(); 

    void newAnimation(); 
    void newAnimation(anim_container anim); 

    void updateAnimation(); 
    void updateAnimation(vector<anim_container> *animations); 
    void initializeAnimation(); 
    void initializeAnimation(vector<anim_container> *animations); 

    void debugTree();    //Prints a tree diagram of the model 
}; 

model::model() 
{ 
    //app::console(); 
} 

model getModelTemplate(int ID) //Returns the template model from the master list at "ID". Defaults to an empty model class if the supplied ID is not defined. 
    { 
     if(ID < models.size()) 
     { 
      return models[ID]; 
     } 
     else 
     { 
      _DEBUG_ERROR("The requested template does not exist"); 
      return model(); 
     } 
    } 

のセクション:

dweller loadDweller() 
{ 
    dweller d; 
    do 
    { 
     string temp = strIn; 
     lineIn(); 
     temp = strIn; 
     int lNum(currLine); 
     if(checkOperator(strIn, "fName:"))   //first name 
     { 
      d.firstName = getRemainder(strIn, "fName:"); 
     } 
     else if(checkOperator(strIn, "lName:"))   //Last name 
     { 
      d.lastName = getRemainder(strIn, "lName:"); 
     } 
     else if(checkOperator(strIn, "pos["))   //Position 
     { 
      d.pos = loadCoord2(); 
     } 
     else if(checkOperator(strIn, "jobType:"))  //Job type/job 
     { 
      d.jobType = getRemainder(strIn, "jobType"); 
     } 
     else if(checkOperator(strIn, "jobPos:"))  //job position 
     { 
      d.machine = numInp(strIn, "jobPos:"); 
     } 
     else if(checkOperator(strIn, "maxHealth:"))  //Maximum health 
     { 
      d.maxHealth = numInp(strIn, "maxHealth:"); 
     } 
     else if(checkOperator(strIn, "currHealth:")) //Current health 
     { 
      d.currHealth = numInp(strIn, "currHealth:"); 
     } 
     else if(checkOperator(strIn, "strength:"))  //Strength 
     { 
      d.strength = numInp(strIn, "strength:"); 
     } 
     else if(checkOperator(strIn, "stamina:"))  //Stamina 
     { 
      d.stamina = numInp(strIn, "stamina:"); 
     } 
     else if(checkOperator(strIn, "agility:"))  //Agility 
     { 
      d.agility = numInp(strIn, "agility:"); 
     } 
     else if(checkOperator(strIn, "intelligence:")) //Intelligence 
     { 
      d.intelligence = numInp(strIn, "intelligence:"); 
     } 
     else if(checkOperator(strIn, "modelRef:")) 
     { 
      model mod = masterList::getModelTemplate(numInp(strIn, "modelRef:"));  //Ensuring that the value can be returned [when debugging] 
      d.dwellerModel = model();  //Error //Ensuring that the variable can be set [when debugging] by setting it equal to a constructor of itself 
      d.dwellerModel = masterList::getModelTemplate(numInp(strIn, "modelRef:")); 
     } 
     else if(strIn == "model[")   //Model 
     { 
      d.dwellerModel = loadModel(); 
     } 
     else if(checkOperator("Gender:")) //Gender 
     { 
      d.setGender(getRemainder("Gender:")); 
     } 
     else if(strIn != "]") 
     { 
      _DEBUG_ERROR("Unknown operator!"); 
     } 
     else if((strIn != "]") && file.eof()) 
     { 
      _DEBUG_ERROR("Unexpected EOF"); 
      failed = true; 
      //return d; 
     } 
    } while(!checkOperator("]") && !file.eof()); 
    strIn = ""; 
    return d; 
} 

クラス(複数可)を定義.cppファイルのセクションクラスを定義する.hファイル:

class dweller 
{ 
public: 
    dweller(); 
    //private:   //Make the following variables private once all direct access has been changed over to function access 

    string firstName; 
    string lastName; 

    bool isMale;   //true = NPC is male, false = NPC is female 

    float movementSpeed; 

    var::coord2 pos;  //The NPC's position 

    //bool hasJob;   //If the NPC has a job 
    string jobType;   //What the NPC's job is 
    int machine;   //The vector ID of the machine the NPC is assigned to (in the map vector list) 

    bool isSelected;  //Whether or not this NPC is selected by the player 

    int maxHealth;   //The maximum health of the NPC 
    int currHealth;   //The current health of the NPC 

    int strength; 
    int stamina; 
    int agility; 
    int intelligence; 

    vector<item> inventory; 
    float maxInvVolume;   //The maximum volume that the inventory can hold (the sum of the volumes in the inventory must be less than this) 

    model dwellerModel; 

    float armLURot;     //The current angle that the NPC's upper left arm is at 
    float armLLRot;     //The current angle that the NPC's lower left arm is at 
    float armRURot;     //The current angle that the NPC's upper right arm is at 
    float armRLRot;     //The current angle that the NPC's lower right arm is at 

    var::coord2 toolPosOnHand;  //The coordinates that the tool should be centered at on the 'dominantHand' model_segment 

    model_segment* dominantHand; //A pointer to the hand that single-handed items will be assigned to 
    model_segment* nonDominantHand; //A pointer to the hand that the secondary position of two-handed items will be assigned to 
    model_segment* itemLoc;   //A pointer to the model of the item that has been assigned to the dominant hand 

    bool holdingItem; 
    item heldItem; 

public: 

    void draw(); 
    void update(); 
    bool setInvVolMax(float _maxVol); 
    float getInvVolMax(); 
    bool addToInventory(item _item); 
    bool removeFromInventory(int inventoryID); //Removes the item at 'inventoryID' in the 'inventory' vector 
    bool equipItem(item _item); 
    bool equipItem(int inventoryID); //Equips the item at 'inventoryID' in the 'inventory' vector 
    bool unequipItem(); 
    void setGender(bool isMale); 
    void setGender(string gender); //Male or Female 
    void executeTask(string _task, var::coord2 _pos); 
    void executeTask(string _task, var::coord2 _pos, block _target); 
    void executeTask(string _task, var::coord2 _pos, item _target); 
    //void executeTask(string _task, var::coord2 _pos, 
    void executeTaskEffect(string _effect); 
}; 

class model 
{ 
public: 
    model(); 

    model_segment root; 
    vector<anim_container> animations; 

    bool runAnimations = true; 
    void draw(var::coord2 position, float rotation); 
    void update(); 

    void newAnimation(); 
    void newAnimation(anim_container anim); 

    void updateAnimation(); 
    void updateAnimation(vector<anim_container> *animations); 
    void initializeAnimation(); 
    void initializeAnimation(vector<anim_container> *animations); 

    void debugTree(); 
}; 
+0

これは[小さなプログラムをデバッグする方法を学ぶ](http://ericlippert.com/2014/03/05/how-to-debug-small-programs/)に最適な機会です。デバッガをできるだけ早く適切に使用する方法を学ぶことを強くお勧めします。 –

+1

'0xCCCCCC04'は、初期化されていないスタックメモリを意味する魔法のデバッグコードである' 0xCCCCCCCC'に近いです。 http://stackoverflow.com/a/127404/487892 – drescherjm

+0

ポインタが初期化されていないスタック上のオブジェクトの内部にあるポインタを使用している可能性があります。 – drescherjm

答えて

0

class modelを、ヘッダファイルのcppファイルに定義しましたか?

そして、あなたは彼らに異なる(少なくともdwellerを:私は、CPPのバージョンのヘッダ・ファイルのバージョンでfloat movementSpeed;ではなく参照)に定義されていますか?

私はこれが少し危険だと思っています(あなたが少し控えめな表現を許せば)。

提案:cppファイルのdwellermodelの定義をクリアし、ヘッダーファイルをインクルードします。

p.s .:申し訳ありませんが、私の悪い英語です。

+0

気づいてくれてありがとう、私はそれをチェックしたと思った。私はいつも.cppファイルの中でクラスを定義し、それを.hファイルにミラーリングしました。これを行う/しない理由がありますか? (何かを何度も入力しなくてもいいですか?) –

+0

@Zachary D. - あなたは大歓迎です。はい、IMHOそれは悪い習慣です。あなたは何かを二度入力しなければならないので、しかし、あなたは** **必ず**同じ**を同じものを二度入力する** ** **ことが必要です。 – max66

+0

@ Zachary D. - あなたの問題は素晴らしい例です(IMHOでも):2つの場所でクラスを定義し、要素を1つだけ多く配置すると、コードが非同期になります。定義に互換性のあるコードの一部と、互換性のない定義を持つコードの別の部分があります。たとえば、あなたのコードの一部( 'movementSpeed'を知っているもの)は、' movementSpeed'を過ぎてメンバーを読み込もうとします(例: '敏捷性')。コードの他の部分'movementSpeed')が別の位置に書かれています(例では 'stamina')。 – max66

関連する問題