Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shader destroy memory residual #2410

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ export class Engine extends EventDispatcher {
if (length > shaderProgramPools.length) {
shaderProgramPools.length = length;
}
shaderProgramPools[index] = pool = new ShaderProgramPool();
shaderProgramPools[index] = pool = new ShaderProgramPool(this);
shaderPass._shaderProgramPools.push(pool);
}
return pool;
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/shader/ShaderPass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ export class ShaderPass extends ShaderPart {
_destroy(): void {
const shaderProgramPools = this._shaderProgramPools;
for (let i = 0, n = shaderProgramPools.length; i < n; i++) {
shaderProgramPools[i]._destroy();
const shaderProgramPool = shaderProgramPools[i];
shaderProgramPool._destroy();
delete shaderProgramPool.engine._shaderProgramPools[this._shaderPassId];
}
// Clear array storing multiple engine shader program pools
shaderProgramPools.length = 0;
}

Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/shader/ShaderProgramPool.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Engine } from "../Engine";
import { ShaderMacroCollection } from "./ShaderMacroCollection";
import { ShaderProgram } from "./ShaderProgram";

Expand All @@ -11,6 +12,8 @@ export class ShaderProgramPool {
private _lastQueryMap: Record<number, ShaderProgram>;
private _lastQueryKey: number;

constructor(public engine: Engine) {}

/**
* Get shader program by macro collection.
* @param macros - macro collection
Expand Down
Loading