cocos-engine icon indicating copy to clipboard operation
cocos-engine copied to clipboard

gfx object must call destroy, and should never be used again

Open star-e opened this issue 3 years ago • 3 comments
trafficstars

Use Case

In webgpu backend, we have to destroy resources and delete object in xxx.destroy() method.

In native engine, v8 finalizer is used to delete native c++ object, while in webgpu, browser finalizer is not fully supported. As a result, we must call destroy to delete webgpu object.

Problem Description

Currently, gfx object might be used after destroy.

const framebuffer = shadowFrameBufferMap.get("xxx");
frameBuffer.destroy();
frameBuffer.initialize(info);

It is forbidden in webgpu backend.

Proposed Solution

Remove all usages of re-initialization of gfx object.

How it works

No response

Alternatives Considered

destroy leak gfx object in webgpu backend.

Additional Information

No response

star-e avatar Sep 13 '22 08:09 star-e

Does it affect native usage? In native, we just use IntrusivePtr to control the lifecycle.

minggo avatar Sep 13 '22 08:09 minggo

I agree that should not reuse gfx objects when they are destroyed.

minggo avatar Sep 13 '22 08:09 minggo

Does it affect native usage? In native, we just use IntrusivePtr to control the lifecycle.

It does not affect native usage. In native engine, v8's finalizer will be called and c++ object is deleted or decRefed. So there is no leak.

In webgpu, browser's finalizer might not be called or is not supported at all. So every webgpu/webasm object must be deleted manually.

star-e avatar Sep 13 '22 09:09 star-e

@star-e I assigned @hana-alice , if it's not appropriate, please re-assign

pandamicro avatar Feb 07 '23 10:02 pandamicro