Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency to libjack64.dll crashes Unity 2019 #15

Closed
Schroedingers-Cat opened this issue Aug 2, 2019 · 14 comments
Closed

Dependency to libjack64.dll crashes Unity 2019 #15

Schroedingers-Cat opened this issue Aug 2, 2019 · 14 comments

Comments

@Schroedingers-Cat
Copy link
Contributor

Opening the sample project included within this repository, Unity 2019 instantly crashes during project loading while accessing the dependency libjack64.dll. This is reproducible on 9d3a32c but also all working previous commits are affected. The plugin from commit 9d3a32c has been built using Jack 1.9.11 libraries and the exact version of this library is installed on the systems where Unity 2019 crashes. This rules out incompatible jack library versions. Unity 5-2018 are not affected by this behaviour. The platform is Windows 10 x64 1809 and 1903.

How to reproduce:

  1. Check out this repo at 9d3a32c (current master)
  2. Install Jack 1.9.11 from here
  3. Open the included sample project with Unity 5-2018
  4. The Unity editor should load and open up
  5. Close the Unity editor
  6. Open the sample project with Unity 2019
  7. During project upgrade/loading, the editor will silently crash

Side note: It is also possible to delete any asset from the "Asset" directory except for the "Plugins" directory, ruling out any C# scripts as cause for the crash.

This project already uses the latest native audio SDK from Unity, so that cannot cause the problem.

Checking the editor log from "%localappdata%\Unity\Editor\Editor.log", the crash happens just after Unity found all compatible native plugins:

Refreshing native plugins compatible for Editor in 2009.80 ms, found 3 plugins.

When creating a debug version of the plugin with VS 2019 and setting up breakpoints to all available functions or constructors and starting the Unity 2019 editor with VS in debug mode, it seems that Unity actually never get's to run any line of code from the plugin. VS will instead report a crash in the external dependency of this plugin "libjack64.dll".

Removing any dependency to jack.h (like done here Schroedingers-Cat@9aa82f0) fixes the crash for Unity 2019 (but also removes any functionality of this plugin).

@Schroedingers-Cat
Copy link
Contributor Author

This also affects builds made with Unity. However, the latest version producing working builds with Jack is Unity 2017.1.5.
It also happens with a minimal Unity project simply marshalling the libjack64.dll and calling jack_client_open() from a C# script/MonoBehaviour. In that case, the crash occurs when going into playmode. So:

  • any access to libjack64.dll causes a crash
  • builds made with versions from 2017.1.5 onwards crash accessing libjack64.dll
  • Unity editor version 2019.1 and onwards crash opening a project with a native library accessing libjack64.dll

I've created a minimal console application utilising the Jack 1.9.11 library on Windows 10 1903 x64 and Visual Studio 2019 (v142 platform toolset and Windows SDK 10.0.18362). That one crashes before the "hello world" line, too. MinimalJack-Console.zip
Building with the VS2017 toolchain (v141 platform toolset and Windows SDK 10.0.17763) and VS2015 toolchain (v140 platform toolset and Windows SDK 8.1) also crashes the console app instantly. I wonder what Unity 2018 and 2017 do differently to access the library without crashing.

@Schroedingers-Cat
Copy link
Contributor Author

Disabling the address space layout randomization feature in the linker setting fixes the crash within the minimal jack console application:
grafik

That makes it likely that a sudden change in Unity's build system is causing this problem in affected versions. The way I see it, this is a problem with the jack library itself. I'll try to contact the jack developers.

@Schroedingers-Cat
Copy link
Contributor Author

Schroedingers-Cat commented Sep 4, 2019

So it seems that the jack developers have been informed about this problem, but didn't do anything until this point: jackaudio/jack2#332
Part of the problem might be that none of the current maintainers is able to build Jack on Windows.

For the time being, there is an insecure workaround on Windows 10:

  1. Open Windows Defender Security Center
  2. Select App & browser control from the sidebar
  3. Scroll down to and click on settings for exploit protection
  4. Disable Randomize memory allocations (Bottom-up ASLR)
  5. Restart Windows

Note: this option can also be set per-application, which might be desirable.

On Windows 7, the equivalent of this workaround seems to be setting the registry key HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\MoveImages to 0 like explained here: https://stackoverflow.com/questions/9560993/how-do-you-disable-aslr-address-space-layout-randomization-on-windows-7-x64

@dburongarcia
Copy link

dburongarcia commented Jun 11, 2020

Hello, @Schroedingers-Cat I tried your workaround but Unity is still crashing whenever I try to enter in play mode with the test scenes. Unity just closes and it also closes Jack server.
I tried with both the master and dev branch, and also just importing the JackAudioForUnity and copying the AudioPlugin-JackAudioForUnity.dll from Plugins in the repo.
I'm using Windows 10 and Unity 2019.4.0f1. Any tips? Thanks

@Schroedingers-Cat
Copy link
Contributor Author

Schroedingers-Cat commented Jun 11, 2020

This issue is about the crashes upon accessing the jack dll when opening a Unity project. Your problem seems to be related to crashing when running a scene, so it's likely a different issue. I've answered your question on the Unity forum.

@dburongarcia
Copy link

Hi, I will follow in Unity forum then. Thanks https://forum.unity.com/threads/multiple-audio-channels-to-multiple-audio-outputs.522738/

@Schroedingers-Cat
Copy link
Contributor Author

So the solution is either #15 (comment) or to build Jack on Windows from Source Code with a more recent version of VS which has the ASLR feature implicitly enabled by default.

@alfonso73
Copy link

alfonso73 commented Jan 26, 2021

Note: this option can also be set per-application, which might be desirable.

@Schroedingers-Cat thanks for the hint.
Should this option be set for scsynth.exe, sclang.exe, qjackctl.exe and jack.exe? Or only on the SC side or Jack side?
thanks

oops i realized the post is about Unity. But on SuperCollider Win10 64x there's the same exact problem. How did you change the option on an app base? On the Unity side or on the Jack side or both?

@Schroedingers-Cat
Copy link
Contributor Author

You'll need to set the option for every executable that has a dependency to JACK. You can use a tool like this to find what libraries are necessary for a given software: https://github.com/lucasg/Dependencies

@alfonso73
Copy link

Many thanks @Schroedingers-Cat !

@alfonso73
Copy link

Should i set this option for .exe only or for .dll too?

@Schroedingers-Cat
Copy link
Contributor Author

Schroedingers-Cat commented Jan 28, 2021

Should i set this option for .exe only or for .dll too?

I had to set the option only for the program loading the dll.

@dyfer
Copy link

dyfer commented Mar 8, 2021

FYI this has been fixed in Jack 1.9.17 - JackRouter has been recompiled and shouldn't cause this crash anymore, AFAIU.

@Schroedingers-Cat
Copy link
Contributor Author

So great to see the devs have had the time to work on windows releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants