Skip to content

Commit

Permalink
Move NoteFieldPreview PlayerState assignment earlier; skip dupe NoteData
Browse files Browse the repository at this point in the history
  • Loading branch information
poco0317 committed Jan 26, 2021
1 parent 5a7be67 commit 9263978
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Etterna/Actor/Gameplay/NoteFieldPreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ NoteFieldPreview::LoadFromNode(const XNode* pNode)
noteFieldHeight = yReverse - yStandard;
}

m_pPlayerState = GAMESTATE->m_pPlayerState;
if (m_pPlayerState == nullptr) {
LuaHelpers::ReportScriptError(
"PlayerState was somehow null when creating NoteFieldPreview. Report "
Expand Down Expand Up @@ -87,13 +86,17 @@ void
NoteFieldPreview::LoadNoteData(NoteData* pNoteData)
{
// avoid leaking NoteData all over the place
// (this should be comparing pointers, not data)
// something that passes this check was previously loaded via:
// - LoadNoteData
// and was not:
// - already what we have loaded
// - the empty dummy NoteData
if (m_pNoteData != p_dummyNoteData && m_pNoteData != pNoteData)
delete m_pNoteData;
// if the current and incoming NoteData pointers are the same, why load?
else if (m_pNoteData == pNoteData)
return;

const auto* style =
GAMESTATE->GetCurrentStyle(m_pPlayerState->m_PlayerNumber);
Expand Down Expand Up @@ -171,8 +174,10 @@ NoteFieldPreview::NoteFieldPreview()
auto* nd = new NoteData;
nd->Init();
nd->SetNumTracks(4);

p_dummyNoteData = nd;

// This is not guaranteed to be non-null!
m_pPlayerState = GAMESTATE->m_pPlayerState;
}

NoteFieldPreview::~NoteFieldPreview()
Expand Down

0 comments on commit 9263978

Please sign in to comment.