Recent

Author Topic: Execution stopp with 331  (Read 6185 times)

SonnyBoyXXl

  • Jr. Member
  • **
  • Posts: 57
Execution stopp with 331
« on: October 10, 2021, 11:22:41 am »
I got an error in the DirectX.Math unit. Procedure XMMatrixRotationQuaternion used for the calculation of
XMMatrixRotationRollPitchYaw.

Funny thing: using XMMatrixRotationRollPitchYaw in a standalone program is working.
In the application it is not working.

Compiling the application with Delphi 10.4 works without any problems and application runs without erros.

What is stopp reason 331?

Maybe compiler issue?

SonnyBoyXXl

  • Jr. Member
  • **
  • Posts: 57
Re: Execution stopp with 331
« Reply #1 on: October 10, 2021, 11:11:48 pm »
Found the solution.
Just an issue with boundaries.   %)
compiling DirectX.Math with {$Z4} or {$Z8} did the magic.
Delphi has 8 byte boundaries as default.

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Execution stopp with 331
« Reply #2 on: October 11, 2021, 08:45:07 am »
Found the solution.
Just an issue with boundaries.   %)
compiling DirectX.Math with {$Z4} or {$Z8} did the magic.
Delphi has 8 byte boundaries as default.
If that really solved it, this should be added to DirectX.Math  as a compiler directive and a bug report would not be out of place.
The maintainer(s) will be grateful since it is such an easy fix.
(Although I wonder where the $Zx comes from: that only exists in Delphi, not FPC, I may still be sleepy, though) Sleepy indeed, Pack Enum size. Plz report as bug since this can be solved for the unit with just {$Z8}. But note it needs some testing, because it may not apply to each and every version. "Delphi" is also version dependent, just like FPC is. So plz always write which version you mean.
« Last Edit: October 11, 2021, 08:58:36 am by Thaddy »
Specialize a type, not a var.

SonnyBoyXXl

  • Jr. Member
  • **
  • Posts: 57
Re: Execution stopp with 331
« Reply #3 on: October 17, 2021, 01:00:58 pm »
Update: adding {$Z4} was only a temporary solutions.
Working further on the code, showing same problems again.
When I start the program the first time, it is working. Starting it a second time,
it fails in the DirectX.Math units.
A change in the aligment directive shows sometimes the effect that first start then works and the second start fails again.
After restart of the PC the first run works every time.

I will dig deeper inside the DirectX Math and also DirectX 12. Also I will analyse the *.s files.
Something is really strange. The same code in Delphi 10.4 works without any problems... %) :(

SonnyBoyXXl

  • Jr. Member
  • **
  • Posts: 57
Re: Execution stopp with 331
« Reply #4 on: October 27, 2021, 11:27:02 pm »
I was diging through a bunch of source codes sind 2012.
Something goes realy strange here...
In the D3DX10 library there is this function:
Code: C  [Select][+][-]
  1. D3DXVECTOR3* D3DXVec3TransformCoord(
  2.   _Inout_       D3DXVECTOR3 *pOut,
  3.   _In_    const D3DXVECTOR3 *pV,
  4.   _In_    const D3DXMATRIX  *pM
  5. );

According to the documentation
https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dxvec3transformcoord
the result value is the same as the pOut Value.

So the translated header function in pascal looks like this:
Code: Pascal  [Select][+][-]
  1. function D3DXVec3TransformCoord(out pOut: TD3DXVECTOR3; const pV: TD3DXVECTOR3; const pM: TD3DXMATRIX): PD3DXVECTOR3; stdcall; external DLL_D3DX10;

Using this function
Code: Pascal  [Select][+][-]
  1. lookAt2 := D3DXVec3TransformCoord(lookAt, lookAt, rotationMatrix);
result in this assembly code:
Code: ASM  [Select][+][-]
  1. # [116] lookAt2:=D3DXVec3TransformCoord(lookAt, lookAt, rotationMatrix);
  2.         leal    -132(%ebp),%eax
  3.         pushl   %eax
  4.         leal    -40(%ebp),%eax
  5.         pushl   %eax
  6.         leal    -40(%ebp),%eax
  7.         pushl   %eax
  8.         call    _$dll$d3dx10_43$D3DXVec3TransformCoord
  9.         movl    %eax,-56(%ebp)
  10. .Ll55:
The problem is, that the application is crashing at this function.


The same pascal routine compiled in Delphi, works fine.
Looks like this:
Code: ASM  [Select][+][-]
  1. cameraclass.pas.122: lookAt2 := D3DXVec3TransformCoord(lookAt, lookAt, rotationMatrix);
  2. 004F6A9A 8D857CFFFFFF     lea eax,[ebp-$00000084]
  3. 004F6AA0 50               push eax
  4. 004F6AA1 8D45C8           lea eax,[ebp-$38]
  5. 004F6AA4 50               push eax
  6. 004F6AA5 8D45C8           lea eax,[ebp-$38]
  7. 004F6AA8 50               push eax
  8. 004F6AA9 E8C2D3FFFF       call D3DXVec3TransformCoord
  9. 004F6AAE 8945F8           mov [ebp-$08],eax

I'm not a assembler guru, but the code looks equal to me.

I found a workaround
Code: Pascal  [Select][+][-]
  1. // Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
  2.     {$IFDEF FPC}
  3.     pos4D := TD3DXVector4.Create(lookAt.x, lookAt.y, lookAt.z, 1);
  4.     d3dxvec4transform(pos4D, pos4D, rotationMatrix);
  5.     lookAt.x := pos4D.x;
  6.     lookAt.y := pos4D.y;
  7.     lookAt.z := pos4D.z;
  8.  
  9.     pos4D := TD3DXVector4.Create(up.x, up.y, up.z, 1);
  10.     d3dxvec4transform(pos4D, pos4D, rotationMatrix);
  11.     up.x := pos4D.x;
  12.     up.y := pos4D.y;
  13.     up.z := pos4D.z;
  14.     {$ELSE}
  15.     D3DXVec3TransformCoord(lookAt, lookAt, rotationMatrix);
  16.     D3DXVec3TransformCoord(up, up, rotationMatrix);
  17.     {$ENDIF}
But I'm not very happy, with this, cause when comes the next problem...?

So whats the problem?

Zvoni

  • Hero Member
  • *****
  • Posts: 2315
Re: Execution stopp with 331
« Reply #5 on: October 28, 2021, 08:32:08 am »
I'm more surprised that his 3 Arguments in the translated Function-Header for "D3DXVec3TransformCoord" are NOT pointers, contrary to the Result-Type which IS a Pointer
Would have expected
Code: Pascal  [Select][+][-]
  1. function D3DXVec3TransformCoord(out pOut: PD3DXVECTOR3; const pV: PD3DXVECTOR3; const pM: PD3DXMATRIX): PD3DXVECTOR3; stdcall; external DLL_D3DX10;
  2.  
« Last Edit: October 28, 2021, 08:44:37 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018