Skip to content

Commit

Permalink
fix(destroy): render error after obj.destroy()
Browse files Browse the repository at this point in the history
  • Loading branch information
lslzl3000 committed Nov 23, 2024
1 parent 9b2d7d1 commit 1e79847
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orillusion/core",
"version": "0.8.4-dev.2",
"version": "0.8.4-dev.3",
"author": "Orillusion",
"description": "Orillusion WebGPU Engine",
"type": "module",
Expand Down
4 changes: 2 additions & 2 deletions src/Engine3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ export class Engine3D {
* Resume the engine render
*/
public static resume() {
if(this._requestAnimationFrameID == 0)
if(this._requestAnimationFrameID === 0)
this._requestAnimationFrameID = requestAnimationFrame((t) => this.render(t));
}

Expand All @@ -450,8 +450,8 @@ export class Engine3D {
this._time = time;
}
await this.updateFrame(time);
this._requestAnimationFrameID = 0;
this.resume()

}

private static async updateFrame(time: number) {
Expand Down
3 changes: 1 addition & 2 deletions src/components/ComponentBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ export class ComponentBase implements IComponent {
* @internal
*/
protected _enable: boolean = true;

private __isStart: boolean = false;
public isDestroyed?: boolean;
public isDestroyed: boolean = false;

public get isStart(): boolean {
return this.__isStart;
Expand Down
7 changes: 3 additions & 4 deletions src/components/renderer/RenderNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,10 @@ export class RenderNode extends ComponentBase {
}

public destroy(force?: boolean) {

super.destroy(force);
this._geometry = null;
this._materials = null;
this._combineShaderRefection = null;
this._geometry = undefined;
this._materials.length = 0;
this._combineShaderRefection = undefined;
}

}
8 changes: 3 additions & 5 deletions src/core/entities/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ export class Entity extends CEventDispatcher {
public get instanceID(): string {
return this._instanceID;
}



/**
*
* The Transform attached to this object.
Expand Down Expand Up @@ -67,9 +64,10 @@ export class Entity extends CEventDispatcher {
protected _boundWorld: IBound;
protected _isBoundChange: boolean = true;
private _dispose: boolean = false;
// private _visible: boolean = true;


public get dispose(): boolean {
return this._dispose;
}

/**
*
Expand Down
4 changes: 3 additions & 1 deletion src/gfx/renderJob/passRenderer/color/ColorPassRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class ColorPassRenderer extends RendererBase {
let nodeMap = renderList[1];
for (const iterator of nodeMap) {
let node = iterator[1];
if (node.preInit(this._rendererType)) {
if (!node.isDestroyed && node.preInit(this._rendererType)) {
node.nodeUpdate(view, this._rendererType, this.rendererPassState, clusterLightingBuffer);
break;
}
Expand All @@ -134,6 +134,8 @@ export class ColorPassRenderer extends RendererBase {
continue;
if (renderNode.hasMask(RendererMask.UI) && !renderNode.isRecievePostEffectUI)
continue;
if (renderNode.isDestroyed)
continue;
if (!renderNode.preInit(this._rendererType)) {
renderNode.nodeUpdate(view, this._rendererType, this.rendererPassState, clusterLightingBuffer);
}
Expand Down
4 changes: 3 additions & 1 deletion src/gfx/renderJob/passRenderer/color/GUIPassRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class GUIPassRenderer extends RendererBase {
let nodeMap = renderList[1];
for (const iterator of nodeMap) {
let node = iterator[1];
if (node.preInit(this._rendererType)) {
if (!node.isDestroyed && node.preInit(this._rendererType)) {
node.nodeUpdate(view, this._rendererType, this.rendererPassState, clusterLightingBuffer);
break;
}
Expand All @@ -94,6 +94,8 @@ export class GUIPassRenderer extends RendererBase {
continue;
if (!renderNode.hasMask(RendererMask.UI) || renderNode.isRecievePostEffectUI)
continue;
if (renderNode.isDestroyed)
continue;
if (!renderNode.preInit(this._rendererType)) {
renderNode.nodeUpdate(view, this._rendererType, this.rendererPassState, clusterLightingBuffer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class ReflectionRenderer extends RendererBase {
let node = iterator[1];
if (node.hasMask(RendererMask.ReflectionDebug))
continue;
if (node.preInit(PassType.REFLECTION)) {
if (!node.isDestroyed && node.preInit(PassType.REFLECTION)) {
node.nodeUpdate(view, PassType.REFLECTION, this.rendererPassState, clusterLightingBuffer);
break;
}
Expand All @@ -206,7 +206,8 @@ export class ReflectionRenderer extends RendererBase {
continue;
if (!renderNode.enable)
continue;

if (renderNode.isDestroyed)
continue;
if (!renderNode.preInit(PassType.REFLECTION)) {
renderNode.nodeUpdate(view, PassType.REFLECTION, this.rendererPassState, clusterLightingBuffer);
}
Expand Down
6 changes: 3 additions & 3 deletions src/gfx/renderJob/passRenderer/ddgi/DDGIProbeRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class DDGIProbeRenderer extends RendererBase {
let nodeMap = renderList[1];
for (const iterator of nodeMap) {
let node = iterator[1];
if (node.preInit(this.passType)) {
if (!node.isDestroyed && node.preInit(this.passType)) {
node.nodeUpdate(view, this.passType, this.rendererPassState, null);
break;
}
Expand All @@ -206,7 +206,7 @@ export class DDGIProbeRenderer extends RendererBase {

for (let i = drawMin; i < drawMax; ++i) {
let renderNode = collectInfo.opaqueList[i];
if (renderNode.enable && renderNode.transform.enable) {
if (renderNode.enable && renderNode.transform.enable && !renderNode.isDestroyed) {
if (!renderNode.preInit(this.passType)) {
renderNode.nodeUpdate(view, this.passType, this.rendererPassState, null);
}
Expand All @@ -226,7 +226,7 @@ export class DDGIProbeRenderer extends RendererBase {

for (let i = drawMin; i < drawMax; ++i) {
let renderNode = collectInfo.transparentList[i];
if (renderNode.enable && renderNode.transform.enable) {
if (renderNode.enable && renderNode.transform.enable && !renderNode.isDestroyed) {
if (!renderNode.preInit(this.passType)) {
renderNode.nodeUpdate(view, this.passType, this.rendererPassState, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class PreDepthPassRenderer extends RendererBase {
let nodeMap = renderList[1];
for (const iterator of nodeMap) {
let node = iterator[1];
if (node.preInit(this._rendererType)) {
if (!node.isDestroyed && node.preInit(this._rendererType)) {
node.nodeUpdate(view, this._rendererType, this.rendererPassState, null);
break;
}
Expand Down Expand Up @@ -110,6 +110,8 @@ export class PreDepthPassRenderer extends RendererBase {
continue;
if (!renderNode.enable)
continue;
if (renderNode.isDestroyed)
continue;
if (!renderNode.preInit(this._rendererType)) {
renderNode.nodeUpdate(view, this._rendererType, this.rendererPassState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class PointLightShadowRenderer extends RendererBase {

for (const iterator of collectInfo.opaqueList) {
let node = iterator;
if (node.preInit(this._rendererType)) {
if (!node.isDestroyed && node.preInit(this._rendererType)) {
node.nodeUpdate(view, this._rendererType, renderContext.rendererPassState, null);
break;
}
Expand Down Expand Up @@ -268,7 +268,7 @@ export class PointLightShadowRenderer extends RendererBase {
let nodeMap = renderList[1];
for (const iterator of nodeMap) {
let node = iterator[1];
if (node.preInit(this._rendererType)) {
if (!node.isDestroyed && node.preInit(this._rendererType)) {
node.nodeUpdate(view, this._rendererType, renderContext.rendererPassState, clusterLightingBuffer);
break;
}
Expand All @@ -285,7 +285,8 @@ export class PointLightShadowRenderer extends RendererBase {
continue;
if (!renderNode.castShadow)
continue;

if (renderNode.isDestroyed)
continue;
if (!renderNode.preInit(this._rendererType)) {
renderNode.nodeUpdate(view, this._rendererType, renderContext.rendererPassState, clusterLightingBuffer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ export class ShadowMapPassRenderer extends RendererBase {
let nodeMap = renderList[1];
for (const iterator of nodeMap) {
let node = iterator[1];

if (node.preInit(this._rendererType)) {
if (!node.isDestroyed && node.preInit(this._rendererType)) {
node.nodeUpdate(view, this._rendererType, this.rendererPassState, null);
break;
}
Expand Down Expand Up @@ -256,9 +255,10 @@ export class ShadowMapPassRenderer extends RendererBase {
continue;
if (!renderNode.enable)
continue;
if (!renderNode.castShadow) {
if (!renderNode.castShadow)
continue;
if (renderNode.isDestroyed)
continue;
}
if (!renderNode.preInit(this._rendererType)) {
renderNode.nodeUpdate(view, this._rendererType, this.rendererPassState, clusterLightingBuffer);
}
Expand Down
2 changes: 1 addition & 1 deletion src/loader/parser/gltf/GLTFParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class GLTFParser extends ParserBase {
//await this.load_gltf_textures();
let subParser = new GLTFSubParser();
let nodes = await subParser.parse(this.initUrl, this._gltf, this._gltf.scene);
subParser.destory();
subParser.destroy();
subParser = null
if (nodes) {
this.data = nodes.rootNode;
Expand Down
2 changes: 1 addition & 1 deletion src/loader/parser/gltf/GLTFSubParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class GLTFSubParser {
return await this.convertToNode(result);
}

public destory() {
public destroy() {
KHR_draco_mesh_compression.unload(this.gltf)
this.gltf = null
}
Expand Down

0 comments on commit 1e79847

Please sign in to comment.