Recent

Author Topic: IDirect3D9.CreateDevice() fails in 64 bit  (Read 7978 times)

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 370
IDirect3D9.CreateDevice() fails in 64 bit
« on: December 07, 2018, 02:17:03 pm »
CreateDevice() in IDirect3D9 fails with D3DERR_INVALIDCALL in 64 bit.

In 32 bit same code works fine.

I attach a simple Lazarus test project in a ZIP (see below the link). DirectX9 headers for FPC where downloaded from clootie.ru

Lazarus 1.8.4 / fpc 3.0.4 / Windows 10 v1803 64 bit.

Code: Pascal  [Select][+][-]
  1. unit MainUnit;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Types, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,  StdCtrls,  Direct3D9;
  9.  
  10. const
  11.   {$IFDEF DXDEBUG}
  12.   Local_D3D_SDK_VERSION   = (32 or $80000000);
  13.   {$ELSE}
  14.   Local_D3D_SDK_VERSION   = 32;
  15.   {$ENDIF}
  16.  
  17. type
  18.   { TForm1 }
  19.   TForm1 = class(TForm)
  20.     Memo1: TMemo;
  21.     procedure FormClick(Sender: TObject);
  22.     procedure FormCreate(Sender: TObject);
  23.     procedure FormKeyPress(Sender: TObject; var Key: char);
  24.     procedure Log(const S : string; N : Int64);
  25.     procedure Init3D;
  26.   private
  27.     fD3D               : IDirect3D9;
  28.     fDevice            : IDirect3DDevice9;
  29.   public
  30.   end;
  31.  
  32. var
  33.   Form1: TForm1;
  34.  
  35. implementation
  36.  
  37. {$R *.lfm}
  38. { TForm1 }
  39.  
  40. procedure TForm1.FormCreate(Sender: TObject);
  41. begin
  42.   Caption:='Fpc'+IntToStr(SizeOf(Pointer)*8);
  43.   Init3D;
  44. end;
  45.  
  46. procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);
  47. begin
  48.   if Key=#13 then Self.Click;
  49. end;
  50.  
  51. procedure TForm1.Init3D;
  52. var
  53.   R             : TRect;
  54.   W, H          : Integer;
  55.   PresParams    : TD3DPresentParameters;
  56.   res           : HResult;
  57. begin
  58.   R:=Self.BoundsRect;
  59.   W:=(R.Right-R.Left);
  60.   H:=(R.Bottom-R.Top);
  61.  
  62.   fD3D:=Direct3DCreate9(Local_D3D_SDK_Version);
  63.   Log('IDirect3D ',UIntPtr(fD3D));
  64.  
  65.   if not Assigned(fD3D) then Exit;
  66.  
  67.   FillChar(PresParams, SizeOf(PresParams), 0);
  68.   PresParams.Windowed:=True;
  69.   PresParams.PresentationInterval:=D3DPRESENT_INTERVAL_DEFAULT;
  70.   PresParams.SwapEffect:=D3DSWAPEFFECT_COPY;
  71.   PresParams.BackBufferCount:=1;
  72.  
  73.   PresParams.BackBufferWidth:=W;
  74.   PresParams.BackBufferHeight:=H;
  75.   PresParams.BackBufferFormat:=D3DFMT_X8R8G8B8; //_D3DFORMAT(Params.DisplayMode.PixelFormat);
  76.  
  77.   Log('Self.Handle ', Self.Handle);
  78.  
  79.   res := fD3D.CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Self.Handle,
  80.       D3DCREATE_MULTITHREADED or D3DCREATE_FPU_PRESERVE or D3DCREATE_SOFTWARE_VERTEXPROCESSING,
  81.       @PresParams, fDevice );
  82.  
  83.   Log('Create Device, HResult ',res );
  84.   if res=D3D_OK then Log('IDirect3DDevice9 ', UIntPtr(fDevice) );
  85. end;
  86.  
  87.  
  88. procedure TForm1.FormClick(Sender: TObject);
  89. var
  90.   R             : TRect;
  91.   W, H          : Integer;
  92. begin
  93.   if fDevice=nil then Exit;
  94.   if Memo1.Visible then begin
  95.     Memo1.Visible:=False;
  96.     Self.Update;
  97.   end;
  98.  
  99.   R:=Self.BoundsRect;
  100.   W:=(R.Right-R.Left);
  101.   H:=(R.Bottom-R.Top);
  102.  
  103.   fDevice.BeginScene;
  104.  
  105.   R:=Rect(0,0,W,H div 3);
  106.   fDevice.Clear(1, @R, D3DCLEAR_TARGET, $00FFFFFF, 0, 0);
  107.  
  108.   R.Top:=R.Bottom; R.Bottom:=H*2 div 3;
  109.   fDevice.Clear(1, @R, D3DCLEAR_TARGET, $000000FF, 0, 0);
  110.  
  111.   R.Top:=R.Bottom; R.Bottom:=H;
  112.   fDevice.Clear(1, @R, D3DCLEAR_TARGET, $00FF0000, 0, 0);
  113.  
  114.   fDevice.EndScene;
  115.  
  116.   R:=Rect(0,0,W,H);
  117.   fDevice.Present( @R, @R, 0, nil );
  118. end;
  119.  
  120. procedure TForm1.Log(const S : string; N : Int64);
  121. begin
  122.   Form1.Memo1.Lines.Add(S+IntToStr(N));;
  123. end;
  124.  
  125. end.
  126.  
« Last Edit: December 07, 2018, 04:06:42 pm by Igor Kokarev »

Igor Kokarev

  • Sr. Member
  • ****
  • Posts: 370
Re: IDirect3D9.CreateDevice() fails in 64 bit
« Reply #1 on: December 07, 2018, 05:14:29 pm »
I found that if I replace all "packed record" to "record" in DirectX headers my app starts to work.

It seems to be compatiblity with 64 bit in current DirectX headers from clootie.

 

TinyPortal © 2005-2018