MantisBT - VCMI
View Issue Details
0003038VCMIAI - Adventure Mappublic2019-02-15 10:052019-02-16 09:15
mpech 
Nullkiller 
normalminoralways
assignedopen 
Ubuntu 16.04.5 LTS
 
 
0003038: core in FuzzyHelper::evaluateDanger
hi guys,

from commit (5f87c98) no problem
from commit (6165954): core

modules are death valley, preserve and retreat


#0 FuzzyHelper::evaluateDanger ([email protected]=0x7f58a12e0c50, [email protected]=0x7f58b2d9c8b0) at /home/mpech2/dl/vcmi/AI/VCAI/FuzzyHelper.cpp:288
288 cb->getTownInfo(obj, iat);
[Current thread is 1 (Thread 0x7f58bcdc0700 (LWP 12907))]
(gdb) bt
#0 FuzzyHelper::evaluateDanger ([email protected]=0x7f58a12e0c50, [email protected]=0x7f58b2d9c8b0) at /home/mpech2/dl/vcmi/AI/VCAI/FuzzyHelper.cpp:288
#1 0x00007f58cce4efc6 in FuzzyHelper::evaluateDanger (this=0x7f58a12e0c50, tile=..., visitor=0x7f58b1f13ea0, cb=0x7f58a14514a0)
    at /home/mpech2/dl/vcmi/AI/VCAI/FuzzyHelper.cpp:234
0000002 0x00007f58cce30739 in AINodeStorage::evaluateDanger (tile=..., this=<optimized out>)
    at /home/mpech2/dl/vcmi/AI/VCAI/Pathfinding/Rules/../AINodeStorage.h:118
0000003 AIPathfinding::AIMovementAfterDestinationRule::process (this=<optimized out>, source=..., destination=..., pathfinderConfig=<optimized out>,
    pathfinderHelper=<optimized out>) at /home/mpech2/dl/vcmi/AI/VCAI/Pathfinding/Rules/AIMovementAfterDestinationRule.cpp:124
0000004 0x00007f58f691ed8b in CPathfinder::calculatePaths ([email protected]=0x7f58bcdbf8c0) at /home/mpech2/dl/vcmi/lib/CPathfinder.cpp:364
0000005 0x00007f58f68c88d2 in CGameState::calculatePaths (this=<optimized out>, config=..., hero=<optimized out>)
    at /home/mpech2/dl/vcmi/lib/CGameState.cpp:1980
load game,
end turn
crashes during ai turn

Not sure about fuzzyHelper::
extern boost::thread_specific_ptr<CCallback> cb;
(could not find where cb variable would be written)

however at some point this variable is accessed instead of the one provided as argument (from AINodeStorage)
not sure sure if diff below is acceptable but somehow it solves the core for me (removed AIUtility::compareDanger since not used along the way)

From 4fb2a68069de26edc18b54ea71a2ea3b4ab325ff Mon Sep 17 00:00:00 2001
From: mpech <xx>
Date: Fri, 15 Feb 2019 10:47:30 +0100
Subject: [PATCH] fix core

---
 AI/VCAI/AIUtility.cpp | 6 ------
 AI/VCAI/FuzzyHelper.cpp | 8 ++++----
 AI/VCAI/FuzzyHelper.h | 2 +-
 3 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/AI/VCAI/AIUtility.cpp b/AI/VCAI/AIUtility.cpp
index 7881893..efe6949 100644
--- a/AI/VCAI/AIUtility.cpp
+++ b/AI/VCAI/AIUtility.cpp
@@ -194,12 +194,6 @@ bool CDistanceSorter::operator()(const CGObjectInstance * lhs, const CGObjectIns
    return ln->cost < rn->cost;
 }
 
