Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

About constant reference

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
No replies to this topic

#1 bluepig.man   Members   

424
Like
0Likes
Like

Posted 03 May 2013 - 06:09 AM

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[i]; }

	// Returns the solution normal at the ith grid point.
	const XMFLOAT3& Normal(int i)const { return mNormals[i]; }

	// Returns the unit tangent vector at the ith grid point in the local x-axis direction.
	const XMFLOAT3 TangentX(int i)const { return mTangentX[i]; }

	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[i].Pos    = mWaves[i];
	v[i].Normal = mWaves.Normal(i);
}

md3dImmediateContext->Unmap(mWavesVB, 0);

 

l know the problem is happened in this sentences:

v[i].Normal = mWaves.Normal(i);

Function Normal's value can't assignment to v[i].Normal.

 

but the things really bother me is,when the Normal's definition changed into:

 

const XMFLOAT3 Normal(int i)const { return mNormals[i]; }

 

Then the project suddenly work well. It‘s just like some magical power.it's So odd.

 






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.