Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix camera crash error in Script #1873

Merged
merged 6 commits into from
Nov 13, 2023

Conversation

GuoLei1990
Copy link
Member

@GuoLei1990 GuoLei1990 commented Nov 10, 2023

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Demo:

/**
 * @title GLTF Basic
 * @category Basic
 */
import { OrbitControl } from "@galacean/engine-toolkit-controls";
import { Camera, GLTFResource, Renderer, Script, Vector3, WebGLEngine } from "@galacean/engine";

WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
  engine.canvas.resizeByClientSize();

  engine.canvas.resizeByClientSize();
  const scene = engine.sceneManager.activeScene;
  const rootEntity = scene.createRootEntity();

  // init camera
  const cameraEntity = rootEntity.createChild("camera");
  cameraEntity.addComponent(Test).camera= cameraEntity.addComponent(Camera);

  const pos = cameraEntity.transform.position;
  pos.set(0, 0, 10);
  cameraEntity.transform.position = pos;
  cameraEntity.transform.lookAt(new Vector3(0, 0, 0));

  const testCameraEntity = rootEntity.createChild("testCamera");
 testCameraEntity.addComponent(Camera);

  engine.run();
});


export class Test extends Script {
  private _camera: Camera;

  set camera(value: Camera) {
    this._camera = value;
  }
  
  onBeginRender(camera: Camera): void {
    this._camera && (this._camera.enabled = false);
    debugger;
  }
}

@GuoLei1990 GuoLei1990 added the bug Something isn't working label Nov 10, 2023
Copy link

codecov bot commented Nov 10, 2023

Codecov Report

Attention: 118 lines in your changes are missing coverage. Please review.

Comparison is base (f7bec17) 66.71% compared to head (5cd8893) 66.90%.
Report is 12 commits behind head on dev/1.2.

❗ Current head 5cd8893 differs from pull request most recent head 36fee14. Consider uploading reports for the commit 36fee14 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           dev/1.2    #1873      +/-   ##
===========================================
+ Coverage    66.71%   66.90%   +0.18%     
===========================================
  Files          472      471       -1     
  Lines        23799    23834      +35     
  Branches      3393     3399       +6     
===========================================
+ Hits         15877    15945      +68     
+ Misses        6732     6697      -35     
- Partials      1190     1192       +2     
Files Coverage Δ
packages/core/src/2d/sprite/SpriteMask.ts 87.50% <100.00%> (+0.22%) ⬆️
packages/core/src/DisorderedArray.ts 85.71% <100.00%> (+0.38%) ⬆️
packages/core/src/RenderPipeline/RenderQueue.ts 67.01% <100.00%> (+19.73%) ⬆️
packages/core/src/Scene.ts 80.86% <ø> (+0.24%) ⬆️
packages/core/src/asset/AssetPromise.ts 88.40% <100.00%> (+0.90%) ⬆️
packages/shader-lab/src/Ast2GLSLUtils.ts 66.66% <100.00%> (+9.52%) ⬆️
packages/shader-lab/src/AstNodeUtils.ts 81.08% <ø> (+2.82%) ⬆️
packages/core/src/Engine.ts 87.42% <88.88%> (-0.28%) ⬇️
packages/core/src/input/pointer/PointerManager.ts 92.43% <75.00%> (+0.04%) ⬆️
packages/core/src/ComponentsManager.ts 79.71% <84.21%> (+0.71%) ⬆️
... and 9 more

... and 13 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@GuoLei1990 GuoLei1990 marked this pull request as draft November 10, 2023 10:35
@GuoLei1990 GuoLei1990 linked an issue Nov 10, 2023 that may be closed by this pull request
@GuoLei1990 GuoLei1990 marked this pull request as ready for review November 10, 2023 10:52
@GuoLei1990 GuoLei1990 changed the title Fix camera error bug Fix camera crash error in Script Nov 13, 2023
const { _activeCameras: cameras } = scene;
const { _activeCameras: cameras } = scene._componentsManager;
const elements = cameras._elements;

for (let j = cameras.length - 1; j >= 0; j--) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cameras should be elements?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's DisorderedArray

continue;
}

cameras.forEach(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why use forEach

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is DisorderedArray

Copy link
Member

@singlecoder singlecoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Collaborator

@cptbtptpbcptdtptp cptbtptpbcptdtptp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@GuoLei1990 GuoLei1990 merged commit 8484abb into galacean:dev/1.2 Nov 13, 2023
5 checks passed
@GuoLei1990 GuoLei1990 deleted the pr/fix-camera-crash branch November 17, 2023 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When make camera disable in _render function will error
3 participants