cuberite/cuberite

cScoreBoard:RegisterTeam doesn't return cTeam

209CATrus opened this issue · 3 comments

Client version: Latest
Server OS: Windows/Linux
Cuberite Commit id: Doesn't matter

Expected behavior

cScoreBoard:RegisterTeam returning team handle

Actual behavior

Apparently returns nil

Steps to reproduce the behavior

@tonitch Can help with reproduction, but that shouldn't be necessary

Server log

Relevant part of server log

for some reasons, here is the value of status (from gdb) at line 366

cuberite/src/Scoreboard.cpp

Lines 359 to 369 in 8a763d3

cTeam * cScoreboard::RegisterTeam(
const AString & a_Name, const AString & a_DisplayName,
const AString & a_Prefix, const AString & a_Suffix
)
{
cTeam Team(a_Name, a_DisplayName, a_Prefix, a_Suffix);
std::pair<cTeamMap::iterator, bool> Status = m_Teams.insert(cNamedTeam(a_Name, Team));
return Status.second ? &Status.first->second : nullptr;
}

$1 = {first = <error reading variable: Cannot access memory at address 0x100000000>, second = false}
so obviously the return statement return false as second = false...

Edit: okay my bad. I forgot to go to next line so the value would be set...
In reality, it returns my element in first and second is true if it's the first time the team is created and then false (so nil for lua) whenever we retry to create a team with the same name!

So I think that the real issue is that it is not really explained well in the doc or maybe that it should not behave like that...

a way to avoid confusion while not altering any change in the current plugins is to use
std::map::insert_or_assign instead of insert... I don't think it's a bad idea ^^

12xx12 commented

The return value is NIL if a team with the same name already exists. I will add an error message to console and documentation to explain this