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 call engine.destroy() crash in Script #1059

Merged
merged 7 commits into from
Sep 19, 2022

Conversation

GuoLei1990
Copy link
Member

@GuoLei1990 GuoLei1990 commented Sep 17, 2022

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)

Main modify:

  • Use delay destroy rule to ignore crash bug
  • Optimization Script logic.

@codecov-commenter
Copy link

codecov-commenter commented Sep 17, 2022

Codecov Report

Base: 33.70% // Head: 34.17% // Increases project coverage by +0.47% 🎉

Coverage data is based on head (3a395ec) compared to base (5982faf).
Patch coverage: 6.06% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1059      +/-   ##
==========================================
+ Coverage   33.70%   34.17%   +0.47%     
==========================================
  Files         334      334              
  Lines       14458    14460       +2     
  Branches     2216     2212       -4     
==========================================
+ Hits         4873     4942      +69     
+ Misses       9058     8982      -76     
- Partials      527      536       +9     
Impacted Files Coverage Δ
packages/core/src/2d/sprite/Sprite.ts 29.50% <ø> (ø)
packages/core/src/Script.ts 38.46% <0.00%> (+18.46%) ⬆️
packages/core/src/input/pointer/Pointer.ts 50.00% <ø> (ø)
packages/core/src/Engine.ts 59.88% <3.84%> (-2.24%) ⬇️
packages/core/src/Entity.ts 75.00% <33.33%> (-0.44%) ⬇️
packages/math/src/Color.ts 89.28% <0.00%> (-3.58%) ⬇️
packages/math/src/Matrix.ts 89.76% <0.00%> (+0.14%) ⬆️
packages/math/src/Quaternion.ts 81.25% <0.00%> (+0.31%) ⬆️
packages/core/src/Camera.ts 13.90% <0.00%> (+3.97%) ⬆️
packages/core/src/ComponentsManager.ts 34.51% <0.00%> (+7.07%) ⬆️
... and 5 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

}
componentsManager.removeOnUpdateScript(this);
componentsManager.removeOnLateUpdateScript(this);
componentsManager.removeOnPhysicsUpdateScript(this);
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to consider the case of -1, is it guaranteed not to have?

Copy link
Member Author

Choose a reason for hiding this comment

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

After this PR #1055 fixed, call onDisable before onEnable maybe never happen.

Copy link
Collaborator

@cptbtptpbcptdtptp cptbtptpbcptdtptp Sep 19, 2022

Choose a reason for hiding this comment

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

After this PR #1055 fixed, call onDisable before onEnable maybe never happen.

Even if fixed, the subscript of onUpdate may be -1.

if (this.onUpdate !== prototype.onUpdate) {
        componentsManager.addOnUpdateScript(this);
}

Copy link
Member Author

Choose a reason for hiding this comment

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

done

if (this._waittingDestroy) {
this._destroy();
}
componentsManager.handlingInvalidScripts();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not put it before destroy?

Copy link
Member Author

@GuoLei1990 GuoLei1990 Sep 19, 2022

Choose a reason for hiding this comment

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

That not work, this._sceneManager._destroy(); is in this._destroy()

Copy link
Collaborator

@cptbtptpbcptdtptp cptbtptpbcptdtptp Sep 19, 2022

Choose a reason for hiding this comment

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

There is still a situation:

onPointerDown() {
    this.entity.destroy();
    this.engine.destroy();
}

onDestroy() {
    console.log('Destroyed at', this.engine.time.nowTime);
}

Copy link
Member Author

Choose a reason for hiding this comment

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

done

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

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

@GuoLei1990 GuoLei1990 merged commit cb369c6 into galacean:main Sep 19, 2022
GuoLei1990 added a commit to GuoLei1990/galacean-engine that referenced this pull request Sep 22, 2022
* main:
  v0.8.0-beta.26
  feat: shader add properties get ability (galacean#1060)
  Fix scene root entity destroy bug (galacean#1062)
  Fix call `engine.destroy()` crash  in `Script` (galacean#1059)
  Fix physics system stablity (galacean#1047)
  v0.8.0-beta.25
  Fix script onDisable() error call bug (galacean#1055)
  fix: sprite transform error when rotates (galacean#1053)
  feat: remove throw (galacean#1052)
  Update README.md
  Update README.md
  v0.8.0-beta.24
  Fix `TextRenderer` render error (galacean#1040)
  v0.8.0-beta.23
@GuoLei1990 GuoLei1990 deleted the pr/fix-script-bug branch September 22, 2022 07:14
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.

Engine destroy all things when call engine.destroy() in Script callback but still call engine.update()
4 participants