Skip to main content
GameDev.net gamedev.net
🔒 Locked

SlimDX texture problem

Started by zcpzzy Dec 8, 2009 at 1:36 AM 4 replies 2k views
Original Post
zcpzzy
zcpzzy
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); } }
Moeller
Moeller
Have you created your Direct3D9 device with CreateFlags.Multithreaded?
Evil Steve
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.
zcpzzy
zcpzzy
thanks for help :)
i created the device with Multithreaded, it works.
Mike.Popoloski
Mike.Popoloski
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...
Mike Popoloski | Journal | SlimDX
Moeller
Moeller
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.