CodeSampleX

示例

three 0.185.1: Instantiating CanvasTexture marks it immediately for update with version 1, while reading needsUpdate yields undefined because needsUpdate is a setter-only property that increments version counters.

已验证示例 — npm three 0.185.1: Instantiating CanvasTexture marks it immediately for update with version 1, while reading needsUpdate yields undefined because…

sha256:961598ac78d3b67c9b8b2e7ca83648daa11ea9e976e9ef72e5fd7dc4fdc5a4a4

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
3
构建过它的签名密钥
3
声明的环境 node linux x64 node node npm

验证运行环境

环境 契约 阶段 运行日期
node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-17
node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-18
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-09-07

案例

HOW
目标
Instantiating CanvasTexture marks it immediately for update with version 1, while reading needsUpdate yields undefined because needsUpdate is a setter-only property that increments version counters.
包
符号
  • CanvasTexture
环境
node
创建时间
2026-08-17T09:04:47Z

契约

  1. CanvasTexture constructor triggers needsUpdate to initialize version and source.version at 1 rather than 0, while reading needsUpdate evaluates to undefined because needsUpdate is a setter-only property on Texture.
  2. Setting needsUpdate to true increments both texture.version and source.version by 1, whereas setting it to false leaves versions unchanged.
  3. Cloning a CanvasTexture shares the source instance and executes copy, which marks needsUpdate on the clone and increments the shared source.version.

文件

  • NOTES.md
  • csx.json
  • package-lock.json
  • package.json
  • test/contract.mjs

下载源代码构件 (tar.gz)

源代码

NOTES.md
# three — CanvasTexture Lifecycle and Update Versioning

## Known Solution Search
`search_known_solution` returned `NO_SAFE_MATCH` for `pkg:npm/three@0.185.1` and symbol `CanvasTexture`.

## Pinned Release
- Package: `three`
- Release: `0.185.1` (npm)

## Observed Behavior
1. **Initial Version State**: When `new CanvasTexture(canvas)` is created, its constructor sets `this.needsUpdate = true` immediately. This increments both `canvasTexture.version` and `canvasTexture.source.version` to `1`. In contrast, a base `new Texture(canvas)` starts with `version = 0` and `source.version = 0`.
2. **Setter-Only Property**: On `Texture.prototype`, `needsUpdate` is defined strictly with a setter (`set needsUpdate(value)`) and no getter. Consequently, reading `texture.needsUpdate` evaluates to `undefined` rather than a boolean.
3. **Counter Incrementing**: Setting `texture.needsUpdate = true` increments the internal `version` and `source.version` integers by 1. Setting `texture.needsUpdate = false` performs no operation and leaves both version counters unchanged.
4. **Cloning and Shared Source**: Calling `.clone()` on a `CanvasTexture` instantiates a new instance sharing the original's `Source` object. The clone's `.copy()` step sets `this.needsUpdate = true`, which increments the clone's `version` to `2` and increments the shared `source.version` counter.

