Texture2D.FromStream Issue

Texture2D.FromStream will hang indefinitely if it is run anywhere on the game tread, either Game1(), Initialize(), LoadContent(), Update(), Draw() etc.

The only way this will work is to make all Textured2D.FromStream Commands to run on a new tread.

We’re aware of the problem and we’re working on a new solution.

Hi,
I tried to create texture from stream and got nullreference as result. Is it connected to this issue?

What I wanted to do is just to create texture from stream. But call Texture2D.FromStream() throws null reference. Digging deeper discovered any call to texture constructor results in this exception… I though it was the issue of texture size, but even this one new Texture2D(device,1,1) doesn’t work. Here is the stacktrace:

at SharpDX.Direct3D11.Device.CreateTexture2D(Texture2DDescription& descRef, DataBox[] initialDataRef, Texture2D texture2DOut)
   at SharpDX.Direct3D11.Texture2D…ctor(Device device, Texture2DDescription description)
   at Microsoft.Xna.Framework.Graphics.Texture2D.CreateTexture()
   at Microsoft.Xna.Framework.Graphics.Texture.GetTexture()
   at Microsoft.Xna.Framework.Graphics.Texture2D.PlatformConstruct(Int32 width, Int32 height, Boolean mipmap, SurfaceFormat format, SurfaceType type, Boolean shared)
   at Microsoft.Xna.Framework.Graphics.Texture2D…ctor(GraphicsDevice graphicsDevice, Int32 width, Int32 height, Boolean mipmap, SurfaceFormat format, SurfaceType type, Boolean shared)
   at Microsoft.Xna.Framework.Graphics.Texture2D…ctor(GraphicsDevice graphicsDevice, Int32 width, Int32 height, Boolean mipmap, SurfaceFormat format)

Monogame and sharpDX are the latest - monogame just compiled from the dev branch, sharpDX is 2.6.0.0 from their nuget package.

What was the texture format? Mips or no mips?

Hi Tom,
Actually I don’t think it matters. The issue seems to be with threads. I already resolved this with super easy workaround. Let me share solution, mayby it will be usefull for somebody. What i need is to insert texture from camera. I need this for all supported platforms (iOS, Android, WP8, Win8). So I have some game class (cs file shared between platforms) and helper class (platform specific implementation). For WP8 my specific helper method was like this:

public static Task<Texture2D> InsertPhoto()

{
            var tcs = new TaskCompletionSource();

PhotoChooserTask photoChooserTask;
            photoChooserTask = new PhotoChooserTask();
            photoChooserTask.Completed += (s, e) =>
            {
                if (e.Error != null)
                {
                    tcs.TrySetResult(null);
                }
                else if (e.ChosenPhoto!=null)
                {
                        BitmapImage bmi = new BitmapImage();
                        bmi.SetSource(e.ChosenPhoto);
                        WriteableBitmap wBitmap = new WriteableBitmap(bmi);

var memoryStream = new MemoryStream();

float aspect = (float)Math.Max(wBitmap.PixelHeight, wBitmap.PixelWidth);
                        var ratio = 1280.0f / aspect;

wBitmap.SaveJpeg(memoryStream, (int)(wBitmap.PixelWidth * ratio), (int)(wBitmap.PixelHeight * ratio), 0, 100);

e.ChosenPhoto.CopyTo(memoryStream);
var texture = Texture2D.FromStream(SceneManager.RenderContext.GraphicsDevice, memoryStream)
                        tcs.TrySetResult(texture);
                   
                }
                else
                {
                    tcs.TrySetResult(null);
                }

};
            photoChooserTask.Show();
            return tcs.Task;
        }

And this code had this null reference exception when I tried to create texture.
Then I change to return memoryStream from this method and created texture in shared game class - and it started to work.

Is there any update on this feature? I also encountered this problem on Android.