LoginSignup
riririki
@riririki (riki nona)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

Unityエラー:warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available.

解決したいこと

Unityで、ARで撮影したものをRenderTextureに変換するコードでエラーが発生します。
コンパイル後にはエラーはありませんが、XCodeでIphoneXに実機ビルドして「RefreshCameraFeedTexture」を83回呼ぶと毎回決まってアプリが落ちます。

落ちるための回数が明確であるため、再起的なコードを書いていると思われます。。。しかしどの部分が再起的かわかりません・・・

なお、「RefreshCameraFeedTexture」の最後の部分でVisualScriptingのカスタムイベントを走らせていますが、走らせない状態でもアプリは決まって落ちたので、関係ないかと思われます。

コードはこちらの、撮影データを変換する部分のコピペを改変したものになります
https://edom18.hateblo.jp/entry/2020/08/23/121008
Unityのバージョンは2021/1/11です。

発生している問題・エラー

2022-03-18 08:33:10.177090+0900 TrustFPS4[5080:1060379] [Technique] ARWorldTrackingTechnique <0x127fed390>: World tracking performance is being affected by resource constraints [1]
2022-03-18 08:33:24.038635+0900 TrustFPS4[5080:1060320] [ServicesDaemonManager] interruptionHandler is called. -[FontServicesDaemonManager connection]_block_invoke
WARNING -> applicationDidReceiveMemoryWarning()
WARNING -> applicationDidReceiveMemoryWarning()
WARNING -> applicationDidReceiveMemoryWarning()
2022-03-18 08:33:28.883617+0900 TrustFPS4[5080:1060191] [Technique] ARWorldTrackingTechnique <0x127fed390>: World tracking performance is being affected by resource constraints [1]
warning: could not execute support code to read Objective-C class data in the process. This may reduce the quality of type information available.

または、問題・エラーが起きている画像をここにドラッグアンドドロップ

該当するソースコード

using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
using Unity.VisualScripting;

public class CaptureXRCamera : MonoBehaviour
{
   
    [SerializeField] private ARCameraManager _cameraManager = null;
    [SerializeField] private GameObject _target = null;
    [SerializeField] private Texture2D _sampleTexture = null;
    [SerializeField] private Material _transposeMaterial = null;
    [SerializeField] private Text _text = null;
    [SerializeField] private GameObject _button_ob = null;

    private Texture2D _texture = null;
    private RenderTexture _previewTexture = null;
    private Renderer _renderer = null;
    private Material _material = null;

    private bool _needsRotate = true;

    public void RefreshCameraFeedTexture()
    {

        Debug.Log("1");
        // TryGetLatestImageで最新のイメージを取得します。
        // ただし、失敗の可能性があるため、falseが返された場合は無視します。
        if (!_cameraManager.TryAcquireLatestCpuImage(out XRCpuImage cameraImage)) return;

        Debug.Log("2");

        

        // デバイスの回転に応じてカメラの情報を変換するための情報を定義します。
        XRCpuImage.Transformation imageTransformation = (Input.deviceOrientation == DeviceOrientation.LandscapeRight)
            ? XRCpuImage.Transformation.MirrorY
            : XRCpuImage.Transformation.MirrorX;
        Debug.Log("3");

        // カメライメージを取得するためのパラメータを設定します。
        XRCpuImage.ConversionParams conversionParams =
            new XRCpuImage.ConversionParams(cameraImage, TextureFormat.RGBA32, imageTransformation);

        Debug.Log("3.5");

        _texture = new Texture2D(cameraImage.width, cameraImage.height, TextureFormat.RGBA32, false);

        // 生成済みのTexture2D(_texture)のネイティブのデータ配列の参照を得ます。
        NativeArray<byte> rawTextureData = _texture.GetRawTextureData<byte>();

        Debug.Log("4");

        try
        {
            unsafe
            {
                Debug.Log("5");
                // 前段で得たNativeArrayのポインタを渡し、直接データを流し込みます。
                cameraImage.Convert(conversionParams, new IntPtr(rawTextureData.GetUnsafePtr()), rawTextureData.Length);
            }
        }
        finally
        {
            cameraImage.Dispose();
            Debug.Log("6");
        }

        // 取得したデータを適用します。
        _texture.Apply();
        CustomEvent.Trigger(gameObject, "On", _texture);
        Debug.Log("OK");

        
    }

}

自分で試したこと

手を動かしながら、とりあえず参考資料を集めています。
https://qiita.com/taji-taji/items/461504a17c750235c3cd
https://marycore.jp/prog/xcode/could-not-load-any-objective-c-class-information/

0

4Answer

追加です
_texture = new Texture2D(cameraImage.width, cameraImage.height, TextureFormat.RGBA32, false);
前回僕が出した質問でこの部分を追加しています

0

スクリーンショット 2022-03-18 9.00.54.png

メモリをARで得た画像をテクスチャに変えているのを何度も行なっているので、メモリが大容量になって落ちていたようです。
現在軽量化する方法を模索中です。なにか良い方法はありますでしょうか・・・

0

Your answer might help someone💌