GraphicsStream.InternalDataPointer null?

Good day,

We are creating a texture from a bitmap region using an unsafe section in C#, but occasionally the InternalDataPointer for the GraphicsStream's returned from Texture.LockRectangle will be null. Following are the relevant lines:

Texturetexture =newTexture(device, bitmap.Width, bitmap.Height, 1,Usage.Dynamic,Format.A8R8G8B8,Pool.Default);

intpitch;

GraphicsStream graphicsStream = texture.LockRectangle(0,LockFlags.None,out pitch);

unsafe

{

byte* to = (byte*)graphicsStream.InternalDataPointer;

...

It is a multi-threaded app, but to our knowledge no other thread acts on these members. What could cause a null InternalDataPointer? Thanks in advance...

[2130 byte] By [RandalGreene] at [2007-12-27]
# 1
Enable unmanaged debugging and crank up the debug level slider in the D3D control panel (and select debug runtime) and see if there are any interesting messages in the output...
WessamBahnassi at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: Graphics...
# 2

Thanks for your feedback, Wessam.

I turned up D3D debugging info as you suggested, but it did not provide any extra detail. When we try to use the "to" variable in the code above, it gives us a System.NullReferenceException (.NET exception). Debugging shows the value of to as 0x00000000 and *to as "could not evaluate expression", even though the GraphicsStream has a positive Length.

One suggestion was to retry the LockRectangle until we get a non-null value for the InternalDataPointer, but the second call to LockRectangle gives a D3DERR_INVALIDCALL (-2005530516) - LockRect failed on a mip level; surface was already locked for a Level of a Texture.

Any other thoughts greatly appreciated...

RandalGreene at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: Graphics...
# 3

Randal Greene wrote:

One suggestion was to retry the LockRectangle until we get a non-null value for the InternalDataPointer, but the second call to LockRectangle gives a D3DERR_INVALIDCALL (-2005530516) - LockRect failed on a mip level; surface was already locked for a Level of a Texture.

Well? Unlock it first :)

One more thing to try, does the Write() method work if you use it instead of directly accessing the data pointer?

WessamBahnassi at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: Graphics...
# 4

Thanks again for your ideas Wessam.

Once in this state, UnlockRectangle calls return System.InvalidOperationException!

I will set a breakpoint and check the Write method next time the problem recurs.

One more strange thing I have noticed - the call stack in the error history for both the InvalidOperationException and the InvalidCallException show 2 sets of calls to the methods, but I don't see how this is possible (see below). The call stack in the debugger only shows 1 set of calls.

Any other ideas greatly appreciated...

--

A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.DirectX.Direct3D.dll

System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled exception</Description><AppDomain>Kraz.vshost.exe</AppDomain><Exception><ExceptionType>System.InvalidOperationException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Operation is not valid due to the current state of the object.</Message><StackTrace> at Microsoft.DirectX.Direct3D.Texture.UnlockRectangle(Int32 level)

at ICAN.IFC.GeoSpatialPlotter.GeoTerrainMesh.CreateTextureFromBitmapRegion(Device device, Texture texture, Rectangle rectBitmap, Bitmap bitmap) in C:\Documents and Settings\rgreene\My Documents\Visual Studio 2005\vssgen3\SourceCode\ClassLibraries\IFC\GeoSpatialPlotter\3D Plotter\GeoTerrainMesh.cs:line 410

at ICAN.IFC.GeoSpatialPlotter.GeoTerrainMesh.UpdateTerrainTextureMap() in C:\Documents and Settings\rgreene\My Documents\Visual Studio 2005\vssgen3\SourceCode\ClassLibraries\IFC\GeoSpatialPlotter\3D Plotter\GeoTerrainMesh.cs:line 934

at ICAN.IFC.GeoSpatialPlotter.TerrainManager.UpdateTerrainLayerTexture(GeoTerrainMesh geoTerrainMesh, Boolean bForceUpdate) in C:\Documents and Settings\rgreene\My Documents\Visual Studio 2005\vssgen3\SourceCode\ClassLibraries\IFC\GeoSpatialPlotter\3D Plotter\TerrianManager.cs:line 377

at ICAN.IFC.GeoSpatialPlotter.TerrainManager.GeoMeshLoadThread(Object plotterStateIn) in C:\Documents and Settings\rgreene\My Documents\Visual Studio 2005\vssgen3\SourceCode\ClassLibraries\IFC\GeoSpatialPlotter\3D Plotter\TerrianManager.cs:line 474

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart(Object obj)</StackTrace><ExceptionString>System.InvalidOperationException: Operation is not valid due to the current state of the object.

at Microsoft.DirectX.Direct3D.Texture.UnlockRectangle(Int32 level)

at ICAN.IFC.GeoSpatialPlotter.GeoTerrainMesh.CreateTextureFromBitmapRegion(Device device, Texture texture, Rectangle rectBitmap, Bitmap bitmap) in C:\Documents and Settings\rgreene\My Documents\Visual Studio 2005\vssgen3\SourceCode\ClassLibraries\IFC\GeoSpatialPlotter\3D Plotter\GeoTerrainMesh.cs:line 410

at ICAN.IFC.GeoSpatialPlotter.GeoTerrainMesh.UpdateTerrainTextureMap() in C:\Documents and Settings\rgreene\My Documents\Visual Studio 2005\vssgen3\SourceCode\ClassLibraries\IFC\GeoSpatialPlotter\3D Plotter\GeoTerrainMesh.cs:line 934

at ICAN.IFC.GeoSpatialPlotter.TerrainManager.UpdateTerrainLayerTexture(GeoTerrainMesh geoTerrainMesh, Boolean bForceUpdate) in C:\Documents and Settings\rgreene\My Documents\Visual Studio 2005\vssgen3\SourceCode\ClassLibraries\IFC\GeoSpatialPlotter\3D Plotter\TerrianManager.cs:line 377

at ICAN.IFC.GeoSpatialPlotter.TerrainManager.GeoMeshLoadThread(Object plotterStateIn) in C:\Documents and Settings\rgreene\My Documents\Visual Studio 2005\vssgen3\SourceCode\ClassLibraries\IFC\GeoSpatialPlotter\3D Plotter\TerrianManager.cs:line 474

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart(Object obj)</ExceptionString></Exception></TraceRecord>

RandalGreene at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: Graphics...
# 5

Wessam, when the InternalDataPointer is null calls to GraphicsStream.Write also give InvalidOperationException!

RandalGreene at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: Graphics...