mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
fix particle destroy error (#4074)
This commit is contained in:
@@ -144,19 +144,24 @@ export default class ParticleSystemRenderer extends RenderableComponent {
|
||||
}
|
||||
if (this._model == null) {
|
||||
this._model = this._getRenderScene().createModel(ParticleBatchModel, this.node) as ParticleBatchModel;
|
||||
}
|
||||
if (!this._model.inited) {
|
||||
this._model.setCapacity(this.particleSystem.capacity);
|
||||
this._model.setVertexAttributes(this._vertAttrs);
|
||||
this._model.node = this.node;
|
||||
}
|
||||
this._model.enabled = this.enabledInHierarchy;
|
||||
}
|
||||
|
||||
public onDisable () {
|
||||
if (this._model) {
|
||||
this._model.enabled = this.enabledInHierarchy;
|
||||
}
|
||||
}
|
||||
|
||||
public onDisable () {
|
||||
this._getRenderScene().destroyModel(this._model!);
|
||||
}
|
||||
|
||||
public onDestroy () {
|
||||
this._model!.destroy();
|
||||
this._getRenderScene().destroyModel(this._model!);
|
||||
this._model = null;
|
||||
}
|
||||
|
||||
public clear () {
|
||||
@@ -316,8 +321,12 @@ export default class ParticleSystemRenderer extends RenderableComponent {
|
||||
} else {
|
||||
console.warn(`particle system renderMode ${this._renderMode} not support.`);
|
||||
}
|
||||
const ea = mat!.effectAsset;
|
||||
mat!.destroy();
|
||||
mat!.initialize({ defines: this._defines });
|
||||
mat!.initialize({
|
||||
defines: this._defines,
|
||||
effectAsset: ea,
|
||||
});
|
||||
|
||||
if (this.particleSystem.textureAnimationModule.enable) {
|
||||
mat!.setProperty('frameTile_velLenScale', vec2.set(this.frameTile_velLenScale, this.particleSystem.textureAnimationModule.numTilesX, this.particleSystem.textureAnimationModule.numTilesY));
|
||||
|
||||
@@ -126,6 +126,7 @@ export class RenderView {
|
||||
} else {
|
||||
this._stages.push('ForwardFlow');
|
||||
this._stages.push('ToneMapFlow');
|
||||
this._stages.push('SMAAFlow');
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -67,9 +67,9 @@ export default class ParticleBatchModel extends Model {
|
||||
// rebuid
|
||||
this._vBuffer = this._createSubMeshData();
|
||||
this._vertAttrsFloatCount = this._vertSize / 4; // number of float
|
||||
this._vBuffer = new ArrayBuffer(this._capacity * this._vertSize * 4);
|
||||
this._vdataF32 = new Float32Array(this._vBuffer);
|
||||
this._vdataUint32 = new Uint32Array(this._vBuffer);
|
||||
this._inited = true;
|
||||
}
|
||||
|
||||
public _createSubMeshData (): ArrayBuffer {
|
||||
@@ -156,8 +156,8 @@ export default class ParticleBatchModel extends Model {
|
||||
offset += 2;
|
||||
} else if (curAttr.format === GFXFormat.RGB32F) {
|
||||
this._vdataF32![offset] = pvdata[i].x;
|
||||
this._vdataF32![offset + 1] = pvdata[i].y;
|
||||
this._vdataF32![offset + 2] = pvdata[i].z;
|
||||
this._vdataF32![offset + 1] = pvdata[i].y;
|
||||
offset += 3;
|
||||
} else if (curAttr.format === GFXFormat.RGBA8) {
|
||||
this._vdataUint32![offset] = pvdata[i];
|
||||
@@ -181,9 +181,13 @@ export default class ParticleBatchModel extends Model {
|
||||
|
||||
public destroy () {
|
||||
super.destroy();
|
||||
this._vBuffer = null;
|
||||
this._vdataF32 = null;
|
||||
this.destroySubMeshData();
|
||||
if (this._subMeshData) {
|
||||
this.destroySubMeshData();
|
||||
}
|
||||
this._iaInfoBuffer.destroy();
|
||||
this._subMeshData = null;
|
||||
}
|
||||
|
||||
private destroySubMeshData () {
|
||||
|
||||
Reference in New Issue
Block a user