[UniWebView 5] Render as Texture crashed on iOS

Hi guys,

I experienced game get crashed on iOS device when using feature Render as Texture of UniWebView 5.
__** **__var texture = webView.CreateRenderedTexture(webView.Frame);__** **__
Any help?

Here is some information:

  • Unity Editor version 2022.3.20f1
  • UniWebView 5 version 5.9.2
  • iOS: 17.4.1

Here is my code:

using System;
using UnityEngine;
using UnityEngine.UI;

public class MapController : MonoBehaviour
{
[SerializeField] private UniWebView webView;

[SerializeField] private RawImage rawImage;

public bool IsLoading { get; private set; } = true;
public bool AllowMediaCapture { get; private set; } = false;

// Start is called before the first frame update
void Start()
{
UniWebViewLogger.Instance.LogLevel = UniWebViewLogger.Level.Verbose;
UniWebView.SetForwardWebConsoleToNativeOutput(true);
webView.Frame = new Rect(0, 0, Screen.width, Screen.height);
webView.OnPageFinished += OnPageFinished;
webView.OnMessageReceived += OnMessageReceived; // window.location.href = “uniwebview://game-over?score=” + myGameArea.frameNo;

var accessURL = UniWebViewHelper.StreamingAssetURLForPath(“www/”);
// var url = UniWebViewHelper.StreamingAssetURLForPath(“www/index.html”);
var url = “https://classroom-dev.servegame.com/”;
webView.Load(url);
Debug.LogWarning($“Load… {url}”);

webView.RegisterOnRequestMediaCapturePermission(RegisterOnRequestMediaCapturePermissionHandler);
webView.RegisterShouldHandleRequest(RegisterShouldHandleRequestHandler);

// Start the rendering process.
webView.StartSnapshotForRendering();
}

private bool RegisterShouldHandleRequestHandler(UniWebViewChannelMethodHandleRequest request)
{
return true;
}

private UniWebViewMediaCapturePermissionDecision RegisterOnRequestMediaCapturePermissionHandler(
UniWebViewChannelMethodMediaCapturePermission permission)
{
AllowMediaCapture = true;
Debug.LogWarning(“RegisterOnRequestMediaCapturePermissionHandler”);
return UniWebViewMediaCapturePermissionDecision.Grant;
}

private void OnMessageReceived(UniWebView webView, UniWebViewMessage message)
{
// if (message.Path.Equals(“game-over”)) {
// var score = message.Args[“score”];
// Debug.Log("Your final score is: " + score);

// // Restart the game after 3 second
// Invoke(“Restart”, 3.0f);
// }
}

private void OnPageFinished(UniWebView webView, int statusCode, string url)
{
IsLoading = true;

// Start the rendering process.
webView.StartSnapshotForRendering(onStarted: texture =>
{
rawImage.texture = texture;
});
}

private void RenderWebView()
{
if (webView != null)
{
// webView.Stop();
var texture = webView.CreateRenderedTexture(webView.Frame);
// Destroy(rawImage.texture);
// rawImage.texture = texture;
// Debug.Log(“Update texture…”);
}
}

void OnDestroy()
{
// clean up webview footprint
webView.StopSnapshotForRendering();
Destroy(rawImage.texture);
webView = null;
}

float cooldownTime = 3;

// Update is called once per frame
void Update()
{
if (IsLoading)
{
cooldownTime -= Time.deltaTime;
if (cooldownTime <= 0)
{
RenderWebView();
cooldownTime = 3f;
}
}
}
}

Ask UniWebView support for help, not us.