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

Crash on rive::gpu::BackgroundShaderCompiler::threadMain() when used in UIBarButtonItem #354

Open
alecsmirnov opened this issue Jan 14, 2025 · 2 comments

Comments

@alecsmirnov
Copy link

Hello!

Description

Rive, for some reason, crashed (SIGABRT (ABORT)) several times during runtime before showing the animation when used in UIBarButtonItem.

Simplified code

// View and VM, which are used as a container for RiveView to change visibility
// final class AnimatedViewModel: RiveViewModel { ... }

final class AnimatedView: UIView {
    var viewModel: AnimatedViewModel? {
        didSet {
            viewModel?.setView(riveView)

            viewModel.configureStateChangeAction { [weak self] isHidden in
                self?.riveView.isHidden = isHidden
            }
        }
    }

    private let riveView = RiveView()

    init() {
        super.init(frame: .zero)

        addSubview(riveView)
        riveView.translatesAutoresizingMaskIntoConstraints = false
        
        riveView.topAnchor.constraint(equalTo: topAnchor).isActive = true
        riveView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
        riveView.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
        riveView.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
// Custom UIBarButtonItem for adding AnimatedView and interactions with it
final class AnimatedBarButtonItem: UIBarButtonItem {
    var viewModel: AnimatedBarButtonItemViewModel? {
        didSet {
            animatedView.viewModel = viewModel?.animatedViewModel

            viewModel.configure(tapRecognizer: tapRecognizer)
            viewModel?.configureTapRecognizerAvailabilityAction { [weak self] isEnabled in
                self?.tapRecognizer.isEnabled = isEnabled
            }
        }
    }

    private let animatedView = AnimatedView()
    private let tapRecognizer = UITapGestureRecognizer()

    override public init() {
        super.init()

        animatedView.addGestureRecognizer(tapRecognizer)

        customView = animatedView
        customView?.translatesAutoresizingMaskIntoConstraints = false
        customView?.widthAnchor.constraint(equalToConstant: 60).isActive = true
        customView?.heightAnchor.constraint(equalToConstant: 50).isActive = true
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
// Add this button to the navbar in VC
final class MainViewController: UIViewController {
    ...
    
    func configureNavigationBar() {
        navigationItem.rightBarButtonItems = [AnimatedBarButtonItem()]
    }
}

Crash Report

Crashed: Thread #1
SIGABRT ABORT 0x00000001db4e12d4

          Crashed: Thread
0  libsystem_kernel.dylib         0xc2d4 __pthread_kill + 8
1  libsystem_pthread.dylib        0x859c pthread_kill + 268
2  libsystem_c.dylib              0x77b08 abort + 128
3  RiveRuntime                    0x1a95f4 rive::gpu::BackgroundShaderCompiler::threadMain() + 2492
4  RiveRuntime                    0x1a9768 void* std::__1::__thread_proxy[abi:un170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (rive::gpu::BackgroundShaderCompiler::*)(), rive::gpu::BackgroundShaderCompiler*>>(void*) + 72
5  libsystem_pthread.dylib        0x17d0 _pthread_start + 136
6  libsystem_pthread.dylib        0x1480 thread_start + 8

Expected behavior

The application should not crash.

Device & Versions (please complete the following information)

  • Device: iPhone SE (2nd generation), iPhone 14
  • iOS version iOS 16, iOS 18.2
  • Rive version: 6.0.7

Additional context

The crash is very rare, but it appears from time to time and only on real devices, and the reason is still unclear.

@dskuza
Copy link
Collaborator

dskuza commented Jan 16, 2025

Have you tried any of the latest versions of the runtime? I'm curious if the problem still exists (we've had a few minor releases since v6.0.7).

@alecsmirnov
Copy link
Author

I'll try the latest version and try to check. Thanks.

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