• RuntimesBugs
  • iOS outlined destroy of SpineRenderer

Add a SpineUIView to my VC, after VC dealloc, crash with SpineRenderer
Thread 1: EXC_BREAKPOINT (code=1, subcode=0x107aa5608)
#8 0x000000010369f6d0 in outlined destroy of SpineRenderer? ()

I have added the clean code:
controller.animationState.clearTracks()
drawable?.dispose()
customSkin?.dispose()
controller.pause()

Any advice? Thanks in advance.

Related Discussions
...

Could you share a minimal project that reproduces the issue? Without the context within which this code is called, it's not possible to say why it would crash.

    This is the simplified code as below:

    @objc class MySpineModel: NSObject {
        var controller: SpineController
        var drawable: SkeletonDrawableWrapper?
        private var customSkin: Skin?
        
        override init() {
            controller = SpineController(
                onInitialized: { controller in
                    controller.animationState.setAnimationByName(
                        trackIndex: 0,
                        animationName: "idle",
                        loop: true
                    )
                },
                disposeDrawableOnDeInit: false
            )
        }
    
        deinit {
            controller.animationState.clearTracks()
            drawable?.dispose()
            customSkin?.dispose()
        }
        
        private func toggleSkin(skinName: String, drawable: SkeletonDrawableWrapper) {
            customSkin?.dispose()
            customSkin = Skin.create(name: "custom-skin")
            if let nemSkin = drawable.skeletonData.findSkin(name: skinName) {
                customSkin?.addSkin(other: nemSkin)
                drawable.skeleton.skin = customSkin
                drawable.skeleton.setToSetupPose()
            }
        }
            
        func loadDrawableData(atlasFileName: String, skeletonFileName: String) async {
            guard let drawable = try? await SkeletonDrawableWrapper.fromBundle(
                atlasFileName: atlasFileName,
                skeletonFileName: skeletonFileName
            ) else { return }
            self.toggleSkin(skinName: "01", drawable: drawable)
            self.drawable = drawable
        }
        
        func updateAnimation(_ animation: UMIAgentSpineAnimation) {
            guard let dw = drawable else { return }
            controller.animationState.clearTracks()
            controller.animationState.setAnimationByName(trackIndex: 0, animationName: animation.name, loop: animation.canLoop)
        }
    }
    @objc class MySpineView: UIView {
        private var spineUIView: SpineUIView?
        private var model = MySpineModel()
        
        @objc func loadData(atlasFileName: String, skeletonFileName: String) async {
            await model.loadDrawableData(atlasFileName: atlasFileName, skeletonFileName: skeletonFileName)
            
            if let drawable = model.drawable {
                spineUIView = SpineUIView(
                    from: .drawable(drawable),
                    controller: model.controller,
                    mode: .fit,
                    alignment: .center,
                    boundsProvider: SkinAndAnimationBounds(skins: ["01"]),
                    backgroundColor: .clear
                )
                
                if let spineUIView = spineUIView {
                    addSubview(spineUIView)
                    spineUIView.snp.makeConstraints { make in
                        make.edges.equalToSuperview()
                    }
                }
            }
        }
        
        @objc func updateAnimation(_ animation: UMIAgentSpineAnimation) {
            guard let _ = model.controller.drawable else {
                DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { [weak self] in
                    self?.updateAnimation(animation)
                }
                return
            }
            
            model.updateAnimation(animation)
        }
    }

    After removing MySpineView from superView, I set the instance = nil, then it crashed.

    Mario
    The code has been posted in the above thread. (not well formatted 😅)

    • Misaki님이 이에 답장했습니다.

      13025438373 I fixed the formatting! When pasting multiple lines of code, please use triple backticks (```) to form a code block.

      The code doesn't look like it's doing anything terrible. What I can not tell from the snippets is when deinit is called. You also need to provide a full stack trace for the crash.

        To release memory of animation, I need set MySpineView instance = nil, then it will release its property SpineUIView.
        In Spine SDK:

        public final class SpineUIView: MTKView {
            internal var renderer: SpineRenderer?

        SpineUIView will release SpineRenderer.

        But somewhere else SpineRenderer is used after released, that's why it crashed in my thought. Should be fixed in Spine SDK? or I misused somewhere?

        I'm sorry, but piecing together what's going wrong from this information is impossible.

        Please create a minimal Xcode project, that reproduces the crash. I can then debug and fix the issue with that.