Unknown Error,直接出来那种
...exe has encountered a problem and needs to close. We are sorry for the inconvenience.
对话框。
没有错误消息。

解决方案 »

  1.   

    大家帮忙看看啊。
    随便在某个D3D程序中加入
        Bitmap bmp = new Bitmap(400, 300);
        Graphics graphics = Graphics.FromImage(bmp);
        graphics.DrawLine(new Pen(Color.Red, 5), 0, 0, 400, 300);
        texture = new Texture(device, bmp, Usage.Dynamic, Pool.Default);
    代码就会出错。
    使用
        texture = Texture.Texture.FromBitmap(device, bmp, 0, Pool.Default);
    也会出同样的错。
    大家帮忙看看是为什么啊。我现在只能使用将Image写入MemoryStream,然后再用Textureloader.FromStream导入,
    但是这样作的效率很低,程序有明显的停顿。
    请问大家怎么能解决这个问题啊。
      

  2.   

    正在看NBA……问题在于你的参数不对!texture =Texture.FromBitmap(dev, bmp,0, Pool.Managed);//最后一个参数还在看NBA……
      

  3.   

    我按你的改了还是不行啊。还是一个样子, 我几乎都要把Usage和Pool的各种组合都试了,都不行。郁闷死了。
    拉兄弟一把吧。兄弟我郁闷死了。
      

  4.   

    你的代码我使用vs2002+d3d和vs2003+d3d都调过,如果错误出在texture上,照我的改运行都不存在问题
    你当然可以:
    texture =new Texture(dev, bmp,0, Pool.Managed);Texture.FromBitmap在内部就是调用了上面这个构造函数。如果你的代码依然无法正常运行,那检查你代码的其他部分,比如device是如何创建的,还有你用什么ide?
      

  5.   

    private static Texture GetTexture(Bitmap bmp)
    {
    Texture texture = null;
             using (MemoryStream mmStream = new MemoryStream())
    {
        bmp.Save(mmStream, ImageFormat.Jpeg);
                 mmStream.Seek(0, SeekOrigin.Begin);
            texture = TextureLoader.FromStream(device, mmStream);
           mmStream.Close();
    }
    return texture;
    }
    我现在使用的代码时这样的,可以正常运行,但是速度慢,而且太愚蠢了。
    但是感觉基本可以证明bmp和device都是没有问题的。当我把代码改成:
    private static Texture GetTexture(Bitmap bmp)
    {
    Texture texture = null;
    texture = Texture.FromBitmap(device, bmp, 0, Pool.Managed);
    return texture;
    }
    运行时出现 System.NullReferenceException 这我就搞不清楚了,而且我跟踪device和bmp都不是空的。我不明白为什么会是这个异常。还有我使用的bmp是Bitmap类的成员这个有没有问题?
    看了几个代码好像都是从resource里面load的bitmap.
      

  6.   

    我在DirectX SDK的Tutorial2里面的Render里面加入
    Bitmap bmp = new Bitmap("c:\\1.jpg");
    Texture texture = Texture.FromBitmap(device, bmp, 0, Pool.Managed);
    这回出现的是Invalide Call Exception,
    在这里面应该device的创建肯定没有问题。
      

  7.   

    楼主给出的两种情况,我都在vs2003下试过了,没有问题。第一, System.NullReferenceException 不一定是device和bmp不是null就没有空引用了,你可以中止程序看看目前device内部成员是否发生该错误;第二,的确是in weird,同样的代码我这里没有问题:)而且产生一个Invalide Call Exception?不知何缘故了
      

  8.   

    texture =new Texture(dev, bmp,0, Pool.Managed);
    你只需这样就能够正确的创建texture么?
    会不会是我的显卡的问题?
      

  9.   

    以前哪个还是解决不了,大家有没有什么变通的方法
    我现在这个应用要频繁的更改Texture上面的图,
    比如在原来的Bitmap上面DrawString DrawImage DrawRectangle之类的事情,如果我没次操作之后都
             using (MemoryStream mmStream = new MemoryStream())
    {
        bmp.Save(mmStream, ImageFormat.Jpeg);
                 mmStream.Seek(0, SeekOrigin.Begin);
            texture = TextureLoader.FromStream(device, mmStream);
           mmStream.Close();
    }
    这样速度太慢了,每次都要大概占去400ms左右的时间.
    大家有什么办法提速么?