C++ Unordered_map.find crash

Эксперт
Статус
Оффлайн
Регистрация
13 Сен 2020
Сообщения
1,415
Реакции[?]
713
Поинты[?]
10K
the real issue here is the dll randomly crashing at runtime without exceptions / error messages...

I was trying to see what was causing the problem, and basically found out this function is not working properly.

The second line of code seems to be what's causing the crash...
FastFloatLerp:
float FastFloatLerp(std::string identifier, bool state, float min, float max, float speed)

{

  static std::unordered_map<std::string, float> valuesMapFloat;


  auto value = valuesMapFloat.find(identifier); // -> CRASH HERE


  const float frameRateSpeed = speed * (1.f - ImGui::GetIO().DeltaTime);


  if (state) {

    if (value->second < max)

      value->second += frameRateSpeed;

  }

  else {

    if (value->second > min)

      value->second -= frameRateSpeed;

  }


  value->second = std::clamp(value->second, min, max);


  return value->second;

}
This is how i am calling the function...
calling of function:
float anim = ImTricks::Animations::FastFloatLerp("theme_anim" , light, 0.f, 1.f, GetIO().DeltaTime * 3);
```

You can find the ImTricks code here:
Пожалуйста, авторизуйтесь для просмотра ссылки.


This problem only verifies in my dll project...

I made another project that uses the same function called in the same way at the same time but everything works good...

So maybe some project setting / properties needs to be edited...
 
unbound
Пользователь
Статус
Оффлайн
Регистрация
27 Окт 2019
Сообщения
271
Реакции[?]
90
Поинты[?]
60K
the real issue here is the dll randomly crashing at runtime without exceptions / error messages...

I was trying to see what was causing the problem, and basically found out this function is not working properly.

The second line of code seems to be what's causing the crash...
FastFloatLerp:
float FastFloatLerp(std::string identifier, bool state, float min, float max, float speed)

{

  static std::unordered_map<std::string, float> valuesMapFloat;


  auto value = valuesMapFloat.find(identifier); // -> CRASH HERE


  const float frameRateSpeed = speed * (1.f - ImGui::GetIO().DeltaTime);


  if (state) {

    if (value->second < max)

      value->second += frameRateSpeed;

  }

  else {

    if (value->second > min)

      value->second -= frameRateSpeed;

  }


  value->second = std::clamp(value->second, min, max);


  return value->second;

}
This is how i am calling the function...
calling of function:
float anim = ImTricks::Animations::FastFloatLerp("theme_anim" , light, 0.f, 1.f, GetIO().DeltaTime * 3);
```

You can find the ImTricks code here:
Пожалуйста, авторизуйтесь для просмотра ссылки.


This problem only verifies in my dll project...

I made another project that uses the same function called in the same way at the same time but everything works good...

So maybe some project setting / properties needs to be edited...
float lerpFloat = ImTricks::Animations::FastFloatLerp(label, *v, 0.f, 1.f, 0.05f);
(*v - bool)
 
Сверху Снизу