Sign in to follow this  
bbr125

D3DXMatrixReflect

Recommended Posts

What is wrong with the following code?


D3DXPLANE mirrorPlane(0.0f, 0.0f, 1.0f, 0.0f); // xy plane
D3DXMATRIX R;
D3DXMatrixReflect(&R, &mirrorPlane);



When I run the program, it crashes constantly due to the D3DXMatrixReflect call. When I use the debugger, it gives the error:

Unhandled exception at 0x6366b9b6 (D3DX10d_43.dll) in dX.exe: 0xC0000005: Access violation reading location 0xffffffff.

At the top of the call stack, the yellow arrow is pointing to:

> D3DX10d_43.dll!intelsse2_D3DXMatrixReflect() + 0x22 bytes

The program crashes maybe half of the time I try to run it. What is wrong?

Share this post


Link to post
Share on other sites
possible reasons is
invalid D3DXMatrix alignement[you use custom allocator?]
wrong dll version or sdk mixup
it could be some fatal error in ur code that ruins stack position and point to the wrong error

try disabling SSE extension for D3DX math library

Share this post


Link to post
Share on other sites
Quote:
Original post by e3d_ALiVE
possible reasons is
invalid D3DXMatrix alignement[you use custom allocator?]
Alignment doesn't matter, the D3DX library just won't use the SSE2 version if it's not aligned.

Quote:
Original post by e3d_ALiVE
wrong dll version or sdk mixup
it could be some fatal error in ur code that ruins stack position and point to the wrong error
I think that's most likely, especially if it crashes half the time - I'd guess stack corruption.

Quote:
Original post by Scoob Droolins
You're reflecting the matrix R about the plane mirrorPlane, resulting in reflected matrix R'. So R must be a valid matrix.
No, D3DXMatrixReflect generates a matrix, it doesn't modify the input matrix (And even if it did, that wouldn't cause an access violation).

Share this post


Link to post
Share on other sites
It doesn't happen when I link d3dx10.lib, only when I link d3dx10d.lib. I tested it over 100 times and it never crashed once when using d3dx10.lib.

Does this mean there is a problem with the dll?

Share this post


Link to post
Share on other sites
Let me clarify - you have to initialize the matrix R with valid values. The output (reflected version of R) is assigned to another matrix, like this:

D3DXPLANE mirrorPlane(0.0f, 0.0f, 1.0f, 0.0f); // xy plane
D3DXMATRIX R (1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);

D3DXMATRIX Rp = D3DXMatrixReflect(&R, &mirrorPlane);

Share this post


Link to post
Share on other sites
Quote:
Original post by Scoob Droolins
Let me clarify - you have to initialize the matrix R with valid values. The output (reflected version of R) is assigned to another matrix...
That's not what the documentation says:
Quote:
D3DXMatrixReflect
Builds a matrix that reflects the coordinate system about a plane.

Parameters
pOut
[in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.

[snip]


P = normalize(Plane);

-2 * P.a * P.a + 1 -2 * P.b * P.a -2 * P.c * P.a 0
-2 * P.a * P.b -2 * P.b * P.b + 1 -2 * P.c * P.b 0
-2 * P.a * P.c -2 * P.b * P.c -2 * P.c * P.c + 1 0
-2 * P.a * P.d -2 * P.b * P.d -2 * P.c * P.d 1

Share this post


Link to post
Share on other sites
Quote:
Original post by Scoob Droolins
Let me clarify - you have to initialize the matrix R with valid values. The output (reflected version of R) is assigned to another matrix, like this:

D3DXPLANE mirrorPlane(0.0f, 0.0f, 1.0f, 0.0f); // xy plane
D3DXMATRIX R (1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);

D3DXMATRIX Rp = D3DXMatrixReflect(&R, &mirrorPlane);


Even with your code change (only changing line 3 to a pointer), the problem still occurs. So I'm not sure it is relevant to this particular problem.

The (temporary) fix is to use the release version of the library and not the debug version. But the mystery remains as to why it happens when using the debug version of the library, and if it is only happening on my machine.

Share this post


Link to post
Share on other sites
[color="#333333"][color="#333333"]I have the same problem on my machine[/color][/color]

[color="#333333"] I have the latest SDK (June 2010) and D3DXMatrixReflect crashes with d3dx10d.lib BUT doesn't crash with d3dx10.lib....[/color]
[color=#333333]I have tried to re-install the SDK but I have the same problem[/color]

[color="#333333"]I have written my own function in order to fix the problem:[/color]

[color="#333333"][code]
D3DXMATRIX* D3DXMatrixReflect_Fixed(__inout D3DXMATRIX *pOut, __in const D3DXPLANE *pPlane)
{
D3DXPLANE P;
D3DXPlaneNormalize(&P,pPlane);

*pOut = D3DXMATRIX
(
-2.0f * P.a * P.a + 1.0f, -2.0f * P.b * P.a , -2.0f * P.c * P.a , 0.0f ,
-2.0f * P.a * P.b , -2.0f * P.b * P.b + 1.0f , -2.0f * P.c * P.b , 0.0f ,
-2.0f * P.a * P.c , -2.0f * P.b * P.c , -2.0f * P.c * P.c + 1.0f , 0.0f ,
-2.0f * P.a * P.d , -2.0f * P.b * P.d , -2.0f * P.c * P.d , 1.0f
);

return pOut;
}[/color]
[color="#333333"][/code][/color]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this