Debugger wykryl coś

0

witam uzylem debugger
i coś takiego wykrył

Item::getSpecialDescription (this=0x1b) at item.cpp:721 721 if(!specialDescription)

std::string Item::getSpecialDescription()
{
    if(!specialDescription)
        return std::string("");
    return *specialDescription;
} 

za bardzo nie wiem o co chodzi więc prosiłbym o wyjaśnienie

1

Próbujesz wywołać metodę nieistniejącego obiektu.

0
_13th_Dragon napisał(a):

Próbujesz wywołać metodę nieistniejącego obiektu.

dobra dzięki jak mógłbym ten obiekt jakoś dodać czy coś?

0
         specialDescription = nullptr;

wystyarczy ze zmienie specialDescription = 0x1b
?

1

Bez kodu na to pytanie tylko wróżbici ci odpowiedzą, ten forum "niestety" dotyczy konkretów.

0
_13th_Dragon napisał(a):

Bez kodu na to pytanie tylko wróżbici ci odpowiedzą, ten forum "niestety" dotyczy konkretów.

rozumiem ze cały kod który zawiera specialDescription mam tutaj umieścić?

2

Raczej miejsce gdzie tworzysz obiekt Item, na rzecz którego wywołujesz metodę getSpecialDescription() - a że podejrzewam że nic to tobie nie mówi, to cały.

0
_13th_Dragon napisał(a):

Raczej miejsce gdzie tworzysz obiekt Item, na rzecz którego wywołujesz metodę getSpecialDescription() - a że podejrzewam że nic to tobie nie mówi, to cały.

poradziłem sobie zmieniłemm SpecialDescription = nullptr; na SpecialDescription = 0;

teraż mam kolejny problem z

GameState::onAttack (this=0xb16f2b64, attacker=0x8282230, pos=..., me=0xb16f2d04)
    at game.cpp:198
198                     targetPlayer = targetCreature->getPlayer();
 

linijka
190:

	Player* attackPlayer = dynamic_cast<Player*>(attacker); 

192:

 	Creature *targetCreature = nullptr; 

194:

	Player *targetPlayer = nullptr; 

198:

 		targetPlayer = targetCreature->getPlayer();
0

znowu używasz nieprawidłowego wskaźnika (nie wskazuje na prawidłowy obiekt).
Pokaż kod tej metody.

0
MarekR22 napisał(a):

znowu używasz nieprawidłowego wskaźnika (nie wskazuje na prawidłowy obiekt).
Pokaż kod tej metody.

void GameState::onAttack(Creature* attacker, const Position& pos, const MagicEffectClass* me)
{
Tile *tile = game->map->getTile(pos);
if(!tile)
return;

CreatureVector::iterator cit;
Player* attackPlayer = dynamic_cast<Player*>(attacker);
Monster* attackMonster = dynamic_cast<Monster*>(attacker);

Creature *targetCreature = nullptr;
Monster *targetMonster = nullptr;
Player *targetPlayer = nullptr;
for(cit = tile->creatures.begin(); cit != tile->creatures.end(); ++cit)
{
targetCreature = (cit);
targetPlayer = targetCreature->getPlayer();
targetMonster = dynamic_cast<Monster
>(targetCreature);
bool pvpArena = false;

if(targetCreature && targetCreature->getName() != "Test" && attackPlayer && (attackPlayer->cos!= 0))
   {
	    attackPlayer->cos = 0;
   }
0

Czy przypadkiem w tej pętli nie usuwasz pokonanego monstra z kontenera tile->creatures?

0
_13th_Dragon napisał(a):

Czy przypadkiem w tej pętli nie usuwasz pokonanego monstra z kontenera tile->creatures?

tak

1

No to usunięcie psuje iterator.
Niektóre metody usunięcia zwracają następny iterator.

1

Zgadzam się z @_13th_Dragon, niektóre kontenery mają taką słabość (np. vector).
Jakiego kontenera używasz?

Poza tym, nie podoba mi się ten dynamic_cast coś popsułeś z API, bo to powinno zostać załatwione za pomocą jakieś abstrakcji (interfejs).

0
MarekR22 napisał(a):

Zgadzam się z @_13th_Dragon, niektóre kontenery mają taką słabość (np. vector).
Jakiego kontenera używasz?

Poza tym, nie podoba mi się ten dynamic_cast coś popsułeś z API, bo to powinno zostać załatwione za pomocą jakieś abstrakcji (interfejs).

#include <vector.h>

0

http://ideone.com/klYLIg

#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
  {
   vector<int> tb({1,2,3,4,5,6,7,8,9});
   ostream_iterator<int> iout(cout,", ");
   copy(begin(tb),end(tb),iout);
   vector<int>::iterator i=begin(tb);
   while(i!=end(tb))
     {
      if(*i&2) i=tb.erase(i);
      else ++i;
     }
   cout<<endl;
   copy(begin(tb),end(tb),iout);
   return 0;
  }
0
_13th_Dragon napisał(a):

http://ideone.com/klYLIg

#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
  {
   vector<int> tb({1,2,3,4,5,6,7,8,9});
   ostream_iterator<int> iout(cout,", ");
   copy(begin(tb),end(tb),iout);
   vector<int>::iterator i=begin(tb);
   while(i!=end(tb))
     {
      if(*i&2) i=tb.erase(i);
      else ++i;
     }
   cout<<endl;
   copy(begin(tb),end(tb),iout);
   return 0;
  }

wlaśnie zle napisałem mam #include <vector>

tzn gdzie ten kod mam dodać może jest coś lepszego niż uzywanie vectora?

0

kolejny problem ale teraż nie pokazało w której lini

 Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xad4ffb70 (LWP 7365)]
0x0d384c00 in ?? ()
(gdb) where
#0  0x0d384c00 in ?? ()
#1  0x0d347398 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
0

Masz na to jakiś system kontroli wersji? Może konto na github?
jak nie zrób zip-a dodaj do wątku może ktoś popatrz na całość.

0

znowu debugger sypie ;]

#0  0x080977f9 in GameState::onAttack (this=0xaaff2b64, attacker=0xed3fb50,
    pos=..., me=0xaaff2d04) at game.cpp:200
#1  0x08098e04 in Game::creatureMakeMagic (this=0x816c540, creature=0xed3fb50,
    centerpos=..., me=0xaaff2d04) at game.cpp:3951
#2  0x0809c69a in Game::creatureCastSpell (this=0x816c540, creature=0xed3fb50,
    centerpos=..., me=...) at game.cpp:4147
#3  0x0810767f in SpellScript::luaActionDoAreaSpell (L=0x8294d70)
    at spells.cpp:554
#4  0x0811a8c4 in luaD_precall ()
#5  0x08122eaa in luaV_execute ()
#6  0x0811ae20 in luaD_call ()
#7  0x08117e30 in f_call ()
#8  0x0811a384 in luaD_rawrunprotected ()
#9  0x0811b063 in luaD_pcall ()
#10 0x08118e4f in lua_pcall ()
#11 0x08104708 in SpellScript::castSpell (this=0x8294988, creature=0xed3fb50,
    pos=..., var=...) at spells.cpp:283
#12 0x08083b45 in Game::creatureSaySpell (this=0x816c540, creature=0xed3fb50,
    text=...) at game.cpp:5215
#13 0x080f5170 in Protocol76::parseSay (this=0xf9a9e48, msg=...)
    at protocol76.cpp:1567
#14 0x081008d3 in Protocol76::parsePacket (this=this@entry=0xf9a9e48, msg=...) 

1 użytkowników online, w tym zalogowanych: 0, gości: 1