Search

Array<> deallocated too early by WinampBar

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 752136
Opened: 7/3/2012 5:24:13 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
In a WinRT component project, I have an async operation which takes an array as an argument. Although captured, the array seems to have been deallocated when the worker lambda gets to touch it.

static IAsyncOperation<int>^ SumNumbers(const Array<int>^ numbers)
{
    return create_async([numbers] ()->int {
        int sum = 0;
        for(unsigned int i=0; i<numbers->Length; ++i)
            sum += numbers[i];
        return sum;
    });
}

This causes an access violation when 'numbers' is referenced within the lambda, and debugging printout does show that the variable is indeed garbage.

Changing it to create a copy of the input array, as in:

static IAsyncOperation<int>^ SumNumbers(const Array<int>^ numbers)
{
    auto numbers2 = ref new Array<int>(numbers);
    return create_async([numbers2] ()->int {
        int sum = 0;
        for(unsigned int i=0; i<numbers2->Length; ++i)
            sum += numbers2[i];
        return sum;
    });
}

does work, but with an extra copy of course.

Should capturing 'numbers' in the lambda environment increment the reference count to keep the variable alive for the lambda to process?
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling Version

Visual Studio 2012 RC

Steps to reproduce

Create WinRT component project, including the example code above as an asynchronous method; create a simple WINRT app wrapper to invoke it, and wait for access violation!

Demo project now attached: a managed "host" app TestApp uses the WinRT component project, LambdaCapture, which is the wizard-created component project with the addition of the Class1::SumNumbersAsync method. This method calls either SumNumbersWhichWorks or SumNumbersWhichCrashes, which differ only as outlined in the description.

Product Language

English

Operating System

Windows 8

Operating System Language

English

Actual results

Access violation on dereferencing the captured WinRT array variable within the "background" lambda

Expected results

No AV
File Attachments
File Name Submitted By Submitted On File Size  
LambdaCapture.zip 7/4/2012 20 KB
Sign in to post a comment.
Posted by Microsoft on 7/6/2012 at 10:41 AM
Hi,
    Thanks for reporting the issue.
    A fix for this issue has been checked into the compiler sources. The fix should show up in the RTM version of Visual Studio 2012.

Xiang Fan
Visual C++ Team
    
Posted by Microsoft on 7/5/2012 at 12:57 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Microsoft Visual Studio Connect Support Team for triage and resolution. These specialized experts will follow-up with your issue.

Thank you

Microsoft Visual Studio Connect Support Team
Posted by Microsoft on 7/4/2012 at 1:26 AM
Thanks for your feedback. In order to efficiently investigate and reproduce this issue, we are requesting additional information outlined below.

Could you please give us a demo project so that we can conduct further research?

Please submit this information to us within 3 business days. We look forward to hearing from you with this information.

Microsoft Visual Studio Connect Support Team
Posted by Microsoft on 7/3/2012 at 5:48 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.