-
-bool compareDanger(const CGObjectInstance * lhs, const CGObjectInstance * rhs)
-{
- return fh->evaluateDanger(lhs) < fh->evaluateDanger(rhs);
-}
-
 bool isSafeToVisit(HeroPtr h, crint3 tile)
 {
    return isSafeToVisit(h, fh->evaluateDanger(tile, h.get()));
diff --git a/AI/VCAI/FuzzyHelper.cpp b/AI/VCAI/FuzzyHelper.cpp
index 288b435..0f5ef54 100644
--- a/AI/VCAI/FuzzyHelper.cpp
+++ b/AI/VCAI/FuzzyHelper.cpp
@@ -231,7 +231,7 @@ ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor, co
 
    if(const CGObjectInstance * dangerousObject = vstd::backOrNull(visitableObjects))
    {
- objectDanger = evaluateDanger(dangerousObject); //unguarded objects can also be dangerous or unhandled
+ objectDanger = evaluateDanger(dangerousObject, cb); //unguarded objects can also be dangerous or unhandled
        if(objectDanger)
        {
            //TODO: don't downcast objects AI shouldn't know about!
@@ -251,7 +251,7 @@ ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor, co
                auto guards = cb->getGuardingCreatures(it->second->visitablePos());
                for(auto cre : guards)
                {
- vstd::amax(guardDanger, evaluateDanger(cre) * tacticalAdvantageEngine.getTacticalAdvantage(visitor, dynamic_cast<const CArmedInstance *>(cre)));
+ vstd::amax(guardDanger, evaluateDanger(cre, cb) * tacticalAdvantageEngine.getTacticalAdvantage(visitor, dynamic_cast<const CArmedInstance *>(cre)));
                }
            }
        }
@@ -260,14 +260,14 @@ ui64 FuzzyHelper::evaluateDanger(crint3 tile, const CGHeroInstance * visitor, co
    auto guards = cb->getGuardingCreatures(tile);
    for(auto cre : guards)
    {
- vstd::amax(guardDanger, evaluateDanger(cre) * tacticalAdvantageEngine.getTacticalAdvantage(visitor, dynamic_cast<const CArmedInstance *>(cre))); //we are interested in strongest monster around
+ vstd::amax(guardDanger, evaluateDanger(cre, cb) * tacticalAdvantageEngine.getTacticalAdvantage(visitor, dynamic_cast<const CArmedInstance *>(cre))); //we are interested in strongest monster around
    }
 
    //TODO mozna odwiedzic blockvis nie ruszajac straznika
    return std::max(objectDanger, guardDanger);
 }
 
-ui64 FuzzyHelper::evaluateDanger(const CGObjectInstance * obj)
+ui64 FuzzyHelper::evaluateDanger(const CGObjectInstance * obj, const CPlayerSpecificInfoCallback * cb)
 {
    if(obj->tempOwner < PlayerColor::PLAYER_LIMIT && cb->getPlayerRelations(obj->tempOwner, ai->playerID) != PlayerRelations::ENEMIES) //owned or allied objects don't pose any threat
        return 0;
diff --git a/AI/VCAI/FuzzyHelper.h b/AI/VCAI/FuzzyHelper.h
index 679c4f6..8826817 100644
--- a/AI/VCAI/FuzzyHelper.h
+++ b/AI/VCAI/FuzzyHelper.h
@@ -43,7 +43,7 @@ public:
    Goals::TSubgoal chooseSolution(Goals::TGoalVec vec);
    //std::shared_ptr<AbstractGoal> chooseSolution (std::vector<std::shared_ptr<AbstractGoal>> & vec);
 
- ui64 evaluateDanger(const CGObjectInstance * obj);
+ ui64 evaluateDanger(const CGObjectInstance * obj, const CPlayerSpecificInfoCallback * _cb);
    ui64 evaluateDanger(crint3 tile, const CGHeroInstance * visitor, const CPlayerSpecificInfoCallback * cb);
    ui64 evaluateDanger(crint3 tile, const CGHeroInstance * visitor);
 };
--
2.7.4
No tags attached.
zip sun2.zip (2,014,265) 2019-02-15 10:05
https://bugs.vcmi.eu/file_download.php?file_id=2986&type=bug
Issue History
2019-02-15 10:05mpechNew Issue
2019-02-15 10:05mpechFile Added: sun2.zip
2019-02-15 11:12AVSAssigned To => Nullkiller
2019-02-15 11:12AVSStatusnew => assigned
2019-02-16 09:14NullkillerNote Added: 0007750
2019-02-16 09:15NullkillerNote Edited: 0007750bug_revision_view_page.php?bugnote_id=7750#r3563

Notes
(0007750)
Nullkiller   
2019-02-16 09:14   
(edited on: 2019-02-16 09:15)
Will be fixed in https://github.com/vcmi/vcmi/pull/552 [^]