(:3[kanのメモ帳]

個人ゲーム開発者kan.kikuchiのメモ的技術ブログ。月木更新でUnity関連がメイン。

(:3[kanのメモ帳]


本ブログの運営者kan.kikuchiが個人で開発したゲームです!

    

ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame.【Unity】【トラブルシューティング】


このエントリーをはてなブックマークに追加


この記事でのバージョン
Unity 5.2.2f1 Personal

はじめに

今回はテクスチャを作成し、編集しようとしたときに

ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame.


f:id:kan_kikuchi:20151211133607p:plain


と表示される場合の対処法です。


WaitForEndOfFrame

以下のようにテクスチャを生成し、

ReadPixelsを実行した時にタイトルのエラーが発生することがあります

Texture2D texture = new Texture2D (100100, TextureFormat.RGB24, false);

//ここでエラー
texture.ReadPixels (new Rect (003232), 00false);

texture.SetPixel (00, Color.white);
texture.Apply ();

どうやら描画が終わってからReadPixels を行わなければいけないようです。


WaitForEndOfFrameを使えばレンダリングが完了するまで待てるようなので、


以下のように

ReadPixelsを実行するより前にWaitForEndOfFrameを使えばエラーは発生しなくなります。

Texture2D texture = new Texture2D (100100, TextureFormat.RGB24, false);


 //レンダリングが完了するまで待つ
yield return new WaitForEndOfFrame();

texture.ReadPixels (new Rect (003232), 00false);

texture.SetPixel (00, Color.white);
texture.Apply ();