FlipBuffers and DirectX9

Advanced game related topics
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

FlipBuffers and DirectX9

Post by IdeasVacuum »

Windows x86

Test code below is a copy of the example file MeshManual.pb, chopped-down (for example, excludes Screen3DRequester.pb) so that I can teach myself about Materials and Cameras.

In PB4.31, it runs perfectly (I have double-triple checked this!) - in Compiler Options, Library Subsystem, I entered "DirectX9" (a tip I picked-up elsewhere on the forum).

In PB4.40, the code fails. Firstly, the compiler complains that "DirectX9" cannot be found: "The following subsystem cannot be found: DirectX9".

If I remove the Subsystem entry, the code fails at FlipBuffers: "[ERROR] Invalid memory access. (read error at address 0)".

Whether DirectX9 is entered as a Subsystem or not, the original MeshManual.pb works fine, so not a PB bug. What is the difference between PB4.31 and PB4.40 that causes my code failure? I know that FlipBuffers and OpenWindowedScreen have been improved in PB4.40.

Code: Select all


; MeshTest

#WINDOW_Screen3D = 0
#CameraSpeed     = 1
#Camera1         = 2
#MeshData        = 3
#MeshEnt         = 4
#MeshMatl        = 5

Global sSourceFolder.s = "D:\PROJECTS\PureBasic\MeshTest\Data\"
Global  sWindowTitle.s = "[ESC] Key to Exit"

