Почему моя ссылка в захвате find_if вызывает проблемы с рендерингом в окне [закрыто]C++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Гость
 Почему моя ссылка в захвате find_if вызывает проблемы с рендерингом в окне [закрыто]

Сообщение Гость »


Я использую in Visual Studio with CL to locate a specific touch/finger in a vector, and the capture is an object that contains a reference to a finger with an ID. The basic idea is that I have a list of fingers, each with an ID, and I want to find the one that matches the ID of the current finger. When I do this manually or pass in the ID, it works, but the following is causing a visual issue, so I'm thinking it's corrupting the memory/undefined behavior.

Код: Выделить всё

auto Finger::dataRef() const -> FingerData const &
{
return fingerData; // member variable, and lifetime is the lifetime of the program
}

Код: Выделить всё

auto findTap(
std::vector & taps,
controls::FingerData const & finger
) -> std::vector::iterator
{
return std::find_if(begin(taps), end(taps), [&](Tap & t) {
return t.getFingerId() == finger.fingerId;
});
}
I'm calling it like this:

Код: Выделить всё

auto tap = findTap(taps, finger.dataRef());
If I inline the code and break out the finger ID like this, it solves the issue:

Код: Выделить всё

auto & fId = x.fingerId;
auto tap = std::find_if(begin(taps), end(taps), [&](auto & t) {
return t.getFingerId() == fId;
});
auto tap = findTap(taps, finger.dataRef());
I haven't tried a different compiler. Am I misunderstanding something about the lambda here? I also tried creating a

Код: Выделить всё

reference_wrapper
to the finger and passing that in instead, but it didn't solve the issue.
I tried different ways to pass in the finger, but the only approach that solves my problem is to create a reference to the finger ID outside the lambda and then use that directly.
This first video is from MSVC, which is causing rapid flickering that the recorder couldn't capture very well. You can see it when options and exit are alternating even though only one of those is actually selected. I'm ignoring the result of . I control the menu selection using the keyboard exclusively (I disabled touch selection).
Изображение
This second video is also from MSVC but only when I pass in the references directly rather than through the finger reference.
Изображение



Источник: https://stackoverflow.com/questions/781 ... ith-window
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C++»