Why does this work?

Just starting out? Need help? Post your questions and find answers here.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Why does this work?

Post 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)
BERESHEIT
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post 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........
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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. :?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Post 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
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
Post Reply