質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

1回答

3824閲覧

UnityでWebViewを動作させようとするとクラッシュが発生する

r.murasaki

総合スコア14

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2019/09/10 08:54

macOS X 上のUnity2018.3.6f1でWebViewを実行しようと考え、プロジェクトを作成し、git(https://github.com/gree/unity-webview)より取得したzipより

dist/unity-webview.unitypackage

をプロジェクトにドロップして必要なソースを取得し、HierarcyにWebView用等のオブジェクトを作成し以下のようにソースを組んでオブジェクトに付与しました。

C#

1using UnityEngine; 2 3public class SampleWebView : MonoBehaviour 4{ 5 private string url = "http://www.google.com/"; 6 WebViewObject webViewObject; 7 8 void Start() 9 { 10 webViewObject = 11 (new GameObject("WebViewObject")).AddComponent<WebViewObject>(); 12 webViewObject.Init((msg) => { 13 if (msg == "clicked") 14 { 15 webViewObject.SetVisibility(false); 16 } 17 }); 18 19 webViewObject.LoadURL(url); 20 21 webViewObject.SetMargins(50, 100, 50, 50); 22 23 webViewObject.SetVisibility(true); 24 25 webViewObject.EvaluateJS( 26 "window.addEventListener('load', function() {" + 27 " window.addEventListener('click', function() {" + 28 " Unity.call('clicked');" + 29 " }, false);" + 30 "}, false);"); 31 32 } 33 34 void OnGUI() 35 { 36 Rect textArea = new Rect(100, 0, 400, 100); 37 url = GUI.TextArea(textArea, url); 38 39 if (GUI.Button(new Rect(500, 0, 100, 100), "GO")) 40 { 41 webViewObject.LoadURL(url); 42 webViewObject.SetVisibility(true); 43 } 44 } 45}

しかし、毎回Unityでクラッシュが発生してしまいます。
ソースを辿ったところ、 webViewObject.SetVisibility(true); でクラッシュは発生しており、エラーログを見てみると以下のようなクラッシュログが残っておりました

Reloading assemblies for play mode. Begin MonoManager ReloadAssembly Initializing Unity.PackageManager (PackageManager) v2018.3.6 for Unity v2018.3.6f1 Registering platform support modules: Registered platform support modules in: 0.0540608s. Native extension for Android target not found Native extension for iOS target not found Native extension for OSXStandalone target not found Refreshing native plugins compatible for Editor in 2.58 ms, found 4 plugins. Preloading 1 native plugins for Editor in 1.31 ms. Mono: successfully reloaded assembly - Completed reload, in 1.416 seconds Platform modules already initialized, skipping Load scene 'Temp/__Backupscenes/0.backup' time: 0.279816 ms Refreshing native plugins compatible for Editor in 0.49 ms, found 4 plugins. Fallback handler could not load library /Applications/Unity/Hub/Editor/2018.3.6f1/Unity.app/Contents/Frameworks/Mono/lib/libAssets/Plugins/WebView.bundle/Contents/MacOS/WebView Fallback handler could not load library /Applications/Unity/Hub/Editor/2018.3.6f1/Unity.app/Contents/Frameworks/Mono/lib/libAssets/Plugins/WebView.bundle/Contents/MacOS/WebView.dylib Fallback handler could not load library /Applications/Unity/Hub/Editor/2018.3.6f1/Unity.app/Contents/Frameworks/Mono/lib/libAssets/Plugins/WebView.bundle/Contents/MacOS/WebView.so Fallback handler could not load library /Applications/Unity/Hub/Editor/2018.3.6f1/Unity.app/Contents/Frameworks/Mono/lib/libAssets/Plugins/WebView.bundle/Contents/MacOS/WebView.bundle Receiving unhandled NULL exception Obtained 12 stack frames. Thread 0x700014e99000 may have been prematurely finalized #0 0x007fff50c9ac44 in glGetIntegerv Thread 0x700014e99000 may have been prematurely finalized #1 0x00000123c9c96c in -[CWebViewPlugin render] Thread 0x700014e99000 may have been prematurely finalized #2 0x00000123c9d185 in UnityRenderEvent Thread 0x700014e99000 may have been prematurely finalized #3 0x00000100fcb16f in GfxDevice::InsertCustomMarkerCallback(void (*)(int), int) Thread 0x700014e99000 may have been prematurely finalized #4 0x00000102a5d8a9 in GfxDeviceWorker::RunCommand(ThreadedStreamBuffer&) Thread 0x700014e99000 may have been prematurely finalized #5 0x0000010078f08c in GfxDeviceWorkerAutoreleasePoolProxy Thread 0x700014e99000 may have been prematurely finalized #6 0x00000102a654c0 in GfxDeviceWorker::RunExt(ThreadedStreamBuffer&) Thread 0x700014e99000 may have been prematurely finalized #7 0x00000102a5af51 in GfxDeviceWorker::RunGfxDeviceWorker(void*) Thread 0x700014e99000 may have been prematurely finalized #8 0x00000100e69542 in Thread::RunThreadWrapper(void*) Thread 0x700014e99000 may have been prematurely finalized #9 0x007fff6f546661 in _pthread_body Thread 0x700014e99000 may have been prematurely finalized #10 0x007fff6f54650d in _pthread_body Thread 0x700014e99000 may have been prematurely finalized #11 0x007fff6f545bf9 in thread_start Launching bug reporter (中略) Assertion failed on expression: 'Thread::EqualsCurrentThreadID(Thread::mainThreadId)' (Filename: /Users/builduser/buildslave/unity/build/Editor/Src/SceneInspector.cpp Line: 532

これはどのような事象、あるいは設定ミスが考えられますでしょうか?
よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

urlをhttpsに変更したらどうなりますか?

iOSでhttp通信するにはApp Transport Securityの設定を変更する必要があります。

投稿2019/09/11 08:36

yxt003

総合スコア184

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問