Procedure Screen3D()

      If OpenWindow(0, 0, 0, 800, 650, sWindowTitle, #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

               Result = OpenWindowedScreen(WindowID(#WINDOW_Screen3D), 0, 50, 800, 600, 0, 0, 0)

      EndIf

EndProcedure

If InitEngine3D()

        UsePNGImageDecoder()

        Add3DArchive(sSourceFolder, #PB_3DArchive_FileSystem)

        InitSprite()
        InitKeyboard()
        InitMouse()

        Screen3D()

        ; The data has to be organize in this order: Vertex, Normal, Color, UVCoordinate (per vertex)
        ; Create a cube, manually.. See the DataSection, for more precisions

         CreateMesh(#MeshData, 100)

        SetMeshData(#MeshData, #PB_Mesh_Vertex, ?VertData, 8)
        SetMeshData(#MeshData, #PB_Mesh_Normal, ?NormData, 8)
        SetMeshData(#MeshData, #PB_Mesh_Face, ?FaceData, 12)

        CreateMaterial(#MeshMatl, LoadTexture(0, "AlphaChannel.png"))
        MaterialAmbientColor(#MeshMatl, RGB($CC,$CC,$CC))

        CreateEntity(#MeshEnt, MeshID(#MeshData), MaterialID(#MeshMatl))

        CreateCamera(#Camera1, 0, 0, 100, 100)
        CameraLocate(#Camera1, 0, 0, 1000)
        CameraLookAt(#Camera1, EntityX(#MeshEnt), EntityY(#MeshEnt), EntityZ(#MeshEnt))
        AmbientColor($FFFFF0)

            Repeat

                        ClearScreen(RGB(0,0,0))

                        RotateEntity(#MeshEnt, 1, 1, 1, #PB_Relative)

                        RenderWorld()

                        FlipBuffers()

            Until KeyboardPushed(#PB_Key_Escape)

Else

        MessageRequester("Error", "3D Engine did not start",0)

EndIf

CloseScreen()

End

#SQRT13 = 0.57735026

DataSection

    VertData:

    Data.f -100.0,100.0,-100.0        ; 0 position
    Data.f 100.0,100.0,-100.0         ; 1 position
    Data.f 100.0,-100.0,-100.0        ; 2 position
    Data.f -100.0,-100.0,-100.0       ; 3 position
    Data.f -100.0,100.0,100.0         ; 4 position
    Data.f 100.0,100.0,100.0          ; 5 position
    Data.f 100.0,-100.0,100.0         ; 6 position
    Data.f -100.0,-100.0,100.0        ; 7 position

    NormData:

    Data.f -#SQRT13,#SQRT13,-#SQRT13  ; 0 normal
    Data.f #SQRT13,#SQRT13,-#SQRT13   ; 1 normal
    Data.f #SQRT13,-#SQRT13,-#SQRT13  ; 2 normal
    Data.f -#SQRT13,-#SQRT13,-#SQRT13 ; 3 normal
    Data.f -#SQRT13,#SQRT13,#SQRT13   ; 4 normal
    Data.f #SQRT13,#SQRT13,#SQRT13    ; 5 normal
    Data.f #SQRT13,-#SQRT13,#SQRT13   ; 6 normal
    Data.f -#SQRT13,-#SQRT13,#SQRT13  ; 7 normal

    FaceData:

    Data.w 0,2,3
    Data.w 0,1,2
    Data.w 1,6,2
    Data.w 1,5,6
    Data.w 4,6,5
    Data.w 4,7,6
    Data.w 0,7,4
    Data.w 0,3,7
    Data.w 0,5,1
    Data.w 0,4,5
    Data.w 2,7,3
    Data.w 2,6,7

EndDataSection

; IDE Options = PureBasic 4.40 (Windows - x86)
; CursorPosition = 13
; FirstLine = 28
; Folding = -
; EnableThread
; EnableXP
; SubSystem = DirectX9
; CurrentDirectory = D:\PROJECTS\PureBasic\
; CompileSourceDirectory
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: FlipBuffers and DirectX9

Post by Kaeru Gaman »

only thing I see at first glance is, you don't process the events tho you use a windowedscreen.
there is an example in the help, with an inner eventloop...

... but I don't think that would cause an IMA, sorry ...

btw: DX9 is default system for PB4.40, that means no entry in the subsystem field.
oh... and have a nice day.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: FlipBuffers and DirectX9

Post by IdeasVacuum »

Hi Kaeru
Kaeru Gaman wrote:only thing I see at first glance is, you don't process the events tho you use a windowedscreen.
there is an example in the help, with an inner eventloop...
There should be an ExamineKeyboard() event at the top of the Repeat loop, just to catch the Escape Key - sorry, that's down to my poor copy and paste of the code -I've only been using PCs since the time they were invented :)

I have discovered the cause of my problem, but still have not worked out what exactly is at fault.

This is the clue I stumbled across:

The failure only occurred in PB4.40 if the .pb file had been saved to the hard drive. If I created a new document, copied and pasted the code (all!) into it and Compile/Run without saving, it worked perfectly! Once the file was saved, it always failed at FlipBuffers().

Now, all my Projects are saved to a folder path on drive D:\. So, instead I saved the file to a folder on drive C:\ and hey-presto, it works perfectly!

So, I believe that does mean there is possibly some kind of regression bug in PB4.40, since this issue does not occur with PB4.31.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: FlipBuffers and DirectX9

Post by Kaeru Gaman »

ExamineKeyboard is no Event, it's a Command.

you need to process all Events in the EventQueue, using an inner loop with WindowEvent()
take a look at the example to OpenWindowedScreen()


your description sounds like you made a mistake while installing 4.40

when you want to run two versions parallel on the same computer,
you need to start allbut one with the parameter /portable,
to make the purebasic.prefs be saved into the versions directory.

and when you installed the 4.40 final into the same dir you had the beta in,
you should install it again into a virgin directory.
oh... and have a nice day.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: FlipBuffers and DirectX9

Post by IdeasVacuum »

you need to process all Events in the EventQueue, using an inner loop with WindowEvent()
take a look at the example to OpenWindowedScreen()
I see what you mean -yes, if was a "real" program I would do that but it's only a means to an end that I can use to experiment with.

I am not running two versions of PB, I have simply installed/un-installed to swap between versions. I have never used the Beta since I'm a PB Newbie.

However, I did not install PB4.40 into a new folder, I overwrote the existing PB4.31 folder (C:\Program Files\PureBasic)(and vice versa). Now that seems to work fine, PB4.31 gets replaced by PB4.40 in Add/Remove programs (and vice versa), but I shall heed your advice and re-install.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: FlipBuffers and DirectX9

Post by IdeasVacuum »

...nope, after a careful re-install of PB4.40, the fault remains the same :( -if the .pb file is saved to any drive other than C, execution fails on FlipBuffers(). It would be interesting to know if anyone else can reproduce this issue.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Demivec
Addict
Addict
Posts: 4269
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: FlipBuffers and DirectX9

Post by Demivec »

IdeasVacuum wrote:
you need to process all Events in the EventQueue, using an inner loop with WindowEvent()
take a look at the example to OpenWindowedScreen()
I see what you mean -yes, if was a "real" program I would do that but it's only a means to an end that I can use to experiment with.
It is a "real" program and so it needs to handle events. Something like this should work:

Code: Select all

  Repeat
    event = WindowEvent() ;hog the CPU, leave out the delay(), for experiment purposes only
    ExamineKeyboard()
    If Not event
      ClearScreen(RGB(0,0,0))
      
      RotateEntity(#MeshEnt, 1, 1, 1, #PB_Relative)
      
      RenderWorld()
      
      FlipBuffers()
    EndIf
    
    
  Until KeyboardPushed(#PB_Key_Escape) Or event = #PB_Event_CloseWindow
I wasn't able to reproduce your problems with FlipBuffers(). Using DirectX9 and v4.40 I get a white rotating cube when I run the program (after adjusting the sSourceFolder path according to my installation).
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: FlipBuffers and DirectX9

Post by IdeasVacuum »

Thanks for your advice and code snippet Demivec.

What drive did you save to?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Demivec
Addict
Addict
Posts: 4269
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: FlipBuffers and DirectX9

Post by Demivec »

IdeasVacuum wrote:What drive did you save to?
"H:"
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: FlipBuffers and DirectX9

Post by IdeasVacuum »

I can still only get it to work on drive C. That should be OK anyway but I don't like to have unknowns. I will try it out on my other PCs. Something else I have found out by accident is that PB4.40 does not need the Engine3D.dll file to be in the Project Folder, whereas that was required by PB4.31.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: FlipBuffers and DirectX9

Post by djes »

I think you have several engine3d.dll in your hd. Search and remove old ones.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: FlipBuffers and DirectX9

Post by IdeasVacuum »

djes wrote:I think you have several engine3d.dll in your hd. Search and remove old ones.
Hello djes. That didn't fix my problem but it is certainly good advice anyway -I did have a stray version of the old dll.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Thade
Enthusiast
Enthusiast
Posts: 266
Joined: Sun Aug 03, 2003 12:06 am
Location: Austria

Re: FlipBuffers and DirectX9

Post by Thade »

Question: When did this start for you? Any significant hardware upgrade?

It started for me for all old Programs when I upgraded my Aspire to NVidia 3D vision (Samsung 2233 120 Hz + 3D Vision Kit + drivers 185.85) ... with Vista and Win 7 ... compatibility mode makes no change. It worked perfect before on the same system without 3D Vision Kit and a Samsung Syncmaster T 260 60 Hz
Now every old Program that uses Flip Buffers crashes (PB, Blitz, etc.). I tested programs like Moorhuhn and old stuff like this ... runs perfect on our other 5 computer systems (same drivers + Vista) ran perfect before - not now on the 3D Vision System ...
I can use 3D Vision with red/cyan-spectacles on other systems with 60 Hz Monitors. It works perfect for all mentioned programs.
Not sure, but it seems, that as soon as a Monitor with 120 Hz is involved FlipBuffers crashes.
--------------
Yes, its an Irish Wolfhound.
Height: 107 cm; Weight: 88 kg
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: FlipBuffers and DirectX9

Post by IdeasVacuum »

Hi Thade

Not necessarily FlipBuffers that causes my issue, since everything is OK providing the files are on Drive C.

For your issue, have you tried the Flags available for FlipBuffers (applied to OpenScreen/OpenWindowedScreen)?

e.g.

Code: Select all

If OpenWindowedScreen(WindowID(#Window), 100, 100, 600, 400, 0, 0, 0, #PB_Screen_NoSynchronization)
I noticed also that the PB experts follow FlipBuffers with a short Delay, and the same with WaitWindowEvent.

Back to the hardware, can you run the Samsung at a slower rate to test?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: FlipBuffers and DirectX9

Post by jesperbrannmark »

Did you get this solved? I get ima's on some machines with flipbuffers... Can't really say what is different with those machines from other ones...
Post Reply