Advertisement
Guest User

Untitled

a guest
Jan 10th, 2025
51
0
21 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.89 KB | None | 0 0
  1. <=====><=====><=====><=====><=====><=====>
  2. <=====><=====>Błąd 1<=====><=====><=====>
  3. <=====><=====><=====><=====><=====><=====>
  4. ==1749== Invalid read of size 4
  5. ==1749==    at 0x187D20: Game::creatureBroadcastTileUpdated(Position const&) (game.cpp:9545)
  6.  
  7. void Game::creatureBroadcastTileUpdated(const Position& pos)
  8. {
  9.     OTSYS_THREAD_LOCK_CLASS lockClass(gameLock, "Game::creatureBroadcastTileUpdated()");
  10.     SpectatorVec list;
  11.     SpectatorVec::iterator it;
  12.     //getSpectators(Range(pos, true), list);
  13.     getSpectators(Range(pos, true), list, false, false); // linia 9545
  14.  
  15.     //players
  16.     for(it = list.begin(); it != list.end(); ++it)
  17.     {
  18.         if(dynamic_cast<Player*>(*it))
  19.         {
  20.             (*it)->onTileUpdated(pos);
  21.         }
  22.     }
  23.  
  24.     //none-players
  25.     for(it = list.begin(); it != list.end(); ++it)
  26.     {
  27.         if(!dynamic_cast<Player*>(*it))
  28.         {
  29.             (*it)->onTileUpdated(pos);
  30.         }
  31.     }
  32. }
  33.  
  34. <=====><=====><=====><=====><=====><=====>
  35. <=====><=====>Błąd 2<=====><=====><=====>
  36. <=====><=====><=====><=====><=====><=====
  37. ==1749== Invalid read of size 4
  38. ==1749==    at 0x26A4FA: Protocol76::AddTileUpdated(NetworkMessage&, Position const&) (protocol76.cpp:2121)
  39. void Protocol76::AddTileUpdated(NetworkMessage &msg, const Position &pos)
  40. {
  41. #ifdef __DEBUG__
  42.     std::cout << "Pop-up item from below..." << std::endl;
  43. #endif
  44.  
  45.     if (CanSee(pos.x, pos.y, pos.z)) // linia 2121
  46.     {
  47.         msg.AddByte(0x69);
  48.         msg.AddPosition(pos);
  49.  
  50.         Tile* tile = game->getTile(pos.x, pos.y, pos.z);
  51.         if(tile)
  52.         {
  53. #ifdef TRS_GM_INVISIBLE
  54.             GetTileDescription(tile, msg, player);
  55. #else
  56.             GetTileDescription(tile, msg);
  57. #endif //TRS_GM_INVISIBLE
  58.             msg.AddByte(0);
  59.             msg.AddByte(0xFF);
  60.         }
  61.         else {
  62.             msg.AddByte(0x01);
  63.             msg.AddByte(0xFF);
  64.         }
  65.     }
  66. }
  67. ==1749==    by 0x26A619: Protocol76::sendTileUpdated(Position const&) (protocol76.cpp:2147)
  68. void Protocol76::sendTileUpdated(const Position &pos)
  69. {
  70.     NetworkMessage msg;
  71.  
  72.     AddTileUpdated(msg, pos); // linia 2147
  73.     WriteBuffer(msg);
  74. }
  75.  
  76. ==1749==    by 0x24E3DD: Player::onTileUpdated(Position const&) (player.cpp:2397)
  77. void Player::onTileUpdated(const Position &pos)
  78. {
  79.   client->sendTileUpdated(pos); // linia 2397
  80. }
  81.  
  82. ==1749==    by 0x187E24: Game::creatureBroadcastTileUpdated(Position const&) (game.cpp:9552)
  83. void Game::creatureBroadcastTileUpdated(const Position& pos)
  84. {
  85.     OTSYS_THREAD_LOCK_CLASS lockClass(gameLock, "Game::creatureBroadcastTileUpdated()");
  86.     SpectatorVec list;
  87.     SpectatorVec::iterator it;
  88.     //getSpectators(Range(pos, true), list);
  89.     getSpectators(Range(pos, true), list, false, false);
  90.  
  91.     //players
  92.     for(it = list.begin(); it != list.end(); ++it)
  93.     {
  94.         if(dynamic_cast<Player*>(*it))
  95.         {
  96.             (*it)->onTileUpdated(pos); // linia 9552
  97.         }
  98.     }
  99.  
  100.     //none-players
  101.     for(it = list.begin(); it != list.end(); ++it)
  102.     {
  103.         if(!dynamic_cast<Player*>(*it))
  104.         {
  105.             (*it)->onTileUpdated(pos);
  106.         }
  107.     }
  108. }
  109.  
  110. ==1749==    by 0x293829: Tile::clean() (tile.cpp:702)
  111. int32_t Tile::clean()
  112. {
  113.     if (house)
  114.         return 0L;
  115.  
  116.     std::list<Item*> trash;
  117.  
  118.     for (int32_t i = 0; i < getThingCount(); i++)
  119.     {
  120.         Item* item = dynamic_cast<Item*>(getThingByStackPos(i));
  121.  
  122. #ifdef SCORPION_CLEAN
  123.         if (item && item->isPickupable() && !item->decoration && item->isCleanable())
  124.             trash.push_back(item);
  125. #else
  126.         if (item && item->isPickupable() && !item->decoration)
  127.             trash.push_back(item);
  128. #endif //SCORPION_CLEAN
  129.     }
  130.  
  131.     for (std::list<Item*>::iterator iter = trash.begin(); iter != trash.end(); ++iter)
  132.     {
  133.         Item* item = *iter;
  134.         Container* container = dynamic_cast<Container*>(item);
  135.  
  136.         if (container)      // check if anyone has this container opened and close it
  137.         {
  138.             AutoList<Player>::listiterator piter = Player::listPlayer.list.begin();
  139.             while (piter != Player::listPlayer.list.end())      // iterate players
  140.             {
  141.                 Player* player = piter->second;
  142.                 containerLayout::const_iterator citer = player->getContainers();
  143.  
  144.                 while (citer != player->getEndContainer())  // iterate containers opened by player
  145.                 {
  146.                     // close container if it is child of the one on the groud
  147.                     if (citer->second->getTopParent() == container)
  148.                         citer = player->closeContainer(citer->first);
  149.                     else
  150.                         ++citer;
  151.                 }
  152.                 ++piter;
  153.             }
  154.         }
  155.  
  156.         if (removeThing(item))
  157.             item->releaseThing();
  158.             g_game.creatureBroadcastTileUpdated(item->pos); //on clean update tiles // linia 702
  159.         }
  160.  
  161.     return (int32_t)trash.size();
  162. }
  163.  
  164.  
  165.  
  166.  
  167. <=====><=====><=====><=====><=====><=====>
  168. <=====><=====>Błąd 3<=====><=====><=====>
  169. <=====><=====><=====><=====><=====><=====
  170. ==1749== Invalid read of size 4
  171. ==1749==    at 0x2315E9: NetworkMessage::AddPosition(Position const&) (networkmessage.cpp:200)
  172. void NetworkMessage::AddPosition(const Position &pos)
  173. {
  174.     AddU16(pos.x); // linia 200
  175.     AddU16(pos.y); // linia 201
  176.     AddByte(pos.z);
  177. }
  178.  
  179. ==1749==    by 0x26A532: Protocol76::AddTileUpdated(NetworkMessage&, Position const&) (protocol76.cpp:2124)
  180. void Protocol76::AddTileUpdated(NetworkMessage &msg, const Position &pos)
  181. {
  182. #ifdef __DEBUG__
  183.     std::cout << "Pop-up item from below..." << std::endl;
  184. #endif
  185.  
  186.     if (CanSee(pos.x, pos.y, pos.z))
  187.     {
  188.         msg.AddByte(0x69);
  189.         msg.AddPosition(pos); // linia 2124
  190.  
  191.         Tile* tile = game->getTile(pos.x, pos.y, pos.z);
  192.         if(tile)
  193.         {
  194. #ifdef TRS_GM_INVISIBLE
  195.             GetTileDescription(tile, msg, player);
  196. #else
  197.             GetTileDescription(tile, msg);
  198. #endif //TRS_GM_INVISIBLE
  199.             msg.AddByte(0);
  200.             msg.AddByte(0xFF);
  201.         }
  202.         else {
  203.             msg.AddByte(0x01);
  204.             msg.AddByte(0xFF);
  205.         }
  206.     }
  207. }
  208. ==1749==    by 0x26A619: Protocol76::sendTileUpdated(Position const&) (protocol76.cpp:2147)
  209. ==1749==    by 0x24E3DD: Player::onTileUpdated(Position const&) (player.cpp:2397)
  210. ==1749==    by 0x187E24: Game::creatureBroadcastTileUpdated(Position const&) (game.cpp:9552)
  211. ==1749==    by 0x293829: Tile::clean() (tile.cpp:702)
  212. ==1749==    by 0x219FEB: Map::clean() (map.cpp:1124)
  213. int32_t Map::clean()
  214. {
  215.     uint64_t start = OTSYS_TIME();
  216.     size_t tiles = 0;
  217.     int32_t RemovedItems = 0;
  218.     for (auto tile : g_game.getTilesToClean())
  219.     {
  220.         if (!tile) {continue;}
  221.  
  222.         ++tiles;
  223.         RemovedItems += tile->clean(); // linia 1124
  224.     }
  225.     g_game.clearTilesToClean();
  226.    
  227.     std::cout << "> CLEAN: Removed " << RemovedItems << " item" << (RemovedItems != 1 ? "s" : "")
  228.         << " from " << tiles << " tile" << (tiles != 1 ? "s" : "") << " in "
  229.         << (OTSYS_TIME() - start) / (1000.) << " seconds." << std::endl;
  230.     return RemovedItems;
  231. }
  232.  
  233. ==1749==    by 0x18C5E4: Game::cleanMap() (game.cpp:10454)
  234.  
  235. int32_t Game::cleanMap()
  236. {
  237.     OTSYS_THREAD_LOCK_CLASS lockClass(gameLock, "Game::cleanMap()");
  238.     return map->clean(); // linia 10454
  239. }
  240.  
  241.  
  242.  
  243. <=====><=====><=====><=====><=====><=====>
  244. <=====><=====>Błąd 4<=====><=====><=====>
  245. <=====><=====><=====><=====><=====><=====
  246. ==1749== Invalid read of size 4
  247. ==1749==    at 0x26A551: Protocol76::AddTileUpdated(NetworkMessage&, Position const&) (protocol76.cpp:2126)
  248. void Protocol76::AddTileUpdated(NetworkMessage &msg, const Position &pos)
  249. {
  250. #ifdef __DEBUG__
  251.     std::cout << "Pop-up item from below..." << std::endl;
  252. #endif
  253.  
  254.     if (CanSee(pos.x, pos.y, pos.z))
  255.     {
  256.         msg.AddByte(0x69);
  257.         msg.AddPosition(pos);
  258.  
  259.         Tile* tile = game->getTile(pos.x, pos.y, pos.z); // linia 2126
  260.         if(tile)
  261.         {
  262. #ifdef TRS_GM_INVISIBLE
  263.             GetTileDescription(tile, msg, player);
  264. #else
  265.             GetTileDescription(tile, msg);
  266. #endif //TRS_GM_INVISIBLE
  267.             msg.AddByte(0);
  268.             msg.AddByte(0xFF);
  269.         }
  270.         else {
  271.             msg.AddByte(0x01);
  272.             msg.AddByte(0xFF);
  273.         }
  274.     }
  275. }
  276. ==1749==    by 0x26A619: Protocol76::sendTileUpdated(Position const&) (protocol76.cpp:2147)
  277. ==1749==    by 0x24E3DD: Player::onTileUpdated(Position const&) (player.cpp:2397)
  278. ==1749==    by 0x187E24: Game::creatureBroadcastTileUpdated(Position const&) (game.cpp:9552)
  279.  
  280.  
  281.  
  282.  
  283.  
  284. Dodam ze drugi blad w tym temacie wlasnie wskazywal na funckje GetSpectators (skompilowane z flaga SPECTATOR_FIX)
  285. game.cpp
  286. void Game::getSpectators(const Range& range, SpectatorVec& list, bool onlyPlayers /*=true*/, bool checkDuplicate /*=false*/)
  287. {
  288.     if(map){
  289.         map->getSpectators(range, list, onlyPlayers, checkDuplicate);
  290.     }
  291. }
  292.  
  293.  
  294. map.cpp
  295. #ifdef SPECTATOR_FIX
  296. void Map::getSpectators(const Range& range, SpectatorVec& list, bool onlyPlayers /*=true*/, bool checkDuplicate /*=false*/)
  297. {
  298.     /*
  299.     #ifdef __DEBUG__
  300.         std::cout << "Viewer position at x: " << range.centerpos.x
  301.             << ", y: " << range.centerpos.y
  302.             << ", z: " << range.centerpos.z << std::endl;
  303.         std::cout << "Min Range x: " << range.minRange.x
  304.             << ", y: " << range.minRange.y
  305.             << ", z: " << range.minRange.z << std::endl;
  306.         std::cout << "Max Range x: " << range.maxRange.x
  307.             << ", y: " << range.maxRange.y
  308.             << ", z: " << range.maxRange.z << std::endl;
  309.     #endif
  310.     */
  311.  
  312.     int32_t offsetz;
  313.     CreatureVector::iterator cit;
  314.     Tile *tile;
  315.  
  316.     for(int32_t nz = range.minRange.z; nz != range.maxRange.z + range.zstep; nz += range.zstep)
  317.     {
  318.         offsetz = range.centerpos.z - nz;
  319.         //negative offset means that the player is on a lower floor than ourself
  320.  
  321.         for (int32_t nx = range.minRange.x + offsetz; nx <= range.maxRange.x + offsetz; ++nx)
  322.         {
  323.             for (int32_t ny = range.minRange.y + offsetz; ny <= range.maxRange.y + offsetz; ++ny)
  324.             {
  325.                 tile = getTile(nx + range.centerpos.x, ny + range.centerpos.y, nz);
  326.                 if (tile)
  327.                 {
  328.                     for (cit = tile->creatures.begin(); cit != tile->creatures.end(); ++cit)
  329.                     {
  330.                         /*
  331.                         #ifdef __DEBUG__
  332.                                                 std::cout << "Found " << (*cit)->getName() << " at x: " << (*cit)->pos.x << ", y: " << (*cit)->pos.y << ", z: " << (*cit)->pos.z << ", offset: " << offsetz << std::endl;
  333.                         #endif
  334.                         */
  335.                         if (*cit) // dodane przeze mnie dla pewnosci
  336.                         list.push_back((*cit));
  337.                     }
  338.                 }
  339.             }
  340.         }
  341.     }
  342. }
  343. #else
  344. void Map::getSpectators(const Range& range, SpectatorVec& list, bool onlyPlayers /*=true*/, bool checkDuplicate /*=false*/)
  345. {
  346.     Position centerPos = range.centerpos;
  347.     if(centerPos.z >= MAP_LAYER){
  348.         return;
  349.     }
  350.  
  351.     bool multifloor = false;
  352.     if(range.minRange.z != range.maxRange.z){
  353.         multifloor = true;
  354.     }
  355.  
  356.     bool foundCache = false;
  357.     bool cacheResult = false;
  358.    
  359.     if(range.minRange.x == -9 && range.maxRange.x == 9 && range.minRange.y == -7 && range.maxRange.y == 7 && multifloor){
  360.         if(onlyPlayers){
  361.             SpectatorCache::iterator it = playersSpectatorCache.find(centerPos);
  362.             if(it != playersSpectatorCache.end()){
  363.                 SpectatorVec playersList;
  364.                 playersList = *it->second;
  365.                 if(list.empty()){
  366.                     list = playersList;
  367.                 }
  368.                 else
  369.                 {
  370.                     list.insert(list.end(), playersList.begin(), playersList.end());
  371.                     /*
  372.                     SpectatorVec::iterator pit;
  373.                     for(pit = playersList.begin(); pit != playersList.end(); ++pit){
  374.                         list.push_back(*pit);
  375.                     }*/
  376.                 }
  377.                 foundCache = true;
  378.             }
  379.         }
  380.  
  381.         if(!foundCache){
  382.             SpectatorCache::iterator it = spectatorCache.find(centerPos);
  383.             if(it != spectatorCache.end()){
  384.                 if(!onlyPlayers){
  385.                     SpectatorVec creaturesList;
  386.                     creaturesList = *it->second;
  387.                     if(list.empty()){
  388.                         list = creaturesList;
  389.                     }
  390.                     else
  391.                     {
  392.                         list.insert(list.end(), creaturesList.begin(), creaturesList.end());
  393.                         /*
  394.                         SpectatorVec::iterator cit;
  395.                         for(cit = creaturesList.begin(); cit != creaturesList.end(); ++cit){
  396.                             list.push_back(*cit);
  397.                         }*/
  398.                     }
  399.                 }
  400.                 else
  401.                 {
  402.                     SpectatorVec playersList;
  403.                     playersList = *it->second;
  404.                     SpectatorVec::iterator pit;
  405.                     Player* playerSpectator = NULL;
  406.                     for(pit = playersList.begin(); pit != playersList.end(); ++pit){
  407.                         playerSpectator = dynamic_cast<Player*>(*pit);
  408.                         if(playerSpectator){
  409.                             list.push_back(playerSpectator);
  410.                         }
  411.                     }
  412.                 }
  413.                 foundCache = true;
  414.             }
  415.             else
  416.             {
  417.                 cacheResult = true;
  418.             }
  419.         }
  420.     }
  421.  
  422.     if(!foundCache){
  423.         /*CreatureVector::iterator cit;
  424.         Tile* tile = NULL;
  425.         int32_t offsetz;
  426.         for(int nz = range.minRange.z; nz != range.maxRange.z + range.zstep; nz += range.zstep){
  427.             offsetz = range.centerpos.z - nz;
  428.             //negative offset means that the player is on a lower floor than ourself
  429.             for(int nx = range.minRange.x + offsetz; nx <= range.maxRange.x + offsetz; ++nx){
  430.                 for(int ny = range.minRange.y + offsetz; ny <= range.maxRange.y + offsetz; ++ny){
  431.                     tile = getTile(nx + range.centerpos.x, ny + range.centerpos.y, nz);
  432.                     if(tile){
  433.                         for(cit = tile->creatures.begin(); cit != tile->creatures.end(); ++cit){
  434.                             if(checkDuplicate){
  435.                                 if(std::find(list.begin(), list.end(), *cit) == list.end()){
  436.                                     list.push_back(*cit);
  437.                                 }
  438.                             }
  439.                             else
  440.                             {
  441.                                 list.push_back(*cit);
  442.                             }
  443.                         }
  444.                     }
  445.                 }
  446.             }
  447.         }*/
  448.         int16_t min_y = centerPos.y + range.minRange.y;
  449.         int16_t min_x = centerPos.x + range.minRange.x;
  450.         int16_t max_y = centerPos.y + range.maxRange.y;
  451.         int16_t max_x = centerPos.x + range.maxRange.x;
  452.  
  453.         int32_t minoffset = centerPos.z - range.maxRange.z;
  454.         uint16_t x1 = std::min<uint32_t>(0xFFFF, std::max<int32_t>(0, (min_x + minoffset)));
  455.         uint16_t y1 = std::min<uint32_t>(0xFFFF, std::max<int32_t>(0, (min_y + minoffset)));
  456.  
  457.         int32_t maxoffset = centerPos.z - range.minRange.z;
  458.         uint16_t x2 = std::min<uint32_t>(0xFFFF, std::max<int32_t>(0, (max_x + maxoffset)));
  459.         uint16_t y2 = std::min<uint32_t>(0xFFFF, std::max<int32_t>(0, (max_y + maxoffset)));
  460.  
  461.         int32_t startx1 = x1 - (x1 % FLOOR_SIZE);
  462.         int32_t starty1 = y1 - (y1 % FLOOR_SIZE);
  463.         int32_t endx2 = x2 - (x2 % FLOOR_SIZE);
  464.         int32_t endy2 = y2 - (y2 % FLOOR_SIZE);
  465.  
  466.         QTreeLeafNode* startLeaf = QTreeNode::getLeafStatic(&root, startx1, starty1);
  467.         QTreeLeafNode* leafS = startLeaf;
  468.         QTreeLeafNode* leafE;
  469.        
  470.         Creature* creature = NULL;
  471.         for(int_fast32_t ny = starty1; ny <= endy2; ny += FLOOR_SIZE){
  472.             leafE = leafS;
  473.             for(int_fast32_t nx = startx1; nx <= endx2; nx += FLOOR_SIZE){
  474.                 if(leafE){
  475.                     CreatureVector& node_list = (onlyPlayers ? leafE->player_list : leafE->creature_list);
  476.                     for(CreatureVector::const_iterator it = node_list.begin(); it != node_list.end(); ++it){
  477.                         creature = (*it);
  478.                         const Position& cpos = creature->pos;
  479.                         if(range.minRange.z > cpos.z || range.maxRange.z < cpos.z){
  480.                             continue;
  481.                         }
  482.                        
  483.                         int16_t offsetZ = centerPos.z - cpos.z;
  484.                         if((min_y + offsetZ) > cpos.y || (max_y + offsetZ) < cpos.y || (min_x + offsetZ) > cpos.x || (max_x + offsetZ) < cpos.x){
  485.                            continue;
  486.                         }
  487.                        
  488.                         if(checkDuplicate){
  489.                             if(std::find(list.begin(), list.end(), creature) == list.end()){
  490.                                 list.push_back(creature);
  491.                             }
  492.                         }
  493.                         else
  494.                         {
  495.                             list.push_back(creature);
  496.                         }
  497.                     }
  498.                     leafE = leafE->stepEast();
  499.                 }
  500.                 else
  501.                 {
  502.                     leafE = getLeaf(nx + FLOOR_SIZE, ny);
  503.                 }
  504.             }
  505.             if(leafS){
  506.                 leafS = leafS->stepSouth();
  507.             }
  508.             else
  509.             {
  510.                 leafS = getLeaf(startx1, ny + FLOOR_SIZE);
  511.             }
  512.         }
  513.        
  514.         if(cacheResult){
  515.             if(onlyPlayers){
  516.                 playersSpectatorCache[centerPos].reset(new SpectatorVec(list));
  517.             }
  518.             else
  519.             {
  520.                 spectatorCache[centerPos].reset(new SpectatorVec(list)); // tu crashowalo
  521.             }
  522.         }
  523.     }
  524. }
  525. #endif //SPECTATOR_FIX
  526.  
  527.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement