pandap / slimdx

Automatically exported from code.google.com/p/slimdx
MIT License
0 stars 0 forks source link

DataRectangle.WriteRange<Color4>(Color4Array) Fails with {"Attempted to read past the end of the stream."} - Most of the time #847

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
v2.0.50727
2.0.12.43

Trying to create a Texture2D in code. (Code below)

1.  Create Array of Color4
2.  Fill
3.  Create Texture2DDescription
4.  Create new Texture2D (using description)
5.  Texture2D.Map texture to a DataRectangle
6.  Attempt to fill Texture2D using 
DataRectangle.WriteRange<Color4>(Color4Array)
7.  Fails with "Attempted to read past the end of the stream." For most source 
array sizes.

----------------------------------------------------------
EXPERIMENT

Code below uses no parameters on WriteRange other than the data source.  This 
is supposed to write all the data in the source.  However, experimenting with 
manually setting the source size showed the following:

Source ColorArray Size=4x4:  No error
Source ColorArray Size=5x5:  Source sizes larger than 20 fail
Source ColorArray Size=6x6:  Source sizes larger than 24 fail

-----------------------------------------------------------
SOURCE (Last line below fails - depending upon height and width

// CREATE THE TEXTURE BUFFER
Color4[] textureBuffer = new Color4[widthInt*heightInt];

// FILL
for(int x=0;x<widthInt;x++)
    for (int y=0;y<heightInt;y++)
        textureBuffer[x+y*heightInt]=new Color4(Color.Blue);

// TEXTURE DESCRIPTION
Texture2DDescription textureDescription = new Texture2DDescription()
{
    ArraySize = 1,
    Width = widthInt,
    Height = heightInt,
    BindFlags = BindFlags.ShaderResource,
    CpuAccessFlags = CpuAccessFlags.Write,
    Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
    OptionFlags = ResourceOptionFlags.None,
    Usage = ResourceUsage.Dynamic,
    MipLevels = 1,
    SampleDescription = new SampleDescription(1, 0)
};

// WRITE TO TEXTURE
propertyTexture = new Texture2D(staticPropertyDevice,textureDescription);
DataRectangle textureAccess = 
propertyTexture.Map(0,MapMode.WriteDiscard,SlimDX.Direct3D10.MapFlags.None);
textureAccess.Data.WriteRange<Color4>(textureBuffer);

Original issue reported on code.google.com by danaball...@gmail.com on 13 Nov 2011 at 10:05

GoogleCodeExporter commented 9 years ago
Solved.  This was my silly mistake of thinking a Color4 = a R8G8B8A8 color!
This is a non-issue.

Sorry for the noise.

-db

Original comment by danaball...@gmail.com on 13 Nov 2011 at 11:10

GoogleCodeExporter commented 9 years ago

Original comment by Mike.Popoloski on 13 Nov 2011 at 11:46