Was referencing a stack allocated variable from a lambda that was called

from a different stack. Ugh.
This commit is contained in:
casey langen 2020-10-27 21:42:33 -07:00
parent 8ccb1b8fd4
commit 93acbbb7a5
2 changed files with 52 additions and 4 deletions

View File

@ -278,9 +278,9 @@ void TrackList::CacheWindow(size_t from, size_t to, bool async) const {
if (async) {
currentWindow.Set(from, to);
auto shared = shared_from_this(); /* ensure we remain alive for the duration of the query */
bool completionFinished = false;
auto completion = [this, &completionFinished, shared, from, to, query](auto q) {
if (completionFinished) {
auto completionFinished = std::make_shared<bool>(false); /* ugh... keep it alive. */
auto completion = [this, completionFinished, shared, from, to, query](auto q) {
if (*completionFinished) {
return;
}
if (query->GetStatus() == IQuery::Finished) {
@ -296,7 +296,7 @@ void TrackList::CacheWindow(size_t from, size_t to, bool async) const {
this->CacheWindow(from, to, true);
}
this->WindowCached(const_cast<TrackList*>(this), from, to);
completionFinished = true;
*completionFinished = true;
};
this->library->EnqueueAndWait(query, kCacheWindowTimeoutMs, completion);

View File

@ -0,0 +1,48 @@
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004-2020 musikcube team
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
namespace cursespp {
namespace InternalWindowMessages {
/* range of message ids reserved for internal use. exercise caution if
creating your own messages within this range. */
static const int kLastReservedMessageId = INT_MAX;
static const int kFirstReservedMessageId = kLastReservedMessageId - 1024;
static const int NotifyVisibilityChanged = kFirstReservedMessageId + 1;
static const int NotifyChildFocusChanged = kFirstReservedMessageId + 2;
}
}