## Failure Mode
- **Silent failure on boolean checks**: Code that attempts to check whether a texture requires an update via `if (texture.needsUpdate)` receives `undefined` (falsy), leading downstream logic to skip GPU re-upload handling or condition checks.
- **Assertion failure on version counters**: Tests or internal systems expecting `version` or `source.version` to initialize at `0` fail with mismatch errors against the initialized value of `1`.
csx.json
{"case":{"believed":"CanvasTexture initializes with version 0 like Texture, and reading needsUpdate returns a boolean indicating whether the texture is flagged for update.","caseId":"case:sha256:af5e1997a564681bec79128207bba8dfcd228d9a8fc9e963fac03682c5d7b3a6","contract":["CanvasTexture constructor triggers needsUpdate to initialize version and source.version at 1 rather than 0, while reading needsUpdate evaluates to undefined because needsUpdate is a setter-only property on Texture.","Setting needsUpdate to true increments both texture.version and source.version by 1, whereas setting it to false leaves versions unchanged.","Cloning a CanvasTexture shares the source instance and executes copy, which marks needsUpdate on the clone and increments the shared source.version."],"goal":"Instantiating CanvasTexture marks it immediately for update with version 1, while reading needsUpdate yields undefined because needsUpdate is a setter-only property that increments version counters.","kind":"HOW","packages":["pkg:npm/three@0.185.1"],"schemaVersion":1,"symbols":["CanvasTexture"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"node","os":"linux","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/three@0.185.1"],"schemaVersion":1,"symbols":["CanvasTexture"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "three-canvastexture-contract",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "three-canvastexture-contract",
      "version": "1.0.0",
      "dependencies": {
        "three": "0.185.1"
      }
    },
    "node_modules/three": {
      "version": "0.185.1",
      "resolved": "https://registry.npmjs.org/three/-/three-0.185.1.tgz",
      "integrity": "sha512-5aojFCXKwnjBRZvUnt3WFfEcvUJgkN5LlijRFN95hMy8WVkG4I0QNcJE+OuWvuJ0bOdStrbfXn0pkd6/QyiAlg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "three-canvastexture-contract",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": {
    "three": "0.185.1"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import * as THREE from 'three';

// 1. CanvasTexture inherits from Texture and sets isCanvasTexture flag
const mockCanvas = { width: 256, height: 128 };
const ct = new THREE.CanvasTexture(mockCanvas);
const baseTexture = new THREE.Texture(mockCanvas);

assert.strictEqual(ct.isCanvasTexture, true, 'CanvasTexture must have isCanvasTexture flag set to true');
assert.strictEqual(ct.isTexture, true, 'CanvasTexture must inherit isTexture flag');
assert.strictEqual(ct instanceof THREE.Texture, true, 'CanvasTexture must be an instance of Texture');
assert.strictEqual(ct instanceof THREE.CanvasTexture, true, 'CanvasTexture must be an instance of CanvasTexture');

// 2. Base Texture initializes with version 0 and source.version 0, while CanvasTexture immediately runs needsUpdate in constructor
assert.strictEqual(baseTexture.version, 0, 'Base Texture must start with version 0');
assert.strictEqual(baseTexture.source.version, 0, 'Base Texture source must start with version 0');
assert.strictEqual(ct.version, 1, 'CanvasTexture constructor must increment version to 1 upon creation');
assert.strictEqual(ct.source.version, 1, 'CanvasTexture constructor must increment source.version to 1 upon creation');

// 3. needsUpdate is a setter-only property on Texture.prototype, so reading it returns undefined rather than a boolean
assert.strictEqual(ct.needsUpdate, undefined, 'Reading needsUpdate on CanvasTexture must return undefined');
assert.strictEqual(baseTexture.needsUpdate, undefined, 'Reading needsUpdate on Texture must return undefined');

const descriptor = Object.getOwnPropertyDescriptor(THREE.Texture.prototype, 'needsUpdate');
assert.ok(descriptor, 'needsUpdate descriptor must exist on Texture.prototype');
assert.strictEqual(typeof descriptor.get, 'undefined', 'needsUpdate descriptor must not define a getter');
assert.strictEqual(typeof descriptor.set, 'function', 'needsUpdate descriptor must define a setter function');

// 4. Setting needsUpdate = true increments version counters; setting false is a no-op
ct.needsUpdate = true;
assert.strictEqual(ct.version, 2, 'Setting needsUpdate = true must increment version from 1 to 2');
assert.strictEqual(ct.source.version, 2, 'Setting needsUpdate = true must increment source.version from 1 to 2');
assert.strictEqual(ct.needsUpdate, undefined, 'needsUpdate property remains undefined after assignment');

ct.needsUpdate = false;
assert.strictEqual(ct.version, 2, 'Setting needsUpdate = false must not change version');
assert.strictEqual(ct.source.version, 2, 'Setting needsUpdate = false must not change source.version');

// 5. Source data and dimensions
assert.strictEqual(ct.image, mockCanvas, 'ct.image getter must return underlying canvas reference');
assert.strictEqual(ct.source.data, mockCanvas, 'ct.source.data must reference canvas');
assert.strictEqual(ct.width, 256, 'ct.width must report canvas width');
assert.strictEqual(ct.height, 128, 'ct.height must report canvas height');

// 6. Cloning shares the Source object and increments clone version and shared source.version
const cloned = ct.clone();
assert.strictEqual(cloned.isCanvasTexture, true, 'Cloned object must be a CanvasTexture');
assert.strictEqual(cloned.source, ct.source, 'Clone must share the exact same Source instance');
assert.strictEqual(cloned.version, 2, 'Cloned CanvasTexture version becomes 2 after constructor and copy');
assert.strictEqual(ct.source.version, 3, 'Copy on clone must increment the shared source.version to 3');

原始种子者

csx-seed