2016-09-13 2 views
0

RenderTextureTexture2D에 그려 디스크에 저장하려고합니다. 이 방법은 Android뿐 아니라 OSX 편집기에서도 작동합니다.Texture2D.readPixels를 호출 할 때 iOS가 중단됩니다.

나는 엑스 코드 콘솔에 오류가 표시되지 않으며, 내 응용 프로그램은 내가 여기

Texture2D.ReadPixels() 코드의 요약입니다 호출 할 때 완전히 얼어 : 나는 다양한 사용하여 시도

// declaring variables... 
    RenderTexture outputTexture; 
    RenderTextureFormat RTFormat = RenderTextureFormat.ARGB32; 

    // use an appropriate format for render textures 
    if(SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBFloat)){ 
     RTFormat = RenderTextureFormat.ARGBFloat; 
    }else if(SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf)){ 
     RTFormat = RenderTextureFormat.ARGBHalf; 
    } 

    // create instance of output texture 
    outputTexture = new RenderTexture (res.x, res.y, 0, RTFormat); 

    // in Update, draw stuff to outputTexture 
    Graphics.Blit (outputTexture, canvasTexture); 
    Graphics.Blit (canvasTexture, outputTexture, material); 

    // later... user wants to save the image 
    // draw rendertexture to a Texture2D so we can write to disk 
    RenderTexture.active = outputTexture; 
    tmpTexture = new Texture2D (outputTexture.width, outputTexture.height, TextureFormat.ARGB32, false); 
    tmpTexture.ReadPixels (new Rect (0, 0, outputTexture.width, outputTexture.height), 0, 0, false); 
    tmpTexture.Apply(); 
    RenderTexture.active = null; 

RenderTextureFormatTextureFormat이지만 아무 것도 작동하지 않는 것 같습니다!

+0

어디에서이 코드를 호출합니까? 이것은 사용자 정의 함수 또는 Unity 콜백 메소드 내에 있습니까? –

+0

또한 어떤 기기를 테스트하고 있습니까? 기억이 나빠지는지 확인하십시오. RenderTexture는 값 비싼 방법입니다. –

답변

1

이것은 렌더링 텍스처 형식 호출로 인해 발생한다고 생각합니다. 이전과 비슷한 비슷한 일이 일어났습니다. 현재 실행 환경 (내 의견이 추가됩니다) 당신이 실제로 이후에 임시 질감을 정의하지만

//set a default render texture of RenderTextureFormat.ARGB32; 
RenderTextureFormat RTFormat = RenderTextureFormat.ARGB32; 

// if my system supports it, switch to either ARGBFloat or ARGBHalf 

// use an appropriate format for render textures 
if(SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBFloat)){ 
    RTFormat = RenderTextureFormat.ARGBFloat; 
}else if(SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf)){ 
    RTFormat = RenderTextureFormat.ARGBHalf; 
} 

, 지원하는 경우

코드의이 비트는 기본 텍스처 형식을 지정

후 기본 형식을 변경 당신은 단지 그것을 정의, ReadPixels()와 함께 하나의 방법 (다시, 내 의견 추가) (포맷을 지원 중) 일부 시스템에 따라서

//define a new tmpTexture container, ALWAYS with a TextureFormat of ARGB32 
tmpTexture = new Texture2D (outputTexture.width, outputTexture.height, TextureFormat.ARGB32, false); 

, 당신이로 하나의 텍스처 형식에서 readPixels()에 노력하고 채우기 다른. 아마도이 문제가 원인 일 수 있습니다.

대상 텍스처의 형식을 동적으로 변경하여이 문제를 해결할 수 있습니다. 대상 객체를 선언 할 때 동적으로 설정 형식을

RenderTextureFormat RTFormat = RenderTextureFormat.ARGB32; 

//add another variable here for the destination Texture format 
var destinationFormat = TextureFormat.ARGB32; 


// use an appropriate format for render textures 
if(SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBFloat)){ 
    RTFormat = RenderTextureFormat.ARGBFloat; 

    //also set destination format 
    destinationFormat = TextureFormat.RGBAFloat; 
}else if(SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf)){ 
    RTFormat = RenderTextureFormat.ARGBHalf; 

    //also set destination format 
    destinationFormat = TextureFormat.RGBAHalf; 
} 

다음 물론, 나중에 소비 :

//define a new tmpTexture container, with a dynamically set destination format that always matches the input texture 
tmpTexture = new Texture2D (outputTexture.width, outputTexture.height, destinationFormat, false); 

날 당신은 여전히이있는 경우 알려 그래서 첫 번째 섹션에서, 당신은 그것을 바꿀 것 의견에 문제가 있습니다.

+0

와우, 그런 자세한 게시물을 가져 주셔서 감사합니다. 내 문제는 최고로 끝나고, 당신은 내가 그것을 볼 수 있도록 도와주었습니다. TextureFormat.RGFloat에 destinationFormat을 설정하려고했습니다! 나는이 눈부신 오류에도 불구하고 실제로 안드로이드에서 작동하고 있다고 당혹스러워하고 있습니다. 정확성과 후손을 위해 귀하의 답변에 편집을 제출하겠습니다. –

+0

죄송합니다, 나는 귀하의 답변을 선제 적으로 받아 들였습니다. 한 번 실행하면되지만 같은 코드로 다시 빌드하면 다시 실패합니다. –

+0

XCode 출력에는 아무 것도 없습니까? 그리고 여전히 Android에서 실행됩니까? – HBomb

관련 문제