I'm using a control which is using XNA inside. But when I try to draw something, it doesn't appear. I already did a lot of tests but can't figure out what's wrong. Here is the test I set up:
RenderTarget2D rTarget = new RenderTarget2D(GraphicsDevice, 1000, 1000); GraphicsDevice.SetRenderTarget(rTarget); GraphicsDevice.Clear(Color.White); _spriteBatch.Draw(ts.Texture, layer.Location, source, Color.White, layer.Angle * (float)Math.PI /180, origin, SpriteEffects.None, 1f); int spriteBatchGraphics = _spriteBatch.GraphicsDevice.GetHashCode(); int normalGraphics = GraphicsDevice.GetHashCode(); GraphicsDevice.SetRenderTarget(null); using (FileStream stream = new FileStream("pic.png", FileMode.Create)) rTarget.SaveAsPng(stream, 1000, 1000); using (FileStream stream = new FileStream("pic2.png", FileMode.Create)) ts.Texture.SaveAsPng(stream, ts.Texture.Width, ts.Texture.Height);
GraphicDevice.Present is called too.
Because I didn't see anything, I tried to draw the stuff onto a
renderTarget and save it to the HDD. I also saved the texture itself to be sure it's not just white.
However, spriteBatch should draw a 48x48 block here and I checked the parameters of spriteBatch, they are okay. But on the rendertarget, nothing appears. I reacts on GraphicDevice.Clear, the color I pick there really gets drawn. The hashCodes of both graphicDevices are the same, so they really seem to draw to the same device.
What could cause this?
I searched for some more and I found the following: I'm getting a AccessViolationException when closing the program. First I thought it's unrelated but it seems it's caused by what happened before. I found in the internet that a very bad graphic card can cause this. And the graphic card I tried this on was very bad indeed. So I tried it on an other machine now - I'm getting different results, but it's still not working and I'm still getting the exception.
Here is what it draws now:
In place of the black spot, the tile should be drawn. But it's not happening. The AccessViolationException only happens when the draw glitch happens - in this case as soon it just draws a black block instead the real texture. The lines are planed and part of it (the horizontal are still missing for some reason, but trying to fix that later).
So what is happening? Gets the graphic device too much stressed? I'm also running a game class which runs with the default loop (which manages the winforms and game).
I absolutely need the XNA technology here, because it should "preview" something from the game and using System.Drawing could change the outcome. The program also could get used by clients so a normal powered graphic card should be able to deal with it.