WebGL Failing to Load - unreachable exception in GetNonCryptographicallySecureRandomBytes

Hi,

I’ve recently made some changes to my project, adding SQLite for WebGL from GitHub - gilzoide/unity-sqlite-net: SQLite-net for Unity, supports Windows, Linux, macOS, iOS, tvOS, visionOS, Android and WebGL.

Previously, I was using Unity 6000.0.26f1.

After making my changes (there are many, it was a whole project migration), my CI build no longer runs in WebGL - it just stops before finishing loading the first scene. There were no errors.

Interestingly, local builds worked fine, just the ones from CI.
I assumed it was a stripping issue or a compression issue, but I changed all the settings and still hit the same issue.

I then updated to Unity 6000.0.35f1, and now I still have the same issue, but I do get the following error stack:

Uncaught RuntimeError: unreachable
    at Sys_GetNonCryptographicallySecureRandomBytes_m6E685E563363C27974F36F253C28B4F19D9FACF9 (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[52309]:0x13055bc)
    at Interop_GetRandomBytes_mCA054362D47D8B1BB32A7501F26A646DD8CA6947 (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[22044]:0x71606e)
    at Guid_NewGuid_m1F4894E8DC089811D6252148AD5858E58D43A7BD (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[2253]:0x100dc2)
    at InputAction__ctor_m2C9BD26403717DAA628B90D4CD2A4057233A1A44 (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[22240]:0x723eb0)
    at RuntimeInvoker_TrueVoid_t4861ACF8F4594C3437BB48B6E56783494B843915(void (*)(), MethodInfo const*, void*, void**, void*) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[121095]:0x23987cb)
    at il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const*, void*, void**) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[14310]:0x49db96)
    at il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[2985]:0x12e307)
    at il2cpp::vm::Runtime::ObjectInitException(Il2CppObject*, Il2CppException**) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[42219]:0xf9ee59)
    at il2cpp_runtime_object_init_exception (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[25474]:0x89f216)
    at Scripting::RuntimeObjectInitLogException(ScriptingObjectPtr, ScriptingCtorCache*) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[6394]:0x2112ff)
    at ArrayOfManagedObjectsTransferer::iterator::SetupManagedObjectTransferer() (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[8423]:0x2a4590)
    at void Transfer_ManagedObject<StreamedBinaryRead, true>(SerializationCommandArguments const&, RuntimeSerializationCommandInfo&) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[76210]:0x1a87cdb)
    at void TransferField_LinearCollection<StreamedBinaryRead>(SerializationCommandArguments const&, RuntimeSerializationCommandInfo&) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[17826]:0x5b742f)
    at void ExecuteSerializationCommands<StreamedBinaryRead>(SerializationCommandProvider&, StreamedBinaryRead&, GeneralMonoObject const&) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[4559]:0x1977d9)
    at void Transfer_ManagedObject<StreamedBinaryRead, true>(SerializationCommandArguments const&, RuntimeSerializationCommandInfo&) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[76210]:0x1a87ce7)
    at void TransferField_LinearCollection<StreamedBinaryRead>(SerializationCommandArguments const&, RuntimeSerializationCommandInfo&) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[17826]:0x5b742f)
    at void ExecuteSerializationCommands<StreamedBinaryWrite>(core::vector<SerializationCommand, core::allocator<SerializationCommand, 0ul>> const&, StreamedBinaryWrite&, GeneralMonoObject const&) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[4877]:0x1aa28a)
    at void TransferScriptingObject<StreamedBinaryRead>(StreamedBinaryRead&, ScriptingObjectPtr, ScriptingClassPtr, SerializationCache::Data*&) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[39384]:0xdb0392)
    at SerializableManagedRefTransfer::Transfer(Object*, SerializableManagedRef&, StreamedBinaryRead&, bool) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[54560]:0x13a7efc)
    at MonoBehaviour::VirtualRedirectTransfer(StreamedBinaryRead&) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[137319]:0x2635df5)
    at SerializedFile::ReadObject(long long, ObjectCreationMode, bool, TypeTree const**, bool*, Object&) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[54502]:0x13a1b3b)
    at PersistentManager::ReadAndActivateObjectThreaded(int, SerializedObjectIdentifier const&, SerializedFile*, bool, bool, PersistentManager::LockFlags) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[21305]:0x6dd7b6)
    at PersistentManager::LoadFileCompletelyThreaded(core::basic_string_ref<char>, long long*, int*, int, PersistentManager::LoadFlags, LoadProgress&, PersistentManager::LockFlags) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[21307]:0x6ddcb8)
    at RunWebGLPlayer() (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[56183]:0x1400237)
    at InitWebGLPlayer(int, char**) (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[144971]:0x27a294f)
    at main (http://localhost:3000/unity/Desktop/Build/Desktop.wasm.br:wasm-function[83561]:0x1c85919)
    at Module._main (http://localhost:3000/unity/Desktop/Build/Desktop.framework.js.br:50:357451)
    at callMain (http://localhost:3000/unity/Desktop/Build/Desktop.framework.js.br:50:359223)
    at doRun (http://localhost:3000/unity/Desktop/Build/Desktop.framework.js.br:50:359637)
    at run (http://localhost:3000/unity/Desktop/Build/Desktop.framework.js.br:50:359809)
    at runCaller (http://localhost:3000/unity/Desktop/Build/Desktop.framework.js.br:50:358923)
    at Object.removeRunDependency (http://localhost:3000/unity/Desktop/Build/Desktop.framework.js.br:50:12315)
    at http://localhost:3000/unity/Desktop/Build/Desktop.framework.js.br:50:3695
    at doCallback (http://localhost:3000/unity/Desktop/Build/Desktop.framework.js.br:50:71277)
    at done (http://localhost:3000/unity/Desktop/Build/Desktop.framework.js.br:50:71431)
    at transaction.oncomplete (http://localhost:3000/unity/Desktop/Build/Desktop.framework.js.br:50:65072)

As far as I can tell, something has made GUID’s not work? Possibly some kind of assembly conflict?

Any insights much appreciated, I’ve been trying various things today with no success. My next steps will be to start with a blank project and slowly add packages until it breaks (current theory is the new input package plus the SQLite package),

The assembly code, if it’s useful:

(func $Sys_GetNonCryptographicallySecureRandomBytes_m6E685E563363C27974F36F253C28B4F19D9FACF9 (;52309;) (param $var0 i32) (param $var1 i32) (param $var2 i32)
    (local $var3 i32)
    (local $var4 i32)
    (local $var5 i32)
    (local $var6 i64)
    global.get $__stack_pointer
    i32.const 16
    i32.sub
    local.tee $var4
    global.set $__stack_pointer
    i32.const 7975581
    i32.load8_u
    i32.eqz
    if
      i32.const 5751420
      call $il2cpp_codegen_initialize_runtime_metadata(unsigned long*)
      i32.const 7975581
      i32.const 1
      i32.store8
    end
    local.get $var4
    i32.const 12
    i32.add
    i32.const 5751420
    i32.load
    call $StackTraceSentry::StackTraceSentry(MethodInfo const*)
    try $label7
      block $label0
        i32.const 7975565
        i32.load8_u
        br_if $label0
        i32.const 0
        local.set $var2
        block $label1
          i32.const 5751296
          i32.load
          i32.const -1
          i32.ne
          br_if $label1
          block $label2
            loop $label3
              local.get $var4
              i32.const 524288
              i32.store
              i32.const 189160
              i32.const 0
              local.get $var4
              call $open
              local.tee $var3
              i32.const -1
              i32.ne
              br_if $label2
              i32.const 7003968
              i32.load
              local.tee $var3
              i32.const 27
              i32.eq
              br_if $label3
            end $label3
            local.get $var3
            i32.const 44
            i32.ne
            br_if $label1
            i32.const 7975565
            i32.const 1
            i32.store8
            br $label1
          end $label2
          i32.const 5751296
          local.get $var3
          i32.const 5751296
          i32.load
          local.tee $var5
          local.get $var5
          i32.const -1
          i32.eq
          local.tee $var5
          select
          i32.store
          local.get $var5
          br_if $label1
          local.get $var3
          call $close
          drop
        end $label1
        i32.const 5751296
        i32.load
        i32.const -1
        i32.eq
        br_if $label0
        loop $label5
          block $label4 (result i32)
            i32.const 5751296
            i32.load
            local.get $var0
            local.get $var2
            i32.add
            local.get $var1
            local.get $var2
            i32.sub
            call $read
            local.tee $var3
            i32.const -1
            i32.eq
            if
              i32.const 5
              i32.const 4
              i32.const 7003968
              i32.load
              i32.const 27
              i32.eq
              select
              br $label4
            end
            local.get $var2
            local.get $var3
            i32.add
            local.set $var2
            i32.const 0
          end $label4
          local.set $var3
          local.get $var1
          local.get $var2
          i32.eq
          br_if $label0
          local.get $var3
          i32.const 4
          i32.ne
          br_if $label5
        end $label5
      end $label0
      i32.const 0
      local.set $var3
      i32.const 7975566
      i32.load8_u
      i32.eqz
      if
        unreachable  # It breaks here
      end
      local.get $var1
      i32.const 0
      local.get $var1
      i32.const 0
      i32.gt_s
      select
      local.set $var1
      i32.const 0
      local.set $var2
      loop $label6
        local.get $var1
        local.get $var2
        i32.ne
        if
          local.get $var2
          i32.const 3
          i32.and
          i32.eqz
          if
            i32.const 5213940
            i32.const 5213952
            i64.load16_u
            i32.const 5213946
            i64.load32_u align=2
            i32.const 5213950
            i64.load16_u
            i64.const 32
            i64.shl
            i64.or
            i32.const 5213940
            i64.load32_u align=2
            i32.const 5213944
            i64.load16_u
            i64.const 32
            i64.shl
            i64.or
            i64.mul
            i64.add
            local.tee $var6
            i64.store16
            i32.const 5213944
            local.get $var6
            i64.const 32
            i64.shr_u
            i64.store16
            i32.const 5213942
            local.get $var6
            i64.const 16
            i64.shr_u
            i64.store16
            local.get $var6
            i64.const 281474976710655
            i64.and
            i64.const 17
            i64.shr_u
            i32.wrap_i64
            local.set $var3
          end
          local.get $var0
          local.get $var2
          i32.add
          local.tee $var5
          local.get $var5
          i32.load8_u
          local.get $var3
          i32.xor
          i32.store8
          local.get $var2
          i32.const 1
          i32.add
          local.set $var2
          local.get $var3
          i32.const 8
          i32.shr_s
          local.set $var3
          br $label6
        end
      end $label6
      i32.const 7990852
      i32.load
      local.tee $var0
      local.get $var0
      i32.load offset=4
      i32.const 20
      i32.sub
      i32.store offset=4
      local.get $var4
      i32.const 16
      i32.add
      global.set $__stack_pointer
      return
    catch_all
      local.get $var4
      global.set $__stack_pointer
      i32.const 7990852
      i32.load
      local.tee $var0
      local.get $var0
      i32.load offset=4
      i32.const 20
      i32.sub
      i32.store offset=4
      rethrow $label7
    end $label7
    unreachable
  )

I’m guess that your C++ Compiler Configuration in Player Settings changed from Release to Debug. Those unreachable’s are I think from C++ assert’s in Sys_GetNonCryptographicallySecureRandomBytes. Changing the compiler configuration back to Release will remove them.

Of course hitting this asserts is still a bug - something unexpected is still happening. Please report this as a bug.

Hi, thanks for the reply.

I was actually using Master C++ compilation settings.
I don’t hit the issue when doing a development build.
I hit the same issue with Debug, Release, or Master C++ Compilation.

I’m going to try a minimum reproduction project today and then I can file a bug report if I can reliably reproduce the issue.

I will also try 6000.0.36, just in case.

Ticket created: IN-94351 with simple reproduction project.
Also reported to the plugin github page: Exception on launch in Unity 6000.0.35f1 · Issue #47 · gilzoide/unity-sqlite-net · GitHub

Update here (also updated on the project github and Unity bug report, but in case anyone else hits this) - the particular combination is the sqlite plugin combined with ANY Code Optimization setting except “Shorter Build Times”. I’m assuming development builds don’t do the code optimization step, which is why they work. I had been using “Disk Size with LTO”.

Work around for now is to set Code Optimization to “Shorter Build Times”