Sign in to follow this  
programmer_tom

Threaded Texture Loading

Recommended Posts

Hey All I'm loading textures on a thread using D3DXCreateTextureFromFileEx(). When the thread completes, I need to swap textures. I'm doing it like this: pOldTexture->Release(); pOldTexture = pNewTexture; This works great, except for once in a while it crashes, as you might expect because I've done nothing to prevent the thread from completing at random times. What do I need to do to make texture loading in DX thread safe? -programmer_tom

Share this post


Link to post
Share on other sites
Are you using D3DCREATE_MULTITHREADED? That's the main thing required for using D3D from multiple threads.

If you want to avoid using that flag (which can affect performance somewhat) then load the texture on the thread into memory using say fread(), and once that's complete on the main thread call D3DXCreateTextureFromFileInMemoryEx().

Share this post


Link to post
Share on other sites
With D3D9 you really want to keep all of your code that accesses D3D interfaces on a single thread (the thread that created the window and pumps messages). You can use the MULTITHREADED flag to make the device thread safe, but this will slow things down significantly. This means that for loading textures you best option is to do all of the file i/o on a separate thread, and read the image data into memory. Then you can pass that data off to your main thread, which can use the device or D3DX functions to make the actual texture object.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this