Fixing the "Check failed: 12 == (*_" error
Troubleshooting notes for the “Check failed: 12 == (*_” error in Microsoft ClearScript V8 on macOS.
If you are running JavaScript code with Microsoft ClearScript V8, and you are doing this on the macOS operating system, you are more likely to encounter the Check failed: 12 == (*_ error.
This error appeared with two different solutions, although the causes are the same.
To explain, we added a simple example in C# below, but it is not really possible to get the error with this code :).
V8ScriptEngine? v8=new V8ScriptEngine([flags]);
string code=
"var sayi_1 = 1, sayi_2 = 2;" +
"var sonuc = sayi_1 + sayi_2;";
v8!.Execute(code);
After running this code, things get complicated when we want to access the resulting value with v8!.Script.sonuc (more precisely, the variables created inside the executed code).
- The first cause we encountered is an undefined variable value; in the example we expect the value of the sonuc variable to be 3, but let us assume there is a point we missed and our variable is undefined. In that case, when we try to access it, it immediately throws an error :). The simplest solution is to proceed by checking the variable we want to access, or to use it within a try-catch block.
if(v8!.Script.sonuc is Undefined)
{
.........
}Not related to our topic, but it is worth adding a reminder: the try-catch block and the if statement are among the things that should be used as little as possible while coding.
- The other cause is macOS: When we encountered this error for the second time, we said "let us push it to the server (Windows) and see what happens", and we saw that the code ran without any problem.
After searching around, we arrived at the solution from the related comment by the user named ClearScriptLib here.
For this problem, again there are two solutions;- Disable JIT compilation while setting the flag definitions in the V8 constructor,
- Find the location of the packages with the command "dotnet nuget locals global-packages --list", go to that directory and type the following
cd microsoft.clearscript.v8.native.osx-x64
cd 7.3.7 (This version number may vary since it is a version number)
cd runtimes
cd osx-x64
cd native
After these operations, the following file should be there:ClearScriptV8.osx-x64.dylib
Run the following command for this file, clean the project, build it and run it.
codesign --sign - --options linker-signed --force ClearScriptV8.osx-x64.dylib
Short guide
When to use it
This error appears mostly in .NET projects that embed a JavaScript engine such as V8/ClearScript. The cause may be code, environment, package version or an unexpected script value.
What to watch
- Read the stack trace together with operating system and package versions.
- Check that variables created inside the script really contain the expected values.
- Test the same code on macOS, Linux and Windows if the project needs to support them.
Common mistake
Treating a fix that works on one machine as a permanent fix is risky. Environment differences can completely change this kind of error.
A note for long-term fixes
When fixing an error, hiding the message is rarely enough. Version, operating system, dependencies, encoding, server settings and logs should be reviewed together. For a long-term fix, it is better to review the environment, dependencies and data flow together.