Jump to content
  • Advertisement
Sign in to follow this  
Mumsfilibaba

"Assertion failed! Expression: !XMVector3Equal(UpDirection, XMVectorZero())"

This topic is 942 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

 

So I have run into an error that makes my program crash and I get the following error message: 

 

Assertion failed!
 
Program: ...min\Source\Workspaces\Engine\Debug\Application.exe
File: c:\program files (x86)\windows kits...\directx...rix.inl
Line: 1912
 
Expression: !XMVector3Equal(UpDirection, XMVectorZero())
 
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts
 
(Press Retry to debug the application - JIT must be enabled)
 
And I have no clue why. I did some chenges to the program:
-Changed my naming-style of functions in every class
-Enabled a debugging device
 
I have located the chrash to the following piece of code:
	DirectX::XMStoreFloat4x4(&this->viewMatrix, DirectX::XMMatrixLookToRH(this->position, this->lookAt, this->up));

The whole piece looks like this:

Camera::Camera(Vector3 position, Vector3 rotation, Vector3 up, float fieldOfViewAngle, int renderWidth, int renderHeight, float nearPlane, float farPlane)
{
	//initialize camera
	this->position = position;
	this->lookAt = Vector3(0.0f, 0.0f, 1.0f);
	this->up = up;
	this->rotation = rotation;
	this->viewMatrix = DirectX::XMFLOAT4X4();

	DirectX::XMStoreFloat4x4(&this->cameraRotationMatrix, DirectX::XMMatrixRotationRollPitchYawFromVector(this->rotation));

	//calculate new lookAt an up- vectors with camera rotation
	this->lookAt = DirectX::XMVector3TransformCoord(this->lookAt, DirectX::XMLoadFloat4x4(&cameraRotationMatrix));
	this->up = DirectX::XMVector3TransformCoord(this->up, DirectX::XMLoadFloat4x4(&cameraRotationMatrix));
	this->lookAt = DirectX::XMVectorAdd(this->position, this->lookAt);

	//create matrices
	DirectX::XMStoreFloat4x4(&this->viewMatrix, DirectX::XMMatrixLookToRH(this->position, this->lookAt, this->up));
	DirectX::XMStoreFloat4x4(&this->projectionMatrix, 
		DirectX::XMMatrixPerspectiveFovLH(fieldOfViewAngle, (float)renderWidth / (float)renderHeight, nearPlane, farPlane));
	DirectX::XMStoreFloat4x4(&this->orthographicMatrix,
		DirectX::XMMatrixOrthographicLH((float)renderWidth, (float)renderHeight, nearPlane, farPlane));
	DirectX::XMStoreFloat4x4(&this->cameraMatrix, DirectX::XMMatrixMultiply(DirectX::XMLoadFloat4x4(&this->viewMatrix), DirectX::XMLoadFloat4x4(&this->projectionMatrix)));
	DirectX::XMStoreFloat4x4(&this->cameraMatrix2D, DirectX::XMMatrixMultiply(DirectX::XMLoadFloat4x4(&this->viewMatrix), DirectX::XMLoadFloat4x4(&this->orthographicMatrix)));
	
	//transpose the matricies
	DirectX::XMStoreFloat4x4(&this->viewMatrix, DirectX::XMMatrixTranspose(DirectX::XMLoadFloat4x4(&this->viewMatrix)));
	DirectX::XMStoreFloat4x4(&this->projectionMatrix, DirectX::XMMatrixTranspose(DirectX::XMLoadFloat4x4(&this->projectionMatrix)));
	DirectX::XMStoreFloat4x4(&this->orthographicMatrix, DirectX::XMMatrixTranspose(DirectX::XMLoadFloat4x4(&this->orthographicMatrix)));
	DirectX::XMStoreFloat4x4(&this->cameraMatrix, DirectX::XMMatrixTranspose(DirectX::XMLoadFloat4x4(&this->cameraMatrix)));
	DirectX::XMStoreFloat4x4(&this->cameraMatrix2D, DirectX::XMMatrixTranspose(DirectX::XMLoadFloat4x4(&this->cameraMatrix2D)));
}

The vector3s are my own vector class and a cast them to a XMVECTOR like this:

Vector3::operator DirectX::XMVECTOR() const
{
	return DirectX::XMVectorSet(this->x, this->y, this->z, 1.0f);
}

Does anyone have any idea what I could have done wrong?

Edited by Mumsfilibaba

Share this post


Link to post
Share on other sites
Advertisement
I think that assert is saying "I don't want the up vector to be (0,0,0), but it is. :("

Somehow your up vector is becoming zero.

Some likely possibilities for how that's happening:
- You're setting it to zero somewhere, perhaps a typo.
- You're multiplying it with zero.
- You might be performing a cross-product on two parallel vectors (or a vector with itself via a typo).

Share this post


Link to post
Share on other sites
DirectX::XMStoreFloat4x4(&this->viewMatrix, DirectX::XMMatrixLookToRH(this->position, this->lookAt, this->up));
Change to:
DirectX::XMStoreFloat4x4(&this->viewMatrix, DirectX::XMMatrixLookToRH(this->position, this->lookAt, Vector3(0.0f, 1.0f, 0.0f)));

L. Spiro

Share this post


Link to post
Share on other sites

So I solved it. The problem were in the Vector2-class that is parent to the Vector3-class. The y value was set to the x value in the constructor.

Vector2::Vector2(float x, float y)
{
	this->x = x;
	this->y = y;
}

Vector3::Vector3(float x, float y, float z) 
	: Vector2(x, y)
{
	this->z = z;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!