std::map을 사용하던 도중 아래 에러를 맞이했다.
std::_Tree_unchecked_iterator<std::_Tree_val<std::_Tree_simple_types...
원인-> std::map에서 존재하지 않는 키에 접근하면, 새로운 엔트리가 자동으로 추가된다.
map<uint64, PlayerRef> _players;
lock_guard<mutex> lock(_lock);
if (_players[targetPlayerId] != nullptr) // null체크를 함과 동시에 데이터 삽입
{
_players[targetPlayerId]->GetOwnerSession()->Send(sendBuffer);
}
STL std::map을 사용할 때에는 키가 있는지 확인하는 find 메소드를 먼저 사용하자.
auto it = _players.find(targetPlayerId);
if (it != _players.end() && it->second != nullptr)
{
it->second->GetOwnerSession()->Send(sendBuffer);
}
'Study > 에러 정리' 카테고리의 다른 글
mfc - iocp 통신 메모리 누수 (0) | 2024.12.23 |
---|---|
더미클라이언트 테스트, 패킷 지연처리 (0) | 2024.09.11 |
공유포인터 생명주기 확인하기 (0) | 2024.09.10 |
람다식 캡쳐와 const, 공유포인터 업데이트 문제 (0) | 2024.09.08 |
멀티스레드 환경 서버의 패킷 지연처리 (4) | 2024.09.07 |