First Chance Exception in ppltasks' _ContextCallback class


  • I've got an first chance exception in ppltasks.h's _ContextCallback that I just don't understand. 

    My project is a mixed WinRT/native application. The application is made up of multiple sub-projects, one of them uses WinRT. The WinRT code is in a static library running in a different thread from the main thread (and it's not in my power to change that). The WinRT code is copied from a generated Direct3D metro app in Visual Studio 2012 RC.

    The code attempts to load one of the simple shaders:

        void CubeRenderer::CreateDeviceResources()
            // going to crash while attempting to load a file.
            auto loadVSTask = DX::ReadDataAsync("SimpleVertexShader.cso");

    The file exists, at the correct location, and proven to work.  

    The code crashes here in ppltasks.h. _M_context._M_pContextCallback is invalid.

    void _Reset()
        if (_M_context._M_captureMethod != _S_captureDeferred && _M_context._M_pContextCallback != nullptr)    

    Output window gives:
        First-chance exception at 0x00E34C89 in MyApplication.exe: 0xC0000005: Access violation reading location 0xCDCDCDCD.

    Stack trace looks like:

    > MyApplication.exe!Concurrency::details::_ContextCallback::_Reset() Line 620 C++
      MyApplication.exe!Concurrency::details::_ContextCallback::operator=(const Concurrency::details::_ContextCallback & _Src) Line 563 C++
      MyApplication.exe!Concurrency::task_continuation_context::operator=(const Concurrency::task_continuation_context & __that) C++
      MyApplication.exe!Concurrency::task<Windows::Storage::StorageFile ^>::_ContinuationTaskHandle<Windows::Storage::StorageFile ^,Windows::Storage::Streams::IBuffer ^,<lambda_676bb22cd4d2217f0e2fa0c70ebd32bb>,std::integral_constant<bool,0>,Concurrency::details::_TypeSelectorAsyncOperation>::_ContinuationTaskHandle<Windows::Storage::StorageFile ^,Windows::Storage::Streams::IBuffer ^,<lambda_676bb22cd4d2217f0e2fa0c70ebd32bb>,std::integral_constant<bool,0>,Concurrency::details::_TypeSelectorAsyncOperation>(const std::shared_ptr<Concurrency::details::_Task_impl<Windows::Storage::StorageFile ^> > & _AncestorImpl, const std::shared_ptr<Concurrency::details::_Task_impl<Windows::Storage::Streams::IBuffer ^> > & _ContinuationImpl, const DX::ReadDataAsync::__l3::<lambda_676bb22cd4d2217f0e2fa0c70ebd32bb> & _Func, const Concurrency::task_continuation_context & _Context, Concurrency::details::_TaskInliningMode _InliningMode) Line 3292 C++
      MyApplication.exe!Concurrency::task<Windows::Storage::StorageFile ^>::_ThenImpl<Windows::Storage::StorageFile ^,<lambda_676bb22cd4d2217f0e2fa0c70ebd32bb> >(const DX::ReadDataAsync::__l3::<lambda_676bb22cd4d2217f0e2fa0c70ebd32bb> & _Func, Concurrency::details::_CancellationTokenState * _PTokenState, const Concurrency::task_continuation_context & _ContinuationContext, bool _Aggregating, Concurrency::details::_TaskInliningMode _InliningMode) Line 3584 C++
      MyApplication.exe!Concurrency::task<Windows::Storage::StorageFile ^>::then<<lambda_676bb22cd4d2217f0e2fa0c70ebd32bb> >(const DX::ReadDataAsync::__l3::<lambda_676bb22cd4d2217f0e2fa0c70ebd32bb> & _Func) Line 2882 C++
      MyApplication.exe!DX::ReadDataAsync(Platform::String ^ filename) Line 42 C++
      MyApplication.exe!CubeRenderer::[Direct3DBase]::CreateDeviceResources() Line 30 C++

    So there's something wrong with the _ContextCallback, and that's where I get stuck. 

    - What is this context callback? It seems to have something to do with passing from a task to another. 
    - If it's invalid, how could that have happened? 
    - If it's simply just not setup properly, how to I properly set it up?

    I can get it to work, but it involves changing all the sub-projects in the application to use WinRT. Unfortunately this is not considered an acceptable solution as the code in those other sub-projects are also outside of my control. I also would like to try to understand what's actually going on here.

    Any insights or ideas? Thanks!
    Wednesday, July 04, 2012 3:33 PM

All replies

  • Hello,


    Thanks for your feedback, I will involve more experts to investigate it.


    Best regards,


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Friday, July 06, 2012 8:06 AM