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] Missing resource bundle when using SPM #243

Closed
1 task done
acoustep opened this issue Jan 30, 2021 · 7 comments · Fixed by #248
Closed
1 task done

[Crash] Missing resource bundle when using SPM #243

acoustep opened this issue Jan 30, 2021 · 7 comments · Fixed by #248
Labels
DownView Issues specific to DownView, the webview renderer SwiftPM Issues related to integrating via SwiftPM

Comments

@acoustep
Copy link

acoustep commented Jan 30, 2021

Please help prevent duplicate issues before submitting a new one:

  • I've searched other open/closed issues for duplicates before opening up this new issue.

Report

What did you do?

I'm trying to parse some markdown and render it to a DownView

What did you expect to happen?

I expected the HTML to render in the DownView.

What happened instead?

I'm getting this crash on the system:

Fatal error: Unexpectedly found nil while unwrapping an Optional value: file Down/DownView.swift, line 42
2021-01-30 11:12:09.122751+0000 DownTest[8704:153732] Fatal error: Unexpectedly found nil while unwrapping an Optional value: file Down/DownView.swift, line 42

Background Info

I've previously had this working on an old Mac app using Carthage. I recently upgraded to Big Sur (Intel) and I'm trying to use the Swift Package Manager instead. I've also been upgrading my dependencies including Down and came across this error in my app and couldn't figure out how to fix it.

I tried recreating the issue in a fresh app and the same thing happened. So either I'm doing something very wrong or there seems to be a bug.

I've added a repo which replicates the issue here: https://github.com/acoustep/DownBugTest

Forgot to mention: I'm running Xcode 12.4

@johnxnguyen
Copy link
Owner

Hey @acoustep , thanks for flagging this issue. So it looks like the DownView.bundle (a resource that contains some css and javascript files) can't be loaded. Bundle resources were not supported in Swift packages until Swift 5.3, and unfortunately Down is still targeting 5.1.

I'll look into getting a fix for this, in the meantime you may need to continue to use Carthage to pull Down into your project.

@johnxnguyen johnxnguyen added DownView Issues specific to DownView, the webview renderer SwiftPM Issues related to integrating via SwiftPM labels Jan 30, 2021
@acoustep
Copy link
Author

Hi @johnxnguyen , no problem. Thanks for responding so fast, I appreciate it!

@johnxnguyen
Copy link
Owner

Hey @acoustep , I have a draft PR that should solve this crash. I've tested it locally and it seems to work, but it'd be great if you could pull the branch fix/swift-package-structure to your project via SPM and check that you can use DownView.

@johnxnguyen johnxnguyen changed the title Fatal error: Unexpectedly found nil while unwrapping an Optional value: file Down/DownView.swift, line 42 [Crash] Missing resource bundle when using SPM Feb 21, 2021
@acoustep
Copy link
Author

Hi @johnxnguyen , I've tried this and it compiles but I'm unable to see anything in the view.

I'm seeing this in my error logs:

2021-02-22 17:11:58.798066+0000 DownTest2[88558:2286407] [Process] 0x7f956b846020 - [pageProxyID=5, webPageID=6, PID=0] WebPageProxy::processDidTerminate: (pid 0), reason 3
2021-02-22 17:11:58.798215+0000 DownTest2[88558:2286407] [Loading] 0x7f956b846020 - [pageProxyID=5, webPageID=6, PID=0] WebPageProxy::dispatchProcessDidTerminate: reason = 3
2021-02-22 17:11:58.909875+0000 DownTest2[88558:2286407] [Process] 0x7f956b846020 - [pageProxyID=5, webPageID=6, PID=0] WebPageProxy::processDidTerminate: (pid 0), reason 3
2021-02-22 17:11:58.928114+0000 DownTest2[88558:2286407] [Loading] 0x7f956b846020 - [pageProxyID=5, webPageID=6, PID=0] WebPageProxy::dispatchProcessDidTerminate: reason = 3
2021-02-22 17:11:58.928157+0000 DownTest2[88558:2286407] [Process] 0x7f956b846020 - [pageProxyID=5, webPageID=6, PID=0] WebPageProxy::tryReloadAfterProcessTermination: process crashed and the client did not handle it, not reloading the page because we reached the maximum number of attempts

Here's a screenshot
image

and the code

//
//  ViewController.swift
//  DownTest2
//
//  Created by Mitch Stanley on 22/02/2021.
//

import Cocoa
import Down

class ViewController: NSViewController {

    @IBOutlet weak var dview: NSView!
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        // Do any additional setup after loading the view.
        renderDownInWebView()
    }

    override var representedObject: Any? {
        didSet {
        // Update the view, if already loaded.
        }
    }


}

private extension ViewController {
    
    func renderDownInWebView() {
        let readMeURL = Bundle.main.url(forResource: nil, withExtension: "md")!
        let readMeContents = try! String(contentsOf: readMeURL)
        
        do {
            let downView = try DownView(frame: dview.bounds, markdownString: readMeContents, didLoadSuccessfully: {
                print("Markdown was rendered.")
            })
            downView.autoresizingMask = [.width, .height]
            dview.addSubview(downView, positioned: .above, relativeTo: nil)
        } catch {
            NSApp.presentError(error)
        }
    }
}

@johnxnguyen
Copy link
Owner

I've tried this and it compiles but I'm unable to see anything in the view.

Hey @acoustep , make sure your entitlements file has a key com.apple.security.network.client with a boolean value 1, as seen here:

Screen Shot 2021-02-22 at 6 18 43 PM

I'm not sure why you need it (I don't use DownView) but I saw it in the demo project and it works for me. Let me know how it goes.

@acoustep
Copy link
Author

Thanks @johnxnguyen that's done the trick. I think it must be because the example markdown file has links to external images.

@johnxnguyen
Copy link
Owner

Good to know! I'll do some some checks that o haven't broken anything when pulling in Down via Carthage or Pods, and if all is good I'll merge the PR and release the changes soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DownView Issues specific to DownView, the webview renderer SwiftPM Issues related to integrating via SwiftPM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants