Note that there are some explanatory texts on larger screens.

plurals
  1. POstd::vector push_back() crashes the program
    primarykey
    data
    text
    <p>I have a function that checks for other players' movement on the map and adjusts their position accordingly and it also checks that if the player just entered.</p> <pre><code>void mapManager::checkForOtherPlayerMovement(int plyId) { sf::Packet receivedPacket; std::vector&lt;player&gt;::iterator it; player pl(0,0,1); if(socket-&gt;Receive(receivedPacket) == sf::Socket::Done) { int header; receivedPacket &gt;&gt; header; switch(header) { case PACKET_PLAYER_DISPATCHNEWPOSITION: { receivedPacket &gt;&gt; pl; std::cout &lt;&lt; pl.plyId &lt;&lt; std::endl; if(plyId != pl.plyId) { try { if(pl.plyId != 0) { std::cout &lt;&lt; "DEBUG1" &lt;&lt; std::endl; players-&gt;at(pl.plyId-1).posX = pl.posX; players-&gt;at(pl.plyId-1).posY = pl.posY; } else { std::cout &lt;&lt; "DEBUG2" &lt;&lt; std::endl; players-&gt;at(pl.plyId).posX = pl.posX; players-&gt;at(pl.plyId).posY = pl.posY; } } catch(const std::out_of_range&amp; oor) { std::cout &lt;&lt; "Added new player!" &lt;&lt; std::endl; players-&gt;push_back(pl); // This crashes } } break; } case PACKET_PLAYER_DISPATCHENTEREDMAP: { break; } } } } </code></pre> <p>So basically the crash happens when a new player connects to the server and the game needs to add it inside the vector. Strange thing is that it didn't crash on visual studio 2010, but crashes when I changed to vs 2012 so I must be doing something wrong.</p> <p>EDIT: Here is how the players vector is created</p> <p>mapManager.h</p> <pre><code>std::vector&lt;player&gt; * players; </code></pre> <p>mapManager.cpp</p> <pre><code>players = new std::vector&lt;player&gt;(); </code></pre> <p>Here I use the players vector</p> <pre><code>void mapManager::drawOtherPlayers(int plyId, player *ownPlayer) { ownPlayerSprite-&gt;SetPosition(ownPlayer-&gt;getX(), ownPlayer-&gt;getY()); window.Draw(*ownPlayerSprite); for(std::vector&lt;player&gt;::iterator it = players-&gt;begin(); it != players-&gt;end(); ++it) { spriteToDraw-&gt;SetPosition(it-&gt;posX,it-&gt;posY); window.Draw(*spriteToDraw); } } </code></pre> <p>My player class: <a href="http://pastebin.com/LJhQdFpL" rel="nofollow">Player.h and player.cpp</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload