Creating a new texture fails with "first chance exception"

I have an application in which I create a texture to later write directly into. It works fine on my development machine, but on the target machine it fails with

A first chance exception of type "microsoft.directx.diretct3d.invalidcallexception" occured.

The code looks like this

texture = new Texture(renderer.Device, 720, 576, 0, Usage.None, Format.A8R8G8B8, Pool.Managed);

The pixelformat is the same as the device. I have tried with sizes which are a power of two and other memory pools as well as other usage modes. Allways the same error pops up.

I have enabled unmanaged debugging in vs2005 and am using debug version of dx. Still i do not get any more info in the error messages, than the above mentioned.

The question is of course.... what is wrong and or how can I get some more debug info

If it can make the problem more clear then the create device method is here.

private Device createAndSetupDevice(IntPtr handle)

{

//check the devices capabilities

Caps caps = Manager.GetDeviceCaps(0, DeviceType.Hardware);

if (caps.PrimitiveMiscCaps.SupportsSeparateAlphaBlend == false)

{

//MessageBox.Show("The device does not support seperate alpha blend");

return null;

}

PresentParameters presentParams = new PresentParameters();

presentParams.Windowed = true;

presentParams.SwapEffect = SwapEffect.Discard;

presentParams.EnableAutoDepthStencil = true;

presentParams.AutoDepthStencilFormat = DepthFormat.D24S8;

presentParams.BackBufferFormat = Format.A8R8G8B8;

Device newDevice = new Device(0, DeviceType.Hardware, handle,

CreateFlags.HardwareVertexProcessing, presentParams);

//no lighting enabled for now

newDevice.RenderState.Lighting = false;

//define view and projection

newDevice.Transform.View = Matrix.LookAtRH(new Vector3(0, 0, 0), new Vector3(0, 0, -1), new Vector3(0, 1, 0));

newDevice.Transform.Projection = Matrix.PerspectiveFovRH((float)Math.PI / 4.0F, 720F/576F, 0.1F, 150.0F);

newDevice.RenderState.AlphaBlendEnable = true;

newDevice.RenderState.SourceBlend = Blend.SourceAlpha;

newDevice.RenderState.DestinationBlend = Blend.InvSourceAlpha;

//implement properly

//newDevice.DeviceLost += new EventHandler(newDevice_DeviceLost);//kor det evt som en initmetode i den anden trad..

//set up proper blending

newDevice.RenderState.SeparateAlphaBlendEnabled=true;

newDevice.RenderState.AlphaBlendOperation=BlendOperation.Add;

newDevice.RenderState.AlphaDestinationBlend = Blend.DestinationAlpha;

newDevice.RenderState.AlphaSourceBlend = Blend.BlendFactor;

//TODO: validate that this does what it is suposed to do

//prepare a font for drawing 2d text on screen

onScreenFont = new Microsoft.DirectX.Direct3D.Font(newDevice,

new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, 20));

return newDevice;

}



Answer this question

Creating a new texture fails with "first chance exception"

  • Helloooo

    I am looking at the output windows.

    Yes it would seem that the gfxcards have different capabilietes.

    They are different in a lot of ways though, so it will be hard to point out the one specific difference which causes the error.


  • mcssSummer

    I might add an extra question since the original one aparently was too diffuse.

    Should I not be getting a more descriptive error than what I do get

    In the controlpanel I have selected the debug version of directx with max debug info.

    In my project in vs2005, I have enabled "debug unmanaged code".

    Still... the error is confusing and the description is not helping me at all.

    What could be possible causes of the create texture failing


  • JohnCNTS

    Is renderer.Device okay Any other function using it successfully
  • ianic

    It is fine. When creating the texture, the device is already rendering. Apart from that, the same exact code works on the other graphics card.


  • prashant_victory

    >Should I not be getting a more descriptive error than what I do get

    Where are you looking When you turn on the debug runtimes and 'unmanaged debugging' the errors go to the 'output' window. They don't change the very generic exceptions that you get.

    If it runs on one machine and not on the other then its either missing runtimes (unlikely if the app runs partially), different caps (could be - use the caps viewer to dump out the caps on both machines) or missing resources (use filemon from http://www.sysinternals.com to see what fine it is trying to load).



  • Hiran55681

    You are correct. Changing into a pow2 or one level mip map removed the error. I thought that I had tried it, but aparently not, or perhaps I was trying more than one change at the same time.
  • holstad

    You are using an ATI graphic card, right

    The problem is you try to create a texture with an non power of two size with a full mip map chain. This is not supported from a large number of GPUs.

    If you don’t need the mip maps you should use a 1 as mipmap count. If you need mipmaps you have to make sure that you use a power of 2 size on cards that don’t support it. Check the caps.



  • Chear

    i looked at the msdn doc on invalidcallexception
    it says that your problem is due to an invalid value for one of the params

    1. have you tried to implement another of the overloads for the method
    this eliminates format, height, width, numlevels as the culprit of your exception.

    2. tried changing the value for usage
    although ithink you put none, your createflags choice is hardwarevertexprocessing. it appears that createflags can also be set to MixedVertexProcessing - test whether the current card supports hardware vertex processing only.

    :) the laughing man strikes again



  • Creating a new texture fails with "first chance exception"