使用XMMatrix和std::vector的访问冲突

Access Violation using XMMatrix and std::vector

本文关键字:vector 访问冲突 std XMMatrix 使用      更新时间:2023-10-16

我目前在我的项目中遇到了一个问题,我正在尝试运行Dx11。

我的错误是:3DTestProject.exe中0x00FC266D处未处理的异常:0xC0000005:读取位置0x00000000时发生访问冲突。

崩溃发生在我的Model.cpp in Model::Render()中的以下行:
cb.mWorld = DirectX::XMMatrixTranspose(aOrientation);

由于实现的原因,我必须将其作为Render()中的常量引用发送

const DirectX::XMMATRIX& aOrientation

从实例调用
m_pModel->Update();

实例的标题如下:

class Instance 
{
public:
  Instance();
  Instance(Model* aModel);
  ~Instance();
  void Update();
  void Render(Camera* aCamera);
private:
  DirectX::XMMATRIX m_Orientation;
};

我的猜测是,这是因为我将实例存储在Scene.h中作为std::向量,但我不知道如何解决它。

std::vector<Instance> m_vecInstances;

在这一点上,更改这些行并使用XMFLOAT4X4似乎是可行的。

const DirectX::XMFLOAT4X4 aOrientation

cb.mWorld = DirectX::XMMatrixTranspose(XMLoadFloat4x4(&aOrientation));