a week ago
Getting crashes on large baked scene, fine on small one. Only in 2020, fine in u6 so I'd like to verify a few assumptions.
Native.Interface.AudioSceneIRReadMemory and AudioGeometryReadMeshMemory comment says that it reads a native array into an object. Does "read" mean copy? I'm wondering if I'm disposing the temp native array too early, I mean that wouldn't explain the non-crash on small scenes but I can't come up with a different explanation.
The temp native array that needs to be created to fix the lack of .unityWebRequest.handler.nativeData should be large enough. If you could check...
IntPtr _geometryMemory = IntPtr.Zero;
IEnumerator LoadGeometryAsync(string relativePath)
{
string path = Application.streamingAssetsPath+"/"+relativePath;
#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
path = "file://" + path;
#endif
Debug.Log($"Loading Geometry {name} from StreamingAssets {path}",gameObject);
float startTime = Time.realtimeSinceStartup;
Profiler.BeginSample("MetaXRAcousticGeometry web request get");
// Create a custom DownloadHandler with pre-allocated NativeArray<byte>
int dataLength = 2048*2048;
NativeDownloadHandler downloadHandler = new NativeDownloadHandler(dataLength);
var unityWebRequest = UnityEngine.Networking.UnityWebRequest.Get(path);
unityWebRequest.downloadHandler = downloadHandler;
Profiler.EndSample();
yield return unityWebRequest.SendWebRequest();
if(!string.IsNullOrEmpty(unityWebRequest.error)) {
Debug.LogError($"web request: done={unityWebRequest.isDone}: {unityWebRequest.error}",gameObject);
yield break;
}
float readTime = Time.realtimeSinceStartup;
float readDuration = readTime-startTime;
Debug.Log($"Geometry {name}, read time = {readDuration}",gameObject);
// Load the data from the NativeArray byte buffer
LoadGeometryFromMemory(downloadHandler.nativeData.AsReadOnly());
}
async void LoadGeometryFromMemory(Unity.Collections.NativeArray<byte>.ReadOnly data)
{
if(data.Length==0) return;
float startTime = Time.realtimeSinceStartup;
int result = -1;
await Task.Run(() =>
{
unsafe {
IntPtr ptr = (IntPtr) Unity.Collections.LowLevel.Unsafe.NativeArrayUnsafeUtility.GetUnsafeReadOnlyPtr(data);
lock (this) {
if(geometryHandle!=IntPtr.Zero) {
result = Native.Interface.AudioGeometryReadMeshMemory(geometryHandle,ptr,(UInt64) data.Length);
GC.KeepAlive(data);
}
}
}
});
if(result==SUCCESS) {
float loadDuration = Time.realtimeSinceStartup-startTime;
Debug.Log($"Sucessfully loaded Geometry {name}, load time = {loadDuration}",gameObject);
Native.Interface.AudioGeometrySetObjectFlag(geometryHandle,ObjectFlags.ENABLED,isActiveAndEnabled);
ApplyTransform();
Native.Interface.AudioGeometrySetObjectFlag(geometryHandle,ObjectFlags.STATIC,gameObject.isStatic);
#if UNITY_EDITOR
UpdateGizmoMesh();
#endif
_isLoaded = true;
if(isActiveAndEnabled) { IncrementEnabledGeometryCount(); }
} else { Debug.Log($"Unable to read the geometry {name}",gameObject); }
}