Fix new crashes pertaining to unchecked 0 distance in line normalizing functions.

master
sigonasr2 2 months ago
parent 0e3a4c0ba7
commit 85ba978793
  1. 2
      Adventures in Lestoria/ItemDrop.cpp
  2. 6
      Adventures in Lestoria/Monster.cpp
  3. 6
      Adventures in Lestoria/Player.cpp
  4. 2
      Adventures in Lestoria/Version.h
  5. 16
      Adventures in Lestoria/olcPGEX_MiniAudio.h
  6. 2
      Adventures in Lestoria/olcUTIL_Geometry2D.h
  7. BIN
      x64/Release/Adventures in Lestoria.exe

@ -110,7 +110,7 @@ void ItemDrop::UpdateDrops(float fElapsedTime){
if(drop.zSpeed==0&&drop.OnUpperLevel()==game->GetPlayer()->OnUpperLevel()){
geom2d::line<float>lineTo=geom2d::line<float>(drop.pos,game->GetPlayer()->GetPos());
float dist=lineTo.length();
if(dist<="ItemDrop.Item Drop Suction Range"_F){
if(dist<="ItemDrop.Item Drop Suction Range"_F&&dist>0){
vf2d pointVel=lineTo.vector().norm();
float moveDistance=(1.f/std::min(48.f,dist))*"ItemDrop.Item Drop Suction Strength"_F*fElapsedTime;
if(moveDistance>dist){

@ -208,7 +208,8 @@ bool Monster::_SetX(float x,const bool monsterInvoked){
return true;
}else
if(monsterInvoked){ //If player invoked, we'll try the smart move system.
vf2d pushDir=geom2d::line<float>(collision.middle(),pos).vector().norm();
vf2d pushDir{vf2d{1.f,util::random(2*PI)}.cart()};
if(collision.middle()!=pos)pushDir=geom2d::line<float>(collision.middle(),pos).vector().norm();
newPos={newPos.x,pos.y+pushDir.y*12};
if(NoEnemyCollisionWithTile()){
return _SetY(pos.y+pushDir.y*game->GetElapsedTime()*12,false);
@ -247,7 +248,8 @@ bool Monster::_SetY(float y,const bool monsterInvoked){
return true;
}else
if(monsterInvoked){ //If player invoked, we'll try the smart move system.{
vf2d pushDir=geom2d::line<float>(collision.middle(),pos).vector().norm();
vf2d pushDir{vf2d{1.f,util::random(2*PI)}.cart()};
if(collision.middle()!=pos)pushDir=geom2d::line<float>(collision.middle(),pos).vector().norm();
newPos={pos.x+pushDir.x*12,newPos.y};
if(NoEnemyCollisionWithTile()){
return _SetX(pos.x+pushDir.x*game->GetElapsedTime()*12,false);

@ -199,7 +199,8 @@ bool Player::_SetX(float x,MoveFlag::MoveFlag flags,const bool playerInvoked){
return true;
}else
if(playerInvoked){ //If player invoked, we'll try the smart move system.
vf2d pushDir=geom2d::line<float>(collision.middle(),pos).vector().norm();
vf2d pushDir=vf2d{1.f,util::random(2*PI)}.cart();
if(collision.middle()!=pos)pushDir=geom2d::line<float>(collision.middle(),pos).vector().norm();
newPos={newPos.x,pos.y+pushDir.y*12};
if(NoPlayerCollisionWithTile()){
return _SetY(pos.y+pushDir.y*game->GetElapsedTime()*12,flags,false);
@ -232,7 +233,8 @@ bool Player::_SetY(float y,MoveFlag::MoveFlag flags,const bool playerInvoked){
return true;
}else
if(playerInvoked){ //If player invoked, we'll try the smart move system.{
vf2d pushDir=geom2d::line<float>(collision.middle(),pos).vector().norm();
vf2d pushDir=vf2d{1.f,util::random(2*PI)}.cart();
if(collision.middle()!=pos)geom2d::line<float>(collision.middle(),pos).vector().norm();
newPos={pos.x+pushDir.x*12,newPos.y};
if(NoPlayerCollisionWithTile()){
return _SetX(pos.x+pushDir.x*game->GetElapsedTime()*12,flags,false);

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 1
#define VERSION_MINOR 3
#define VERSION_PATCH 0
#define VERSION_BUILD 11621
#define VERSION_BUILD 11633
#define stringify(a) stringify_(a)
#define stringify_(a) #a

@ -262,14 +262,28 @@ namespace olc
{
if(sound != nullptr)
{
ma_sound_stop(sound);
ma_sound_uninit(sound);
delete sound;
}
}
for(auto sound : vecOneOffSounds)
{
if(sound != nullptr)
{
ma_sound_stop(sound);
ma_sound_uninit(sound);
delete sound;
}
}
ma_engine_stop(&engine);
ma_engine_uninit(&engine);
ma_resource_manager_uninit(&resourceManager);
ma_engine_uninit(&engine);
ma_device_stop(&device);
ma_device_uninit(&device);
}
bool MiniAudio::OnBeforeUserUpdate(float& fElapsedTime)

@ -594,7 +594,7 @@ namespace olc::utils::geom2d
// Given a real distance, get point along line
inline constexpr olc::v_2d<T> rpoint(const T& distance) const
{
if(abs(distance)<0.01f){
if(start==end){
return start;
}else{
return start + vector().norm() * distance;

Loading…
Cancel
Save