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

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

新規登録して質問してみよう
ただいま回答率
85.50%
Unity

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

Q&A

0回答

950閲覧

unity 実機でカメラロールから写真(1M程度)を何回か読み込むとこけてしまいます。

29507-01

総合スコア46

Unity

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

0グッド

0クリップ

投稿2020/05/17 02:03

編集2022/01/12 10:55

前提・実現したいこと

実機でカメラロールから写真(iM程度)を何回か読み込むとこけてしまいます。
参考URL

発生している問題・エラーメッセージ

参考URLのGitHubをダウンロードして使っているだけです。

実機なのでこけてもエラー表示が出ないので何が原因かわからないのですが,
Button1でカメラロールから,1M以上の写真を何回か表示するとこけます。

只,カメラロールからではなくダイレクトにButton2をクリックして表示するテストでは何回でも表示されます。

該当のソースコード

Unity

1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5using System.Runtime.InteropServices; 6 7public class GameController : MonoBehaviour 8{ 9 [DllImport ("__Internal")] 10 private static extern float OpenCameraRoll (string path); 11 12 public Image image; 13 public int d_no; 14 15 void Start() 16 { 17 d_no = 0; 18 } 19 20 public void OnButtonClick (int number) 21 { 22 if (number == 0) 23 { 24 Debug.Log("click"); 25 26 if (Application.isEditor) 27 { 28 29 } 30 else if (Application.platform == RuntimePlatform.IPhonePlayer) 31 { 32 OpenCameraRoll(Application.temporaryCachePath + "/tempImage"); 33 } 34 else if (Application.platform == RuntimePlatform.Android) 35 { 36 AndroidJavaClass nativeDialog = new AndroidJavaClass("com.wapa5pow.plugin.CameraRoll"); 37 38 AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 39 AndroidJavaObject context = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); 40 41 context.Call("runOnUiThread", new AndroidJavaRunnable(() => { 42 nativeDialog.CallStatic( 43 "openCameraRoll", 44 context, 45 Application.temporaryCachePath + "/tempImage" 46 ); 47 })); 48 49 } 50 } 51 52 if (number == 1) 53 { 54 d_no += 1; 55 Texture2D texture2D = new Texture2D(2, 2); 56 57 if (d_no == 4) 58 { 59 d_no = 1; 60 } 61 if (d_no == 1) 62 { 63 texture2D = Resources.Load<Texture2D>("DSC_0019"); 64 } 65 if (d_no == 2) 66 { 67 texture2D = Resources.Load<Texture2D>("DSC_0020"); 68 } 69 if (d_no == 3) 70 { 71 texture2D = Resources.Load<Texture2D>("DSC_0021"); 72 } 73 Sprite sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), 0.5f * Vector2.one); 74 image.sprite = sprite; 75 } 76 } 77 78 public void SetImage (string path) 79 { 80 Texture2D texture2D = new Texture2D (2, 2); 81 texture2D.LoadImage (System.IO.File.ReadAllBytes (path)); 82 Sprite sprite = Sprite.Create (texture2D, new Rect (0, 0, texture2D.width, texture2D.height), 0.5f * Vector2.one); 83 image.sprite = sprite; 84 } 85} 86 87

試したこと

実機にて

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

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

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

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

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

sakura_hana

2020/05/18 00:06

「こける」とはアプリがクラッシュするということでいいですか? ログを取って何が起こっているのか把握するのが先決かと思います。(メモリリークかなーとは思いますが)
29507-01

2020/05/18 11:58 編集

アプリがクラッシュします。(異常終了) 実機でログが取れるのでしょうか?
sakura_hana

2020/05/19 01:59

実機ログ取れます。「android 実機 ログ」等で調べてみてください。
29507-01

2020/05/19 09:12

調べてみます
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

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

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

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問