Skip to content

Commit

Permalink
Fixed destroy for renderer plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsmalm committed Aug 20, 2021
1 parent 7c25884 commit 3e863ab
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Setting `alphaMode` on `StandardMaterial` no longer changes `depthMask` or `renderSortType`.
- Setting `renderSortType` on `Material` also changes `depthMask`.

### Fixed
- Fixed an issue which caused a crash when application was destroyed.

## [0.9.7] - 2021-08-11
### Added
- New functionality to `PostProcessingSprite` so it can be used for rendering a 3D object as a 2D sprite.
Expand Down
8 changes: 8 additions & 0 deletions src/camera/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ export class Camera extends Container3D implements TransformId {
this.transform.rotationQuaternion.setEulerAngles(0, 180, 0)
}

destroy(options?: boolean | PIXI.IDestroyOptions) {
super.destroy(options)
if (this === Camera.main) {
// @ts-ignore It's ok, main camera was destroyed.
Camera.main = undefined
}
}

/**
* The camera's half-size when in orthographic mode. The visible area from
* center of the screen to the top.
Expand Down
5 changes: 4 additions & 1 deletion src/lighting/lighting-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Light } from "./light"
* A lighting environment represents the different lighting conditions for a
* specific object or an entire scene.
*/
export class LightingEnvironment {
export class LightingEnvironment implements PIXI.IRendererPlugin {
private _imageBasedLighting?: ImageBasedLighting

/** The lights affecting this lighting environment. */
Expand Down Expand Up @@ -44,6 +44,9 @@ export class LightingEnvironment {
get valid() {
return !this._imageBasedLighting || this._imageBasedLighting.valid
}

destroy() {
}
}

PIXI.Renderer.registerPlugin("lighting", <any>LightingEnvironment)
5 changes: 4 additions & 1 deletion src/picking/picking-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { PickingMap } from "./picking-map"
* is then used to map a mesh to a x/y coordinate. The picking manager is
* registered as a renderer plugin.
*/
export class PickingManager {
export class PickingManager implements PIXI.IRendererPlugin {
private _map: PickingMap
private _hitAreas: PickingHitArea[] = []

Expand Down Expand Up @@ -37,6 +37,9 @@ export class PickingManager {
})
}

destroy() {
}

/**
* Hit tests a area using the specified x/y coordinates.
* @param x The x coordinate.
Expand Down
5 changes: 5 additions & 0 deletions src/picking/picking-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export class PickingMap {
this._output.framebuffer.addDepthTexture()
}

destroy() {
this._output.destroy(true)
this._shader.destroy()
}

resize(width: number, height: number) {
this._pixels = new Uint8Array(width * height * 4)
this._output.resize(width, height)
Expand Down

0 comments on commit 3e863ab

Please sign in to comment.