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

destroy instances and release resources #6941

Closed
Daisiyou opened this issue Jul 7, 2023 · 1 comment
Closed

destroy instances and release resources #6941

Daisiyou opened this issue Jul 7, 2023 · 1 comment

Comments

@Daisiyou
Copy link

Daisiyou commented Jul 7, 2023

Describe the bug
when I call method "setMaterialInstanceAt", How should I destroy old material instances?

MyCode: (iOS)

 RenderableManager& rcm = _engine->getRenderableManager();
 MaterialInstance* matIns = rcm.getMaterialInstanceAt(rcm.getInstance(entity), 0);
    if (matIns != NULL) {
        NSLog(@"find partName :%@", partName);
        NSData *data = [NSData dataWithContentsOfFile:materialPath];
        size_t size = data.length;
        Material* mat = Material::Builder()
            .package([data bytes], size)
            .build(*_engine);
        MaterialInstance* mInstance = mat->createInstance();
        rcm.setMaterialInstanceAt(rcm.getInstance(entity), 0, mInstance);
        
        //release resource
        _engine->destroy(matIns->getMaterial());
        _engine->destroy(matIns);
  }

Logs

in destroy:994
reason: destroying material "volume_ubershader" but 10 instances still alive
#0 FFChat 0x106844cc0 _ZN5utils7details8panicLogEPKcS2_iS2_z + 260
#1 FFChat 0x1067d0d78 _ZN8filament7FEngine7destroyEPKNS_9FMaterialE + 208
#2 FFChat 0x106e2a720 -[FF_3DApp changeModelPart:withPartName:andMaterial:] + 864
#3 FFChat 0x1044a4ca8 $s6FFChat10FFUser3DVCC10beardClickyySo8UIButtonCF + 620
#4 FFChat 0x1044a5544 $s6FFChat10FFUser3DVCC10beardClickyySo8UIButtonCFTo + 52
#5 UIKitCore 0x18ee0b908 + 100
#6 UIKitCore 0x18ee0b608 + 112
#7 UIKitCore 0x18ee0af9c + 324
#8 UIKitCore 0x18ee0ae40 + 124
#9 UIKitCore 0x18ee0aa14 + 400
#10 FFChat 0x106e25260 -[UIButton(BUATouchTracker) touchesEnded:withEvent:] + 1208
#11 UIKitCore 0x18ecf0268 + 5772
#12 CoreFoundation 0x18ca79d40 + 36
#13 CoreFoundation 0x18ca02290 + 532
#14 CoreFoundation 0x18ca63c60 + 1048
#15 CoreFoundation 0x18ca68ec0 CFRunLoopRunSpecific + 612
#16 GraphicsServices 0x1c6abf368 GSEventRunModal + 164
#17 UIKitCore 0x18ef5e86c + 888

@romainguy
Copy link
Collaborator

You can't destroy a material if you haven't destroyed its instances still in use.

@romainguy romainguy closed this as not planned Won't fix, can't repro, duplicate, stale Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants