• Advertisement
Sign in to follow this  

SlimDX texture problem

This topic is 2994 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am building one project like GoogleEarth, and create two thread for working, one thread for render and another for update,but the problem is that ,when the update thread building texture from bitmap an exception be throwed : E_OUTOFMEMORY: Ran out of memory (-2147024882) can somebody help me? here is my code: if (texture == null) { using (Bitmap bmp = new Bitmap(256, 256)) using (Graphics g = Graphics.FromImage(bmp)) using (MemoryStream ms = new MemoryStream()) { g.Clear(Color.White); g.DrawRectangle(Pens.Red, 0, 0, 255, 255); g.DrawString(name, GlobalSetting.DebugFont, Brushes.Red, 1, 1); bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] buffer = ms.ToArray(); texture = Texture.FromMemory(e.Device, buffer); } }

Share this post


Link to post
Share on other sites
Advertisement
This is a guess, since I'm not familiar with C#, but...

I suspect that Texture.FromMemory expects a in-memory image file, not a stream of bytes as you're giving it. Texture.FromMemory is probably trying to interpret the bytes as a .bmp file, and reading the width and height as some obscenely large number.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
This is a guess, since I'm not familiar with C#, but...

I suspect that Texture.FromMemory expects a in-memory image file, not a stream of bytes as you're giving it. Texture.FromMemory is probably trying to interpret the bytes as a .bmp file, and reading the width and height as some obscenely large number.


It does indeed (it mirrors D3DXCreateTextureFromFileInMemory) but he's using Bitmap.Save, which saves off the image file into the provided stream, so that should already be handled.

I'm not sure why the Multithreaded flag helps in this case...

Share this post


Link to post
Share on other sites
He is accessing Direct3D from two different threads
Quote:
Original post by zcpzzy... and create two thread for working,
one thread for render and another for update ...

so without thread safty (CreateFlags.Multithreaded) many strange things can happen. Thats at least what I would expect.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement