Search Unity

Store 10 Universal D3D IL2CPP: Application.Quit(); works with XAML not with D3D

Discussion in 'Windows' started by AVOlight, Jan 24, 2016.

  1. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    Is there anything else I need to do to get Application.Quit(); to work?

    --
    Heres the exception:

    Microsoft C++ exception: Platform::COMException ^ at memory location ... HRESULT:0x8000FFFF Catastrophic failure

    WinRT information: Catastrophic failure

    Code (CSharp):
    1. >    KernelBase.dll!00007ffbb10e1f08()    Unknown
    2.      vcruntime140_app.dll!00007ffba6ad4522()    Unknown
    3.      vccorlib140_app.dll!00007ffb92dcba35()    Unknown
    4.      UnityPlayer.dll!__abi_WinRTraiseException(long)    Unknown
    5.      UnityPlayer.dll!__abi_ThrowIfFailed(long)    Unknown
    6.      UnityPlayer.dll!Windows::UI::Xaml::IApplicationStatics::Current::get(void)    Unknown
    7.      UnityPlayer.dll!Windows::UI::Xaml::Application::Current::get(void)    Unknown
    8.      UnityPlayer.dll!UnityPlayer::OutputDebugInfo(void)    Unknown
    9.      UnityPlayer.dll!UnityPlayer::AppCallbacks::DoPerformUpdateAndRender(void)    Unknown
    10.      UnityPlayer.dll!UnityPlayer::AppCallbacks::PerformUpdateAndRender(void)    Unknown
    11.      UnityPlayer.dll!UnityPlayer::AppCallbacks::_AppThreadImplementation(void *)    Unknown
    12.      UnityPlayer.dll!UnityPlayer::AppCallbacks::_AppThread(void *)    Unknown
    13.      UnityPlayer.dll!std::_Vector_const_iterator<class std::_Vector_val<struct std::_Simple_types<class Platform::String ^> > >::operator<(class std::_Vector_const_iterator<class std::_Vector_val<struct std::_Simple_types<class Platform::String ^> > > const &)    Unknown
    14.      UnityPlayer.dll!Platform::Details::__abi_FunctorCapture<class <lambda_2852166a1bcbafb0670719dff45fb12f>,void,struct Windows::Foundation::IAsyncAction ^>::Invoke(struct Windows::Foundation::IAsyncAction ^)    Unknown
    15.      UnityPlayer.dll!Windows::System::Threading::WorkItemHandler::Invoke(struct Windows::Foundation::IAsyncAction ^)    Unknown
    16.      UnityPlayer.dll!Windows::System::Threading::WorkItemHandler::[Windows::System::Threading::WorkItemHandler::__abi_IDelegate]::__abi_Windows_System_Threading_WorkItemHandler___abi_IDelegate____abi_Invoke(struct Windows::Foundation::IAsyncAction ^)    Unknown
    17.      threadpoolwinrt.dll!00007ffb9e913f4d()    Unknown
    18.      threadpoolwinrt.dll!00007ffb9e91b2a7()    Unknown
    19.      kernel32.dll!00007ffbb4608102()    Unknown
    20.      ntdll.dll!00007ffbb48ac2e4()    Unknown
    21.  
    ---

    works with XAML build type
     
    Last edited: Jan 24, 2016
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Looks like it's our bug - could we get a bug report? I'll look for a workaround for you on monday.
     
  3. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    Thank you,
    its already monday for me :)

    will do after sleep, unless someone else reports by then
     
  4. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    Case 764378
     
  5. bakanekofr

    bakanekofr

    Joined:
    Feb 28, 2014
    Posts:
    122
    Is adding a Quit option authorized on Windows Store? I've removed it from my game as I though it wasn't.

    BTW, I also had a crash when using Application.Quit (Windows 10 PC, D3D, IL2CPP).
     
  6. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    yea hoping for a workaround, put time into the animation for it so prefer to keep it in :)
    don't know why it wouldn't be authorized,
     
  7. bakanekofr

    bakanekofr

    Joined:
    Feb 28, 2014
    Posts:
    122
  8. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    @bakanekofr Thank you for the info :)

    :( but my quit animation
    personally i think full screen apps should always have a quit option, there all kinds of different customers out there, and they all see things differently
     
  9. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    for consistency, since its working in XAML, i hope they do the same with D3D
     
  10. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    I found a workaround for you for il2cpp scripting backend:

    In C#:

    Code (csharp):
    1.  
    2. [DllImport("__Internal")]
    3. private static extern void QuitApplication();
    4.  
    5. void OnGUI()
    6. {
    7.     if (GUI.Button(new Rect(100, 100, 200, 80), "Quit"))
    8.         UnityEngine.WSA.Application.InvokeOnUIThread(() => QuitApplication(), false);
    9. }
    In addition to that, create a C++ source code file (".cpp"), drop it into your Unity project and mark it as compatible with "Windows Store" in the plugin inspector. Add this code to it:

    Code (csharp):
    1. #include <roapi.h>
    2. #include <Windows.ApplicationModel.core.h>
    3. #include <wrl.h>
    4.  
    5. using namespace ABI::Windows::ApplicationModel::Core;
    6. using namespace Microsoft::WRL;
    7. using namespace Microsoft::WRL::Wrappers;
    8.  
    9. extern "C" void __stdcall QuitApplication()
    10. {
    11.     ComPtr<ICoreApplicationExit> coreApplicationExit;
    12.     RoGetActivationFactory(HStringReference(L"Windows.ApplicationModel.Core.CoreApplication").Get(), __uuidof(ICoreApplicationExit), &coreApplicationExit);
    13.     coreApplicationExit->Exit();
    14. }
    As for Application.Quit() - we will be fixing it.
     
    AVOlight likes this.
  11. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    @Tautvydas Zilys Thank You Again!!!

    c++ looks so very odd to me
    so is this how i would go about making my own IAP workaround, until Unity IAP supports IL2CPP
     
  12. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Pretty much, yes. You could also compile it into a DLL if you have several source files, it will make managing them easier.
     
  13. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    Just trying to understand how the namespaces work different,
    right now the IL2CppOutputProject doesn't show certain namespaces that are in the main Universal Windows project

    what do i use in IL2CppOutputProject for using namespace Platform; ?
     
  14. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    There's one caveat... You can't use that namespace in IL2CPPOutputProject, as that namespace is exclusive to C++/CX, and that is not enabled in IL2CPPOutputProject, as it increases build times significantly and IL2CPP doesn't use that functionality anyway. Only vanilla C++ can be used in that project.

    If you want to use Platform namespace and the rest of C++/CX, you need to create a new Visual Studio project (you'll probably want a DLL) and then enable windows runtime extensions (make sure to do it for all configurations and all platforms, as displayed in the second image):




    Then you can just PInvoke into compiled dll by specifying its file name (e. g. "MyPlugin.dll") in DllImport attribute instead of using "__Internal".
     

    Attached Files:

    AVOlight likes this.
  15. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    Consume Windows Runtime Extension!!! YAY strings are there now :)

    Thank You @Tautvydas Zilys
     
    Last edited: Jan 26, 2016
  16. bakanekofr

    bakanekofr

    Joined:
    Feb 28, 2014
    Posts:
    122
    Is there a plan for a fix on the next patch release (p5) ? I prefer waiting for a proper fix before updating my game.
     
  17. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Unfortunately not. I'm hoping to get into the next weeks patch release.
     
    bakanekofr likes this.
  18. bakanekofr

    bakanekofr

    Joined:
    Feb 28, 2014
    Posts:
    122
    Was the Application.Quit bug (Windows Store, IL2CPP, D3D) fixed in the latest patch release? (5.3.2p1), I've checked the change log and didn't see it listed.

    If not, is it planned for the next patch release?
     
  19. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    I merged the fix today. It should make it to 5.3.2p2.
     
    bakanekofr likes this.
  20. bakanekofr

    bakanekofr

    Joined:
    Feb 28, 2014
    Posts:
    122
    Awesome. Thanks!
     
  21. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    is there a way to use these extern "C" methods in the editor?

    trying to write my byte operations in c++ so that there isn't so many casts back and forth from ints to bytes inside the IL2CPP generated code
     
  22. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Yes, you can compile C++ code into a DLL that targets Windows Desktop and PInvoke into it the same way by specifying the dll name in the DllImport attribute.

    There are two gotchas:

    1. The bitness of the editor DLL must match the bitness of the editor. You're most likely using 64-bit editor, so you will have to compile C++ code into 64-bit DLL.
    2. Once you PInvoke into it, the editor will load the plugin, and you will not be able to replace/modify it until you quit the editor.
     
    AVOlight likes this.
  23. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    Thats a big gotcha for a learner

    Thank You :)
     
  24. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    For anyone using this work around be aware that you must close your FileStreams before processing the quit

    I had mine in OnApplicationQuit and OnDisable and OnDestroy and they don't close there for some reason

    looking forward to this patch update :confused:
     
  25. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    should i have to close a filestream every time i write bytes?
    this seems like a bug?

    ----edit

    guess i should be flushing the stream periodically
    just its not the same behavior as in the editor, where the data was always saved
     
    Last edited: Feb 3, 2016
  26. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    Just tested this work around in the Mobile Emulator 10.0.10240.0 and it breaks after calling the custom QuitApplication

    so hopefully the upcoming fix will work with mobile
     
  27. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,731
    If you want data to be written to it's destination, you should call Flush() on a stream (closing stream also does this). Otherwise there's no guarantee the data is actually written and not kept in some memory buffer.
     
    AVOlight likes this.
  28. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    The fix is included in 5.3.2p2.
     
    bakanekofr and AVOlight like this.
  29. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    427
    forgot that there are some IL2CPP issues in 5.3.2p1 for Rewired, that were only going to be fixed by 5.3.2p3

    is there a workaround?
    will p3 be available before February 10
     
  30. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    February 10 is the estimated release date, but I wouldn't rely on it as it can easily slip if we find issues with the build.