このコードを実行すると、次のランタイム エラーが発生しました。
void AlienShipManager::Update(float timeDelta,
BulletManager* bulletManager,
ParticleManager* particleManager,
GameStringSystem* stringBatch)
{
unsigned int i = 0;
while (i < m_alienShipList.size())
{
AlienResult result = m_alienShipList[i].Update(timeDelta, bulletManager);
switch (result)
{
case AlienResult::Dead:
break;
default:
break;
}
++i
}
}
列をなして
AlienResult result = m_alienShipList[i].Update(timeDelta, bulletManager);
AlienShip を vector クラスに追加する方法は次のとおりです。
m_alienShipList.push_back(AlienShip(position, speed, m_screeSize, m_alienShipTexture));
次のような場合にもエラーが発生します。
AlienShip* newAlien = new AlienShip(position, speed, m_screeSize, m_alienShipTexture);
m_alienShipList.push_back(*newAlien);
delete newAlien;
しかし、それを次のように変更すると表示されません:
AlienShip* newAlien = new AlienShip(position, speed, m_screeSize, m_alienShipTexture);
m_alienShipList.push_back(*newAlien);
そのため、大量のメモリ リークが発生します。
これは、私の AlienShip クラスの外観です。
#pragma once
#include "Body.h"
#include "BulletManager.h"
#include "ParticleManager.h"
enum AliensShipState
{
flying,
dying,
dead,
escaped
};
enum AlienResult
{
No,
Hit,
Dying,
Dead,
Escaped
};
class AlienShip : public Body
{
public:
AlienShip(void);
AlienShip(float2& position, float2& speed, float2* screenSize, ID3D11Texture2D* alienTexture);
~AlienShip(void);
AlienResult Update(float timeDelta, BulletManager* bulletManager);
void Draw(BasicSprites::SpriteBatch^ spriteBatch);
protected:
float m_baseY;
AliensShipState m_state;
float2* m_screenSize;
};
AlienShip クラスは、内部に別のベクトルを持つ Sprite クラスを持つ Body クラスから継承されます。しかし、Sprite クラスは別の場所で問題なく動作しているため、エラーの原因ではないと思います。
一時オブジェクトの削除とベクトル反復子の破損との関係が見つからないため、なぜこれが起こるのだろうか。
また、プログラムはリリースでコンパイルおよび実行されますが、一部のデータが破損しています。
Windows 8 用の Visual Studio 2012 Beta を使用しています。
さらにソースコードが必要な場合は書いてください。残念ながら、これは複雑なプログラムであるため、すべてのコードを投稿することは非常に困難です。