playcanvas / playcanvas/engine

Destroying the scene on a cloned entity element mouseup event fires exception

Open
#3,340 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: ui
Dominant language
JavaScript
Stars
16.8k
Forks
2k
Avg merge
4h 32m
Merged PRs (30d)
222

Description

Forum thread: https://forum.playcanvas.com/t/cannot-read-property-active-of-null/21115
Project: https://playcanvas.com/editor/scene/1195817

The blue button is a runtime clone of the green button. Both buttons have a script that destroys the scene root on mouseup.

The green button when pressed is fine.

The blue button (clone) when pressed fires an exception:

Uncaught TypeError: Cannot read property 'active' of null
    at ButtonComponent.get (playcanvas-stable.dbg.js:43169)
    at ButtonComponent._determineVisualState (playcanvas-stable.dbg.js:48769)
    at ButtonComponent._updateVisualState (playcanvas-stable.dbg.js:48703)
    at ButtonComponent._onMouseUp (playcanvas-stable.dbg.js:48611)
    at ElementComponent.fire (playcanvas-stable.dbg.js:799)
    at ElementInput._fireEvent (playcanvas-stable.dbg.js:73923)
    at ElementInput._onElementMouseEvent (playcanvas-stable.dbg.js:73785)
    at ElementInput._handleUp (playcanvas-stable.dbg.js:73610)

Code that does the clone is: BrandSelectButtonsGroup

I believe this is due to the initialisation order difference from loading a hierarchy vs a clone.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the linked PlayCanvas scene and inspect the BrandSelectButtonsGroup clone path alongside ButtonComponent._onMouseUp and _determineVisualState in the stack trace. Compare cloned and loaded hierarchy initialization, then verify that destroying the scene root during mouseup no longer raises the reported null active-property exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.