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

[Critical] .Net4.x crashes #40

Open
sekkit opened this issue Aug 4, 2019 · 7 comments
Open

[Critical] .Net4.x crashes #40

sekkit opened this issue Aug 4, 2019 · 7 comments
Assignees
Labels

Comments

@sekkit
Copy link

sekkit commented Aug 4, 2019

Unity2018.4.5f1, MacOS works fine, but windows crashes.

issue reproduce: When calling MyGameAbstractBaseBallScriptUpdate

CSharp code:

                public override void Update()
		{
			if (CppHandle != 0)
			{
				int thisHandle = CppHandle;
				NativeScript.Bindings.MyGameAbstractBaseBallScriptUpdate(thisHandle);
				if (NativeScript.Bindings.UnhandledCppException != null)
				{
					Exception ex = NativeScript.Bindings.UnhandledCppException;
					NativeScript.Bindings.UnhandledCppException = null;
					throw ex;
				}
			}
		}

When executes to the line: auto returnValue = Plugin::UnityEngineTimePropertyGetDeltaTime();
It crashes.
C++ code:

System::Single UnityEngine::Time::GetDeltaTime()
	{
		auto returnValue = Plugin::UnityEngineTimePropertyGetDeltaTime();
		if (Plugin::unhandledCsharpException)
		{
			System::Exception* ex = Plugin::unhandledCsharpException;
			Plugin::unhandledCsharpException = nullptr;
			ex->ThrowReferenceToThis();
			delete ex;
		}
		return returnValue;
	}

Exception thrown at 0x00007FFDE974D5D9 (NativeScript_temp.dll) in Unity.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

Stacktrace:

========== OUTPUTTING STACK TRACE ==================

0x00007FFE2AEBD5D9 (NativeScript_temp) [c:\projects\research\unitycpp\unity\libs\cppsource\nativescript\bindings.cpp:5498] UnityEngine::Time::GetDeltaTime 
0x00007FFE2AEA3B9A (NativeScript_temp) [c:\projects\research\unitycpp\unity\libs\cppsource\game\game.cpp:38] MyGame::BallScript::Update 
0x00007FFE2AEBFCA7 (NativeScript_temp) [c:\projects\research\unitycpp\unity\libs\cppsource\nativescript\bindings.cpp:5819] MyGameAbstractBaseBallScriptUpdate 
0x000000004E2DC2C5 (Mono JIT Code) (wrapper managed-to-native) object:wrapper_native_00007FFE2AEA12AD (int)
0x000000004E367898 (Mono JIT Code) [C:\Projects\Research\unitycpp\Unity\Assets\NativeScript\Bindings.cs:2121] MyGame.BaseBallScript:Update () 
0x000000004EE32FC8 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
0x00007FFDBABCB970 (mono-2.0-bdwgc) [c:\users\bokken\builds\vm\mono\mono\mini\mini-runtime.c:2809] mono_jit_runtime_invoke 
0x00007FFDBAB51922 (mono-2.0-bdwgc) [c:\users\bokken\builds\vm\mono\mono\metadata\object.c:2919] do_runtime_invoke 
0x00007FFDBAB5A91F (mono-2.0-bdwgc) [c:\users\bokken\builds\vm\mono\mono\metadata\object.c:2966] mono_runtime_invoke 
0x0000000140C03DAA (Unity) scripting_method_invoke
0x0000000140BF400A (Unity) ScriptingInvocation::Invoke
0x0000000140BBCB57 (Unity) MonoBehaviour::CallMethodIfAvailable
0x0000000140BBD271 (Unity) MonoBehaviour::CallUpdateMethod
0x00000001406EEBDC (Unity) BaseBehaviourManager::CommonUpdate<BehaviourManager>
0x00000001406F5266 (Unity) BehaviourManager::Update
0x0000000140960373 (Unity) `InitPlayerLoopCallbacks'::`2'::UpdateScriptRunBehaviourUpdateRegistrator::Forward
0x000000014095EFC7 (Unity) ExecutePlayerLoop
0x000000014095F093 (Unity) ExecutePlayerLoop
0x0000000140962351 (Unity) PlayerLoop
0x0000000141349FDF (Unity) PlayerLoopController::UpdateScene
0x0000000141339383 (Unity) PlayerLoopController::EnterPlayMode
0x0000000141345323 (Unity) PlayerLoopController::SetIsPlaying
0x0000000141348282 (Unity) Application::TickTimer
0x00000001414A4C53 (Unity) MainMessageLoop
0x00000001414A693D (Unity) WinMain
0x000000014249BABA (Unity) __scrt_common_main_seh
0x00007FFE3E237BD4 (KERNEL32) BaseThreadInitThunk
0x00007FFE3EBCCE71 (ntdll) RtlUserThreadStart


Game booted up
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
NativeScript.Bindings:UnityEngineDebugMethodLogSystemObject(Int32) (at Assets\NativeScript\Bindings.cs:1372)
System.Object:wrapper_native_00007FFE2AEA18DE(IntPtr, Int32, InitMode)
NativeScript.Bindings:OpenPlugin(InitMode) (at Assets\NativeScript\Bindings.cs:836)
NativeScript.Bindings:Open(Int32) (at Assets\NativeScript\Bindings.cs:622)
NativeScript.BootScript:Awake() (at Assets\NativeScript\BootScript.cs:36)
 
(Filename: Assets/NativeScript/Bindings.cs Line: 1372)

Crash!!!
@jacksondunstan
Copy link
Owner

It's working fine for me on Windows. Can you please provide more information such as your version of Windows, your C++ compiler version, the reproduction rate of the crash, and any modifications you've made since cloning the repo?

@sekkit
Copy link
Author

sekkit commented Aug 6, 2019

It's working fine for me on Windows. Can you please provide more information such as your version of Windows, your C++ compiler version, the reproduction rate of the crash, and any modifications you've made since cloning the repo?

Windows 10 1903 latest 64bit
Unity2018.4.5f1
VS2015/VS2017/VS2019

switching to .net4.x, it crashes everytime^^
Tested on your original project, no code changed at all.

@jacksondunstan
Copy link
Owner

I am also seeing the issue in 2018.3.12f1 after switching to .NET 4.x and running in the editor. I'll investigate a solution. In the meantime, please use .NET 3.5.

@jacksondunstan jacksondunstan self-assigned this Aug 6, 2019
@sekkit
Copy link
Author

sekkit commented Jan 25, 2021

Has the issue been solved?

@jacksondunstan
Copy link
Owner

There have been several bug fixes since the issue was reported, so it's possible it's fixed. Can you reproduce with the latest version?

@sekkit
Copy link
Author

sekkit commented Jan 28, 2021

ok. btw I hope coroutine feature could be implemented. either by upgrading c++ version or the other.
I've got a plan for impl automatic types generation feature with Mono.Cecil (including nested types). which would help with developing larger projects.

@jacksondunstan
Copy link
Owner

Sounds cool. Definitely feel free to submit a PR if you implement such a feature.

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

No branches or pull requests

2 participants