Hi everybody thanks for reading!
I have a project that runs perfectly on the Editor. However, when I make a build it crashes with the error:
UnityEngine.Texture2D:Internal_CreateImpl (From the stack trace)
By adding logs on the project I discvered that it happens when I am calling:
Texture2D tex = new Texture2D(1,1);
Does anyone knows why creating a texture could cause the build to crash?
Thank you so much for the help!
Lucas
Here is the fuction that calls the line above:
private async Task<(int, Texture2D)> LoadTextureAsync(string path, int id, CancellationToken ct)
{
UnityWebRequest TextureFileRequest = null;
try
{
Texture2D tex = new Texture2D(1,1);// Decrypt the source file and write it to the destination file.
MemoryStream destinationStream = new MemoryStream();
Debug.Log(path);
using (var sourceStream = File.OpenRead(path))
using (var provider = new AesCryptoServiceProvider())
{
var IV = new byte[Auxiliary.Config.EncryptionIV.Length];
sourceStream.Read(IV, 0, IV.Length);
using (var cryptoTransform = provider.CreateDecryptor(Auxiliary.Config.EncryptionKey, IV))
using (var cryptoStream = new CryptoStream(sourceStream, cryptoTransform, CryptoStreamMode.Read))
{
cryptoStream.CopyTo(destinationStream);
tex.LoadImage(destinationStream.ToArray());
return (id, tex);
}
}
}
catch (Exception e)
{
Debug.LogError("Error loading media" + e);
if (TextureFileRequest != null)
TextureFileRequest.Dispose();
return (id, null);
}
}
Here is part of the stack trace:
========== OUTPUTTING STACK TRACE ==================
0x00007FFC58B9C159 (UnityPlayer) UnityMain
0x00007FFC58B927EF (UnityPlayer) UnityMain
0x00007FFC58B7011E (UnityPlayer) UnityMain
0x00007FFC58E8340A (UnityPlayer) UnityMain
0x000001FBF46DC7A0 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Texture2D:Internal_CreateImpl (UnityEngine.Texture2D,int,int,int,UnityEngine.Experimental.Rendering.GraphicsFormat,UnityEngine.Experimental.Rendering.TextureCreationFlags,intptr)
0x000001FBF46DC603 (Mono JIT Code) UnityEngine.Texture2D:Internal_Create (UnityEngine.Texture2D,int,int,int,UnityEngine.Experimental.Rendering.GraphicsFormat,UnityEngine.Experimental.Rendering.TextureCreationFlags,intptr)
0x000001FBF46DA3AB (Mono JIT Code) UnityEngine.Texture2D:.ctor (int,int,UnityEngine.TextureFormat,int,bool,intptr)
0x000001FBF46DA283 (Mono JIT Code) UnityEngine.Texture2D:.ctor (int,int)
0x000001FBF46D9AF3 (Mono JIT Code) VIS.Data.Persistent.DataVault/d__16:MoveNext ()
0x000001FBF46D998B (Mono JIT Code) System.Runtime.CompilerServices.AsyncTaskMethodBuilder1<System.ValueTuple
2<int, UnityEngine.Texture2D>>:Start<VIS.Data.Persistent.DataVault/d__16> (VIS.Data.Persistent.DataVault/d__16&)
0x000001FBF46D927B (Mono JIT Code) VIS.Data.Persistent.DataVault:LoadTextureAsync (string,int,System.Threading.CancellationToken)
0x000001FBF463B93B (Mono JIT Code) VIS.Data.Persistent.DataVault/d__13:MoveNext ()
0x000001FBF463ACC3 (Mono JIT Code) System.Runtime.CompilerServices.AsyncTaskMethodBuilder1<bool>:Start<VIS.Data.Persistent.DataVault/<LoadMenuThumbnails>d__13> (VIS.Data.Persistent.DataVault/<LoadMenuThumbnails>d__13&) 0x000001FBF463AB6B (Mono JIT Code) VIS.Data.Persistent.DataVault:LoadMenuThumbnails (System.Threading.CancellationToken) 0x000001FBF463A843 (Mono JIT Code) VIS.Data.DataManager/<LoadHomeThumbnailsAsync>d__27:MoveNext () 0x000001FBF463A733 (Mono JIT Code) System.Runtime.CompilerServices.AsyncTaskMethodBuilder
1:Start<VIS.Data.DataManager/d__27> (VIS.Data.DataManager/d__27&)
0x000001FBF463A5F3 (Mono JIT Code) VIS.Data.DataManager:LoadHomeThumbnailsAsync (System.Threading.CancellationToken)
0x000001FBF4639C1B (Mono JIT Code) VIS.Core.AppManager/d__41:MoveNext ()