godotengine / godotengine/godot-docs
System.AccessViolationException when creating a new Node2D in a unit test with xUnit
- Dominant language
- reStructuredText
- Stars
- 5.7k
- Forks
- 3.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 25
Description
### Tested versions
- Reproductible in Godot 4.2.1 & 4.2.2
### System information
Windows 10 - Godot 4.2.2
### Issue description
# System.AccessViolationException when creating a new Node2D in a unit test with xUnit
## Description
When running a simple unit test using xUnit that creates a new instance of `Node2D`, the test host process crashes with a `System.AccessViolationException`. This issue occurs consistently and seems to indicate memory corruption.
## Reproducibility
100% - The error occurs every time the test is run.
## Additional Information
- the issue occurs with other nodes (not just `Node2D`).
### Steps to reproduce
## Steps to Reproduce
1. Create a new project in Godot.
2. Add a C# script file named `UnitTest1.cs` with the following code:
```csharp
using Godot;
using Xunit;
namespace Test2
{
public class UnitTest1
{
[Fact]
public void Test1()
{
var o = new Node2D();
}
}
}
```
3. Run the unit test using the `dotnet test` command.
## Expected Result
The test should pass without any exceptions.
## Actual Result
The test host process crashes with the following error:
The active test run was aborted. Reason: Test host process crashed : Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Godot.NativeInterop.NativeFuncs.godotsharp_string_new_with_utf16_chars(Godot.NativeInterop.godot_string ByRef, Char*)
at Godot.NativeInterop.Marshaling.ConvertStringToNative(System.String)
at Godot.NativeInterop.NativeFuncs.godotsharp_string_name_new_from_string(System.String)
at Godot.StringName..ctor(System.String)
at Godot.StringName.op_Implicit(System.String)
at Godot.Node2D..cctor()
at Godot.Node2D..ctor()
at Test2.UnitTest1.Test1()
...
### Minimal reproduction project (MRP)
N/A
```
net8.0
enable
enable
false
true
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.