Fix skidding ai crash

This commit is contained in:
Benau 2019-11-24 11:37:02 +08:00
parent 8c223cd2c2
commit fe028b4534
2 changed files with 19 additions and 0 deletions

View File

@ -29,6 +29,8 @@
#include <SColor.h>
#include <assert.h>
#include <algorithm>
#include <map>
#include <memory>
#include <random>
@ -174,6 +176,14 @@ public:
return dynamic_cast<Item*>(m_all_items[n]);
}
// ------------------------------------------------------------------------
bool itemExists(const ItemState* is) const
{
if (!is)
return false;
auto it = std::find(m_all_items.begin(), m_all_items.end(), is);
return it != m_all_items.end();
}
// ------------------------------------------------------------------------
/** Returns a reference to the array of all items on the specified quad.
*/
const AllItemTypes& getItemsInQuads(unsigned int n) const

View File

@ -222,6 +222,15 @@ unsigned int SkiddingAI::getNextSector(unsigned int index)
void SkiddingAI::update(int ticks)
{
float dt = stk_config->ticks2Time(ticks);
// Clear stored items if they were deleted (for example a switched nitro)
if (m_item_to_collect &&
!ItemManager::get()->itemExists(m_item_to_collect))
m_item_to_collect = NULL;
if (m_last_item_random &&
!ItemManager::get()->itemExists(m_last_item_random))
m_last_item_random = NULL;
m_controls->setRescue(false);
// This is used to enable firing an item backwards.