Page 1 of 1

Why does this work?

Posted: Fri Mar 14, 2008 3:21 pm
by netmaestro
PB doc wrote:Note: Don't use DirectX inside threads (MS Windows limitation)! If you need to display graphics in threads use Images and 2DDrawing instead

Code: Select all

Procedure test(void)
  InitSprite():InitSprite3D()
  OpenWindow(0,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  OpenWindowedScreen(WindowID(0),0,0,320,240,0,0,0)
  CreateSprite(0,64,64,#PB_Sprite_Texture)
  StartDrawing(SpriteOutput(0))
    Circle(32,32,32,#Blue)
  StopDrawing()
  CreateSprite3D(0,0)
  Repeat
    ClearScreen(0)
    If WaitWindowEvent(1)=#PB_Event_CloseWindow
      End
    EndIf
    Start3D()
      DisplaySprite3D(0,120,90)
    Stop3D()
    FlipBuffers()
  ForEver
EndProcedure

tid=CreateThread(@test(),0)
WaitThread(tid)
This seems to work without problem. Has something changed, is this safe? (I assumed it wouldn't work at all when I wrote the test)

Posted: Fri Mar 14, 2008 3:36 pm
by AND51
Somewhere I read this:

Each thread (no matter if extra thread or main thread) must initialize InitSprite() and/or InitSprite3D() on it's own.
And youo're doing so, so you can use DirectX even in threads.

Remember, we don't know, if threads can share their sprites, etc, so that thread A creates a sprite and thread B draws on it; because each thread inits DX on its own. Maybe each thread has got its own sprite management, this would make you able to assign IDs twice. On the other hand it's impossible to share ressources.

So far, I would assume, this is safe, but I'm not completely sure. Would be good to hear the PB Team's voice........

Posted: Fri Mar 14, 2008 4:53 pm
by Psychophanta
Mm.. that is a good question netmaestro.
But i didn't imagine that there was not allowed to deal with 3D stuff inside threads!! :o
So sorry i have no answer for it, but waiting for an answer too. :?

Posted: Sun Mar 16, 2008 1:37 pm
by citystate
I thought the restriction was that you couldn't have multiple threads utilising DirectX - there's no conflict if you only have one thread running