小编Max*_*kov的帖子

为什么我需要 depthBuffer 来使用 RenderTexture?

我认为我不太了解 Unity 渲染引擎。

我使用RenderTexture生成截图(我需要稍后管理它):

    screenshotRenderTexture = new RenderTexture(screenshot.width, screenshot.height, depthBufferBits, RenderTextureFormat.Default);
    screenshotRenderTexture.Create();

    RenderTexture currentRenderTexture = RenderTexture.active;
    RenderTexture.active = screenshotRenderTexture;

    Camera[] cams = Camera.allCameras;

    System.Array.Sort(
            cams,
            delegate(Camera cam1, Camera cam2)
            {
                // It's easier than write float to int conversion that won't floor
                // depth deltas under 1 to zero and will correctly work with NaNs
                if (cam1.depth < cam2.depth)
                    return -1;
                else if (cam1.depth > cam2.depth)
                    return 1;
                else return 0;
            }
        );

    foreach(Camera cam in cams)
    {
        cam.targetTexture = …
Run Code Online (Sandbox Code Playgroud)

c# camera render unity-game-engine depth-buffer

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

如何以不可变的方式实现缓存?

我已经阅读并听到了很多关于不变性的好东西,所以我决定在我的一个爱好项目中尝试一下.我将所有字段都声明为readonly,并使所有通常会改变对象的方法返回一个新的修改版本.

它运行良好,直到我遇到一种情况,一种方法应该通过外部协议返回有关对象的某些信息而不修改它,但同时可以通过修改内部结构来优化.特别是,这在联合查找算法中使用树路径压缩时会发生.

当用户调用时int find(int n),对象显示为未修改为局外人.它在概念上代表相同的实体,但它的内部字段被改变以优化运行时间.

我怎样才能以不可变的方式实现它?

c# immutability

5
推荐指数
1
解决办法
380
查看次数

为什么RESTful API中通常不使用RSA签名?

我开发了一个简单的应用程序,该应用程序至少不使用任何第三方授权。我想创建一个可供iOS / Android /任何客户端使用的RESTful API,因此,我阅读了许多有关RESTful API实现的信息。但是,实现它们的通常方法包括发送某种用于签名请求的安全“令牌”。这使该API容易受到中间人攻击,建议使用HTTPS来解决该问题。

但是,阅读所有这些使我感到奇怪,为什么不为此使用私钥/公钥签名(如RSA)。这样,客户端将根据密码生成私钥和公钥,发送注册时的公钥并将私钥保留在客户端上,即使有人掌握了服务器和客户端之间的所有通信,他仍然不会不能冒充客户。

但是我对密码学和安全性几乎一无所知,所以一定有原因导致我没想到没有使用这种方法,对吗?

api signing rsa restful-authentication

5
推荐指数
1
解决办法
1282
查看次数

ld:找不到库

我正在尝试构建一个依赖于SDL2库的项目.我用自制软件安装并链接了它:

> ls /usr/local/lib | grep SDL2
libSDL2-2.0.0.dylib
libSDL2.a
libSDL2.dylib
libSDL2_test.a
libSDL2main.a
Run Code Online (Sandbox Code Playgroud)

我还添加了/usr/local/lib我的/etc/paths~/.bash_profile也:

> cat /etc/paths
/usr/local/lib
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试构建项目时,我仍然会收到此错误:

error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' (...) '-lSDL2'
ld: library not found for -lSDL2
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

为什么会发生,我该如何解决?

linker build ld

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

为什么在使用返回值时将 0 移到堆栈中?

我正在试验反汇编clang简单 C 程序的二进制文件(用 编译-O0),我对生成的某个指令感到困惑。

这是两个main带有标准参数的空函数,其中一个返回值,另一个不返回:

// return_void.c
void main(int argc, char** argv)
{
}

// return_0.c
int main(int argc, char** argv)
{
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

现在,当我拆卸它们的组件时,它们看起来相当不同,但有一行我不明白:

return_void.bin:
(__TEXT,__text) section
_main:
0000000000000000    pushq   %rbp
0000000000000001    movq    %rsp, %rbp
0000000000000004    movl    %edi, -0x4(%rbp)
0000000000000007    movq    %rsi, -0x10(%rbp)
000000000000000b    popq    %rbp
000000000000000c    retq

return_0.bin:
(__TEXT,__text) section
_main:
0000000100000f80    pushq   %rbp                
0000000100000f81    movq    %rsp, %rbp          
0000000100000f84    xorl    %eax, %eax          # We return with EAX, so we clean it …
Run Code Online (Sandbox Code Playgroud)

c assembly clang calling-convention disassembly

5
推荐指数
1
解决办法
414
查看次数

强类型语言是否有承诺规范?

承诺/ A +规格为优秀落实承诺,但它使用JavaScript的弱类型很多.Promise的规范是否设计了具有强大静态类型的语言,例如C#?

javascript specifications strong-typing promise

5
推荐指数
1
解决办法
154
查看次数

为什么Boolean.class.newInstance()会抛出异常?

我认为sunject非常不言自明.我使用JDK 1.6.0更新26,并创建了一个只有一行的新项目来确认这一点:

Boolean.class.newInstance();
Run Code Online (Sandbox Code Playgroud)

它会抛出以下内容:

Exception in thread "main" java.lang.InstantiationException: java.lang.Boolean
    at java.lang.Class.newInstance0(Class.java:340)
    at java.lang.Class.newInstance(Class.java:308)
Run Code Online (Sandbox Code Playgroud)

它会假设失败吗?如果是这样,为什么?

java

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

Apple Core Data教程中的奇怪错误

我正在做Apple Core数据教程,并且在第一次建议我构建项目时,我收到了这个错误:

Ld /Users/user/Library/Developer/Xcode/DerivedData/Locations-fajvunxiruohofbhzimrgekrpnqh/Build/Products/Debug-iphonesimulator/Locations.app/Locations normal i386
    cd "/Users/user/Documents/xcode projects/Locations"
    setenv MACOSX_DEPLOYMENT_TARGET 10.6
    setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk -L/Users/user/Library/Developer/Xcode/DerivedData/Locations-fajvunxiruohofbhzimrgekrpnqh/Build/Products/Debug-iphonesimulator -F/Users/user/Library/Developer/Xcode/DerivedData/Locations-fajvunxiruohofbhzimrgekrpnqh/Build/Products/Debug-iphonesimulator -filelist /Users/user/Library/Developer/Xcode/DerivedData/Locations-fajvunxiruohofbhzimrgekrpnqh/Build/Intermediates/Locations.build/Debug-iphonesimulator/Locations.build/Objects-normal/i386/Locations.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -framework UIKit -framework Foundation -framework CoreGraphics -framework CoreData -o /Users/user/Library/Developer/Xcode/DerivedData/Locations-fajvunxiruohofbhzimrgekrpnqh/Build/Products/Debug-iphonesimulator/Locations.app/Locations

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_CLLocationManager", referenced from:
      objc-class-ref in RootViewController.o
  "_kCLLocationAccuracyNearestTenMeters", referenced from:
      -[RootViewController locationManager] in RootViewController.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

我使用的是XCode 4.0.2,Mac OS X 10.6.8.这可能是什么原因?我一步一步地按照教程进行操作,完全不知道出了什么问题.

iphone xcode ios xcode4

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

如何创建和初始化不可变数组?

我想创建一个数组。我不需要数组是可变的,并且在创建时,我拥有计算数组第 i 个成员所需的所有信息。但是,无法弄清楚如何在 Rust 中创建不可变数组。

这是我现在所拥有的:

let mut my_array: [f32; 4] = [0.0; 4];
for i in 0..4 {
    // some calculation, doesn't matter what exactly
    my_array[i] = some_function(i);
}
Run Code Online (Sandbox Code Playgroud)

这就是我想要的:

let my_array: [f32; 4] = array_factory!(4, some_function);
Run Code Online (Sandbox Code Playgroud)

我怎样才能在 Rust 中实现这一点?

arrays immutability rust

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

Google Cloud Function 部署错误:提供的函数不是可加载的模块

我正在尝试从头开始使用 Typescript 构建我的 GCF 项目。我对这个项目(和这个问题)的目标是了解云功能的工作原理并手动执行所有设置步骤,这就是我不复制任何示例代码或使用自动化工具的原因。

首先,这是我的src/index.ts文件:

export const helloWorld = (req: any, res: any) => {
    res.send('Hello, world 4');
}
Run Code Online (Sandbox Code Playgroud)

运行打字稿编译器后,我得到了这个dist/index.js文件,这似乎完全合理:

"use strict";
exports.__esModule = true;
exports.helloWorld = function (req, res) {
    res.send('Hello, world 4');
};
Run Code Online (Sandbox Code Playgroud)

package.json的设置指向这个文件:

{
  "main": "dist/index.js",
  "scripts": {
    "start": "npx tsc-watch --onSuccess 'npx @google-cloud/functions-framework --target=helloWorld'",
    "deploy": "gcloud functions deploy helloWorld --runtime nodejs10 --trigger-http"
  },
  "dependencies": {
    "@google-cloud/functions-framework": "^1.1.2",
    "tsc-watch": "^2.2.1",
    "typescript": "^3.5.3"
  }
}
Run Code Online (Sandbox Code Playgroud)

我想先设置本地测试环境,所以我使用了函数框架。当我运行它时,一切正常:

$ npx @google-cloud/functions-framework …
Run Code Online (Sandbox Code Playgroud)

node.js typescript google-cloud-functions

4
推荐指数
2
解决办法
3861
查看次数