SlimDX texture problem
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);
}
}
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.
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.
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...
He is accessing Direct3D from two different threads
so without thread safty (CreateFlags.Multithreaded) many strange things can happen. Thats at least what I would expect.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement