Jump to content
  • Advertisement
Sign in to follow this  
mxion

SlimDX and LockRectangle blocks...

This topic is 2109 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi.

 

I'm pretty new to SlimDX/DirectX so bare with me. I have this application (programmed using Visual Studio 2008, .NET2, C#) that gets map tiles from an online service and then renders them on the screen. Tiles are fetched asynchronously (using multiple threads, core count - 1).

 

The problem is that when I call Texture.LockRectangle(0, LockFlags.None) the application freezes when I pan or zoom the chart. New tiles are fetched from the online service depending on how the map is panned/zoomed (like in e.g. Googe Maps). If I have gotten this right DirectX's Map is equivalent to LockRectangle and Unmap to UnlockRectangle. I have read some DirectX documentation but haven't found anything about blocking the calling thread.

 

I haven't programmed this application but I have to fix so I cannot provide you with any thorough description how it works. I'm just wondering is there a situation where LockRectangle blocks the calling thread until the previous lock/unlock has been processed? The method that uses LockRectangle also uses UnlockRectangle at the end. I've also put the code between inside try/catch but it never catches anythig - i.e. everything should be okay when it comes to calling this particular method. I've also used Console.WriteLine to ouput "lock" and "unlock" to see that there are event count of both. Natually the outputting ends in "lock" because the application freezes.

 

I've gone through the code for a couple of days and there are a lot of "lock" keywords so thread synchronization is at least considered. Not sure if it works completely because most of the time the tile object itself is locked instead of dedicated Object instance. Well anyway, let's assume that the thread related code works...

 

One thing to mention is that there is this Tile class that holds the actual SlimDX Texture object and the texture object is disposed from Tile's finalizer ("destructor"). When I comment out the line where the texture object is disposed the application does not freeze. Naturally the texture object then does not get released from the memory.

 

So, here's something to begin with. Ask away if you need to know something and naturally try to keep your question/answers as simple as possible. :)

 

Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement

Locking a resource does two things: it gets you a handle to the memory representing the contents of the resources (copying stuff around, if needed), and it protects the resource data from other threads.

 

The latter action causes locking to block the calling thread if any other thread (or the GPU) has already locked the resource. Some drivers are smart enough to allow multiple locks on one resource if the memory ranges of said simultaneous locks are not overlapping, but I believe this is only true for linearly-accessed buffers such as vertex and index buffers (and not 2d or 3d textures).

 

During rendering, the GPU will implicitly lock the resources that it uses during the render process, to protect the data from modification in the middle of the drawing ops.

 

You should only get locks for as short time as possible, and as few times as possible.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!