Skip to content

Commit f4a1076

Browse files
committed
fix:Increase handling for effect.destroyed == true.(增加对effect.destroyed==true 处理)
1 parent bbe8096 commit f4a1076

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

src/layaAir/laya/display/PostProcess2D.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ export class PostProcess2D extends EventDispatcher {
142142
* @param effect 要添加的后期处理效果。
143143
*/
144144
addEffect<T extends PostProcess2DEffect>(effect: T): T | null {
145+
if (effect.destroyed) {
146+
console.error("the target effect is destroyed", effect);
147+
return null;
148+
}
149+
145150
if (effect.singleton && this.getEffect((effect as any).constructor)) {
146151
console.error("the target effect is a singleton", effect);
147152
return null;
@@ -160,11 +165,11 @@ export class PostProcess2D extends EventDispatcher {
160165
* @param effect 要移除的后期处理效果。
161166
*/
162167
removeEffect(effect: PostProcess2DEffect) {
163-
effect.destroy();
164168

165169
let index = this._effects.indexOf(effect);
166170
if (index !== -1) {
167171
this._effects.splice(index, 1);
172+
effect.destroy();
168173
this._onChangeRender();
169174
}
170175
}
@@ -179,7 +184,7 @@ export class PostProcess2D extends EventDispatcher {
179184
this._context.destination = this._context.source;
180185
for (var i: number = 0, n: number = this._effects.length; i < n; i++) {
181186
let effect = this._effects[i];
182-
if (effect.active) {
187+
if (effect.active && !effect.destroyed) {
183188
effect.render(this._context);
184189
this._context.indirectTarget = this._context.destination;
185190
}

src/layaAir/laya/display/PostProcess2DEffect.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { PostProcess2D, PostProcessRenderContext2D } from "./PostProcess2D";
33
export abstract class PostProcess2DEffect {
44
protected _active: boolean = true;
55
protected _owner: PostProcess2D;
6-
6+
destroyed = false;
77
protected _singleton: boolean = false;
88

99
/**
@@ -59,7 +59,8 @@ export abstract class PostProcess2DEffect {
5959
* @en Destroys the effect.
6060
* @zh 销毁效果。
6161
*/
62-
abstract destroy(): void;
63-
62+
destroy(): void {
63+
this.destroyed = true;
64+
}
6465

6566
}

src/layaAir/laya/display/effect2d/BlurEffect2D.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ export class BlurEffect2D extends PostProcess2DEffect {
147147

148148
/** @ignore */
149149
destroy() {
150+
super.destroy();
151+
150152
if (this._destRT) {
151153
// 回收纹理到对象池
152154
RenderTexture2D.recoverToPool(this._destRT);

src/layaAir/laya/display/effect2d/ColorEffect2D.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ export class ColorEffect2D extends PostProcess2DEffect {
349349

350350
/** @ignore */
351351
destroy() {
352+
super.destroy();
353+
352354
if (this._destRT) {
353355
// 回收纹理到对象池
354356
RenderTexture2D.recoverToPool(this._destRT);

src/layaAir/laya/display/effect2d/GlowEffect2D.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ export class GlowEffect2D extends PostProcess2DEffect {
248248

249249
/** @ignore */
250250
destroy() {
251+
super.destroy();
252+
251253
if (this._destRT) {
252254
// 回收纹理到对象池
253255
RenderTexture2D.recoverToPool(this._destRT);

0 commit comments

Comments
 (0)