Today,l was met a strange problem.
l have a buffer called mWavesVB:
ID3D11Buffer* mWavesVB;
And a class called wave:
Waves mWaves;
The declaration like this:
class Waves
{
public:
Waves();
~Waves();
// Returns the solution at the ith grid point.
const XMFLOAT3& operator[](int i)const { return mCurrSolution; }
// Returns the solution normal at the ith grid point.
const XMFLOAT3& Normal(int i)const { return mNormals; }
// Returns the unit tangent vector at the ith grid point in the local x-axis direction.
const XMFLOAT3 TangentX(int i)const { return mTangentX; }
void Init(UINT m, UINT n, float dx, float dt, float speed, float damping);
private:
XMFLOAT3* mCurrSolution;
XMFLOAT3* mNormals;
XMFLOAT3* mTangentX;
};
The member variable all initialize and assgin the suitable value.
But when the following call happened,the project crashed:
D3D11_MAPPED_SUBRESOURCE mappedData;
md3dImmediateContext->Map(mWavesVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedData);
Vertex* v = reinterpret_cast<Vertex*>(mappedData.pData);
for(UINT i = 0; i < mWaves.VertexCount(); ++i)
{
v.Pos = mWaves;
v.Normal = mWaves.Normal(i);
}
md3dImmediateContext->Unmap(mWavesVB, 0);
l know the problem is happened in this sentences:
v.Normal = mWaves.Normal(i); Function Normal's value can't assignment to v.Normal.
but the things really bother me is,when the Normal's definition changed into:
const XMFLOAT3 Normal(int i)const { return mNormals; }
Then the project suddenly work well. It‘s just like some magical power.it's So odd.