I'm using SlimDX in a managed Windows application ( Win. XP, .Net 3.5 ). SlimDX handles all unmanaged DirectX API calls. I'm trying to call the following method found in SlimDX framework: SlimDX.Direct3D9.XFile.CreateEnumerationObject(Stream stream). Here is implementation:
XFile xfile = new XFile();
XFileEnumerationObject enumObj = null;
string Filename = @"MyDocs\Test.x";
using (FileStream fs = new FileStream(Filename, FileMode.Open, FileAccess.Read))
{
enumObj = xfile.CreateEnumerationObject(fs);
}
When I call this method I get the following exception:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at SlimDX.Direct3D9.XFile.CreateEnumerationObject(Byte[] memory)
at SlimDX.Direct3D9.XFile.CreateEnumerationObject(Stream stream)
at SceneGenerator.ContentManager.XParser.Parse(XParserMode Mode, MeshFlags options, List`1& materialPartitions, GDEAssetConfig& cfg, _XData& userContext, Byte[] filedata) in D:\Documents and Settings\GDEAuxiliary\My Documents\Visual Studio 2010\Projects\SceneGenerator\SceneGenerator\XParser.cs:line 191
SlimDX is to handle the conversion of this memory stream to byte array, and byte array to unmanaged memory. I imagine that the file data was not loaded in the expected text encoding...
I have validated the file by using an alternate method found in SlimDX framework that creates an enumeration object using a filename and a specified character set...here is implementation:
XFile xfile = new XFile();
XFileEnumerationObject enumObj = null;
string Filename = @"MyDocs\Test.x";
enumObj = xfile.CreateEnumerationObject(cfg.Filename, System.Runtime.InteropServices.CharSet.Auto);
This method works fine...
What can I do to prepare the memory stream for SlimDX...unfortunately I'm not entirely sure what is expected of the memory stream by SlimDX...