Resource Manager/DataStream

madmark

13-03-2007 17:03:03

I have run into a snag using the Ogre resource manager and data streaming.

I need to get the binary data into a buffer or MemoryStream, but the Read method of DataStream takes a (void *) and I can't seem to grok how to make that happen in C#.

Am I missing something?

For completeness, here is the test I ran...

public MemoryStream OgreResourseFetchStream(String name)
{
DataStreamPtr pStream = ResourceGroupManager.Singleton.OpenResource(name);
if (pStream.Size() != 0)
{
MemoryStream s = new MemoryStream((int) pStream.Size());
for (int i = 0; i < pStream.Size(); i++)
s.WriteByte((byte)pStream.AsString[i]);

return s;

}
return null;
}

The problem is that as soon as the data contains a zero byte, the string ends and an exception occurs (out of bounds)

Bekas

21-03-2007 00:15:40

the Read method of DataStream takes a (void *) and I can't seem to grok how to make that happen in C#.
You'll need unsafe code for this:
byte[] buffer = new byte[pStream.Size()];
unsafe
{
fixed (byte* ptr = &buffer[0])
{
pStream.Read(ptr, buffer.Length);
}
}