小编tbr*_*dge的帖子

为什么此代码抛出System.ExecutionEngineException

背景: 我使用DirectX 9.0托管库将3d点数组转换为2d屏幕坐标.为了速度,我使用UnsafeNativeMethods来完成所有的转换.

问题: 如果我的自定义行裁剪功能被使用,我的应用程序就会死掉,而不会抛出任何异常,我花了一段时间才弄清楚它是无法捕获的 System.ExecutionEngineException.由于剪切功能的最后两行,我已经缩小了它的范围.

List<Vector3> verticesAfterClipping = new List<Vector3>;
public unsafe void ClipLine(Line lineToClip)
{
    this.verticesAfterClipping.Clear();

    // Clipping algorithm happens here... (this is psuedo-code of what it does)
    foreach(Vertex in lineToClip.Vertices)
    {
        bool thisIsClipped =   // Set to whether this vertex is clipped
        bool lastWasClipped =  // Set to whether last vertex was clipped

        if(thisIsClipped == false && lastWasClipped == true)
        {
            verticesAfterClipping.Add( /* intersection on clipping plane */ );
            verticesAfterClipping.Add( /* thisVertex */ );
        } …
Run Code Online (Sandbox Code Playgroud)

c# exception managed-directx

11
推荐指数
1
解决办法
3万
查看次数

奇怪的lambda行为

我偶然发现了这篇文章并发现它非常有趣,所以我自己进行了一些测试:

测试一:

List<Action> actions = new List<Action>();

for (int i = 0; i < 5; ++i)
    actions.Add(() => Console.WriteLine(i));

foreach (Action action in actions)
    action();
Run Code Online (Sandbox Code Playgroud)

输出:

5
5
5
5
5
Run Code Online (Sandbox Code Playgroud)

测试二:

List<Action> actions = new List<Action>();

for (int i = 0; i < 5; ++i)
{
    int j = i;
    actions.Add(() => Console.WriteLine(j));
}

foreach (Action action in actions)
    action();
Run Code Online (Sandbox Code Playgroud)

输出:

0
1
2
3
4
Run Code Online (Sandbox Code Playgroud)

根据文章,在Test One中,所有lambdas都包含一个引用i,使得它们全部输出5.这是否意味着我在Test Two中得到了预期的结果,因为int为每个lambda表达式创建了一个new ?

c# lambda closures

11
推荐指数
2
解决办法
234
查看次数

从基类方法返回派生类型

我有一个类似于这个的类层次结构:

public class Base
{
    private List<string> attributes = new List<string>();

    public T WithAttributes<T>(params string[] attributes)
        where T : Base
    {
        this.attributes.AddRange(attributes);
        return this as T;
    }
}

public class Derived : Base
{
}
Run Code Online (Sandbox Code Playgroud)

我想以Base.WithAttributesfluent-api样式语法从派生类调用,并返回派生实例,如下例所示.

void Main()
{
    Derived d = new Derived();

    // CS0411 The type arguments for method 'UserQuery.Base.WithAttributes<T>(params string[])' cannot be inferred from the usage.
    d.WithAttributes("one", "two"); 

    // Works, but type arguments must be explicity specified. 
    d.WithAttributes<Derived>("one", "two");

    // Works without explicitly specifying, but …
Run Code Online (Sandbox Code Playgroud)

c# generics

8
推荐指数
1
解决办法
2779
查看次数

我可以更快地复制这个数组吗?

难道这就是绝对速度最快的,我可以有可能复制BitmapByte[]C#

如果有一种更快的方式我很想知道!

const int WIDTH = /* width */;
const int HEIGHT = /* height */;


Bitmap bitmap = new Bitmap(WIDTH, HEIGHT, PixelFormat.Format32bppRgb);
Byte[] bytes = new byte[WIDTH * HEIGHT * 4];

BitmapToByteArray(bitmap, bytes);


private unsafe void BitmapToByteArray(Bitmap bitmap, Byte[] bytes)
{
    BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, WIDTH, HEIGHT), ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);

    fixed(byte* pBytes = &bytes[0])
    {
        MoveMemory(pBytes, bitmapData.Scan0.ToPointer(), WIDTH * HEIGHT * 4);
    }

    bitmap.UnlockBits(bitmapData);
}

[DllImport("Kernel32.dll", EntryPoint = …
Run Code Online (Sandbox Code Playgroud)

c# optimization copy bytearray bitmap

6
推荐指数
2
解决办法
3564
查看次数

PHP - 在多维数组中查找最小值/最大值

我需要在PHP中找到多维数组中的最小值和最大值,我有我认为可以在下面工作但它一直给我一个解析错误,这是功课,我不是要求任何人为我做这个但我是一个初学者和任何帮助将不胜感激.

<?php

/* 2 dimensional array in PHP - strictly an array of arrays */

$multable[] = array("11", "12", "15", "22", "41", "42");  
$multable[] = array("6", "7", "16", "17", "22", "23");  
$multable[] = array("1", "15", "16", "20", "22", "3");  


# ---------------------------------------------
?>
<html>
<head>
<title>An array of arrays in PHP</title>
</head>
<body bgcolor=white>
<h2>Two dimensional array</h2><br>
<table border=2 cellpadding=2 cellspacing=2>

<?php

/* display a table from a 2D array */
for ($j=0;$j<3;$j++) {
    print "<tr>";
    for ($k=0;$k<6;$k++) {
            echo "<td>",$multable[$j][$k],"</td>"; …
Run Code Online (Sandbox Code Playgroud)

php

4
推荐指数
1
解决办法
6546
查看次数

DirectX Z-Buffer问题

有谁知道可能导致我在C#Managed DirectX应用程序中看到的奇怪工件的原因.以下是我遇到的问题的屏幕截图:

在此输入图像描述

你正在看的是一些平面下面有一个平面的地形.

  • 在左边你可以看到地形前面的平面,即使它不应该是可见的(它在下面)
  • 在中间有一个过渡阶段,你可以看到我所谓的'百叶窗'
  • 在右侧,它显示正确

这必须是Z-Buffer问题,但我无法解决它.有没有其他人遇到同样的问题?它让我疯了!

c# directx xna zbuffer managed-directx

3
推荐指数
1
解决办法
568
查看次数

DirectX9中的简单HLSL发光/模糊效果

我一直在努力寻找任何资源来帮助我使用高级着色器语言和DirectX 9托管库编写简单的辉光/模糊着色器.

我需要做的就是将一系列CustomVertex.TransformedColored顶点绘制成简单的线条,然后通过HLSL效果模糊/发光.

我已经在互联网上搜索了大约三天的一些结果,但我找不到一个非常好的教程或示例.我对HLSL有一个基本的了解,但我不太了解如何编写这个着色器(我已经阅读了3本DirectX书籍中的HLSL章节).

这是一些(删节)代码:

CustomVertex.TransformedColored[] glowVertices = new CustomVertex.TransformedColored[4];
glowVertices[0] = new CustomVertex.TransformedColored(random.Next(this.render.Width), random.Next(this.render.Height), 1, 1, Color.Cyan.ToArgb());
glowVertices[1] = new CustomVertex.TransformedColored(random.Next(this.render.Width), random.Next(this.render.Height), 1, 1, Color.Blue.ToArgb());
glowVertices[2] = new CustomVertex.TransformedColored(random.Next(this.render.Width), random.Next(this.render.Height), 1, 1, Color.Cyan.ToArgb());
glowVertices[3] = new CustomVertex.TransformedColored(random.Next(this.render.Width), random.Next(this.render.Height), 1, 1, Color.Blue.ToArgb());

this.device.BeginScene();
int passes = this.glowEffect.Begin(0);
for (int i = 0; i < passes; i++)
 {
     this.glowEffect.BeginPass(i);
     this.device.DrawUserPrimitives(PrimitiveType.LineStrip, glowVertices.Length - 1, glowVertices);
     this.glowEffect.EndPass();
 }
 this.glowEffect.End();
 this.device.EndScene();
Run Code Online (Sandbox Code Playgroud)

我想我不是在寻找HLSL特定部分的帮助,考虑到我要发布的问题和代码数量,我真的只是寻找一些帮助寻找资源!

c# hlsl glow directx-9 managed-directx

2
推荐指数
1
解决办法
5148
查看次数

将List <List <int >>转换为double [] []

有没有办法转换List<List<int>>double[][]使用LINQ?

我已经想出如何从中走出来List<List<int>>,int[][]但我仍然坚持演员阵容.这是我到目前为止:

List<List<int>> ints = new List<List<int>>()
{
    new List<int>(){0, 1, 2},
    new List<int>(){0, 1, 2},
    new List<int>(){0, 1, 2},
};

// int[][]
ints.Select(x => x.ToArray()).ToArray();
Run Code Online (Sandbox Code Playgroud)

c# linq

2
推荐指数
1
解决办法
596
查看次数