wheybags / freeablo

[ARCHIVED] Modern reimplementation of the Diablo 1 game engine
GNU General Public License v3.0
2.16k stars 193 forks source link

Crashes during fights #376

Closed akuskis closed 6 years ago

akuskis commented 6 years ago

Game crashes.

How to repeat: 1) start game 2) go to the second dungeon (click "page down" twice, there are more enemies) 3) try to fight with mobs (walk around them and try to hit)

Issue explanation: It crashes when target position is the same with player position. Vec2Fix is created with zeroes and getIsometricDirection is called. During normalize function call, division by "0" happens.

Dump:

raise 0x00007fbd0439de97
abort 0x00007fbd0439f801
<unknown> 0x00007fbd04fb18fb
<unknown> 0x00007fbd04fb7d3a
std::terminate() 0x00007fbd04fb7d95
__cxa_throw 0x00007fbd04fb7fe8
boost::throw_exception<boost::exception_detail::error_info_injector<std::overflow_error> > throw_exception.hpp:69
boost::exception_detail::throw_exception_<std::overflow_error> throw_exception.hpp:86
boost::multiprecision::backends::eval_divide<128u, 128u, (boost::multiprecision::cpp_integer_type)0, (boost::multiprecision::cpp_int_check_type)0, void> divide.hpp:634
boost::multiprecision::operator/<boost::multiprecision::backends::cpp_int_backend<128u, 128u, (boost::multiprecision::cpp_integer_type)0, (boost::multiprecision::cpp_int_check_type)0, void> > no_et_ops.hpp:447
FixedPoint::operator/ fixedpoint.cpp:177
Vec2Fix::normalise vec2fix.cpp:8
Vec2Fix::<lambda()>::operator()(void) const vec2fix.cpp:47
Vec2Fix::getIsometricDirection vec2fix.cpp:123
FAWorld::ActorState::BaseState::update basestate.cpp:43
FAWorld::StateMachine::update statemachine.cpp:41
FAWorld::Actor::update actor.cpp:30
FAWorld::GameLevel::update gamelevel.cpp:84
FAWorld::World::update world.cpp:328
Engine::EngineMain::runGameLoop enginemain.cpp:177
std::__invoke_impl<void, void (Engine::EngineMain::*&)(boost::program_options::variables_map const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&), Engine::EngineMain*&, boost::program_options::variables_map const*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&> invoke.h:73
std::__invoke<void (Engine::EngineMain::*&)(boost::program_options::variables_map const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&), Engine::EngineMain*&, boost::program_options::variables_map const*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&> invoke.h:95
std::_Bind<void (Engine::EngineMain::*(Engine::EngineMain*, boost::program_options::variables_map const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >))(boost::program_options::variables_map const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>::__call<void, , 0ul, 1ul, 2ul>(std::tuple<>&&, std::_Index_tuple<0ul, 1ul, 2ul>) functional:467
std::_Bind<void (Engine::EngineMain::*(Engine::EngineMain*, boost::program_options::variables_map const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >))(boost::program_options::variables_map const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>::operator()<, void>() functional:551
std::__invoke_impl<void, std::_Bind<void (Engine::EngineMain::*(Engine::EngineMain*, boost::program_options::variables_map const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >))(boost::program_options::variables_map const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>>(std::__invoke_other, std::_Bind<void (Engine::EngineMain::*(Engine::EngineMain*, boost::program_options::variables_map const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >))(boost::program_options::variables_map const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>&&) invoke.h:60
std::__invoke<std::_Bind<void (Engine::EngineMain::*(Engine::EngineMain*, boost::program_options::variables_map const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >))(boost::program_options::variables_map const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>>(std::_Bind<void (Engine::EngineMain::*(Engine::EngineMain*, boost::program_options::variables_map const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >))(boost::program_options::variables_map const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>&&) invoke.h:95
std::thread::_Invoker<std::tuple<std::_Bind<void (Engine::EngineMain::*(Engine::EngineMain*, boost::program_options::variables_map const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >))(boost::program_options::variables_map const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)> > >::_M_invoke<0ul>(std::_Index_tuple<0ul>) thread:234
std::thread::_Invoker<std::tuple<std::_Bind<void (Engine::EngineMain::*(Engine::EngineMain*, boost::program_options::variables_map const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >))(boost::program_options::variables_map const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)> > >::operator()() thread:243
std::thread::_State_impl<std::thread::_Invoker<std::tuple<std::_Bind<void (Engine::EngineMain::*(Engine::EngineMain*, boost::program_options::variables_map const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >))(boost::program_options::variables_map const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)> > > >::_M_run() thread:186
<unknown> 0x00007fbd04fe3733
start_thread 0x00007fbd047576db
clone 0x00007fbd0448088f

I think that it's better to return default direction when getIsometricDirection is called on Vec2Fix(0, 0). Another solution is to prevent overlapping, but it doesn't looks good.

wheybags commented 6 years ago

Yup, two separate bugs, fixed one and opened a separate issue for the other. Thanks for the report!