mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 08:04:01 +02:00
Merge pull request #4231 from ZappoMan/crashonexit
BUG FIXES: Crash on Exit with partially loaded scene & (near)-infinite loop in skipForward physics
This commit is contained in:
commit
6a4577b6a5
4 changed files with 42 additions and 15 deletions
|
@ -73,6 +73,7 @@
|
|||
#include <PhysicsEngine.h>
|
||||
#include <ProgramObject.h>
|
||||
#include <ResourceCache.h>
|
||||
#include <ScriptCache.h>
|
||||
#include <SettingHandle.h>
|
||||
#include <SoundCache.h>
|
||||
#include <TextRenderer.h>
|
||||
|
@ -188,6 +189,7 @@ bool setupEssentials(int& argc, char** argv) {
|
|||
auto jsConsole = DependencyManager::set<StandAloneJSConsole>();
|
||||
auto dialogsManager = DependencyManager::set<DialogsManager>();
|
||||
auto bandwidthRecorder = DependencyManager::set<BandwidthRecorder>();
|
||||
auto resouceCacheSharedItems = DependencyManager::set<ResouceCacheSharedItems>();
|
||||
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
|
||||
auto speechRecognizer = DependencyManager::set<SpeechRecognizer>();
|
||||
#endif
|
||||
|
@ -514,6 +516,11 @@ Application::~Application() {
|
|||
_myAvatar = NULL;
|
||||
|
||||
DependencyManager::destroy<GLCanvas>();
|
||||
DependencyManager::destroy<AnimationCache>();
|
||||
DependencyManager::destroy<TextureCache>();
|
||||
DependencyManager::destroy<GeometryCache>();
|
||||
DependencyManager::destroy<ScriptCache>();
|
||||
DependencyManager::destroy<SoundCache>();
|
||||
}
|
||||
|
||||
void Application::initializeGL() {
|
||||
|
|
|
@ -548,7 +548,10 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
|
|||
// is sending us data with a known "last simulated" time. That time is likely in the past, and therefore
|
||||
// this "new" data is actually slightly out of date. We calculate the time we need to skip forward and
|
||||
// use our simulation helper routine to get a best estimate of where the entity should be.
|
||||
float skipTimeForward = (float)(now - _lastSimulated) / (float)(USECS_PER_SECOND);
|
||||
const float MIN_TIME_SKIP = 0.0f;
|
||||
const float MAX_TIME_SKIP = 1.0f; // in seconds
|
||||
float skipTimeForward = glm::clamp((float)(now - _lastSimulated) / (float)(USECS_PER_SECOND),
|
||||
MIN_TIME_SKIP, MAX_TIME_SKIP);
|
||||
if (skipTimeForward > 0.0f) {
|
||||
#ifdef WANT_DEBUG
|
||||
qDebug() << "skipTimeForward:" << skipTimeForward;
|
||||
|
|
|
@ -112,27 +112,30 @@ void ResourceCache::reserveUnusedResource(qint64 resourceSize) {
|
|||
}
|
||||
|
||||
void ResourceCache::attemptRequest(Resource* resource) {
|
||||
auto sharedItems = DependencyManager::get<ResouceCacheSharedItems>();
|
||||
if (_requestLimit <= 0) {
|
||||
// wait until a slot becomes available
|
||||
_pendingRequests.append(resource);
|
||||
sharedItems->_pendingRequests.append(resource);
|
||||
return;
|
||||
}
|
||||
_requestLimit--;
|
||||
_loadingRequests.append(resource);
|
||||
sharedItems->_loadingRequests.append(resource);
|
||||
resource->makeRequest();
|
||||
}
|
||||
|
||||
void ResourceCache::requestCompleted(Resource* resource) {
|
||||
_loadingRequests.removeOne(resource);
|
||||
|
||||
auto sharedItems = DependencyManager::get<ResouceCacheSharedItems>();
|
||||
sharedItems->_loadingRequests.removeOne(resource);
|
||||
_requestLimit++;
|
||||
|
||||
// look for the highest priority pending request
|
||||
int highestIndex = -1;
|
||||
float highestPriority = -FLT_MAX;
|
||||
for (int i = 0; i < _pendingRequests.size(); ) {
|
||||
Resource* resource = _pendingRequests.at(i).data();
|
||||
for (int i = 0; i < sharedItems->_pendingRequests.size(); ) {
|
||||
Resource* resource = sharedItems->_pendingRequests.at(i).data();
|
||||
if (!resource) {
|
||||
_pendingRequests.removeAt(i);
|
||||
sharedItems->_pendingRequests.removeAt(i);
|
||||
continue;
|
||||
}
|
||||
float priority = resource->getLoadPriority();
|
||||
|
@ -143,16 +146,13 @@ void ResourceCache::requestCompleted(Resource* resource) {
|
|||
i++;
|
||||
}
|
||||
if (highestIndex >= 0) {
|
||||
attemptRequest(_pendingRequests.takeAt(highestIndex));
|
||||
attemptRequest(sharedItems->_pendingRequests.takeAt(highestIndex));
|
||||
}
|
||||
}
|
||||
|
||||
const int DEFAULT_REQUEST_LIMIT = 10;
|
||||
int ResourceCache::_requestLimit = DEFAULT_REQUEST_LIMIT;
|
||||
|
||||
QList<QPointer<Resource> > ResourceCache::_pendingRequests;
|
||||
QList<Resource*> ResourceCache::_loadingRequests;
|
||||
|
||||
Resource::Resource(const QUrl& url, bool delayLoad) :
|
||||
_url(url),
|
||||
_request(url) {
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include <QUrl>
|
||||
#include <QWeakPointer>
|
||||
|
||||
#include <DependencyManager.h>
|
||||
|
||||
class QNetworkReply;
|
||||
class QTimer;
|
||||
|
||||
|
@ -40,6 +42,21 @@ static const qint64 DEFAULT_UNUSED_MAX_SIZE = 1024 * BYTES_PER_MEGABYTES;
|
|||
static const qint64 MIN_UNUSED_MAX_SIZE = 0;
|
||||
static const qint64 MAX_UNUSED_MAX_SIZE = 10 * BYTES_PER_GIGABYTES;
|
||||
|
||||
// We need to make sure that these items are available for all instances of
|
||||
// ResourceCache derived classes. Since we can't count on the ordering of
|
||||
// static members destruction, we need to use this Dependency manager implemented
|
||||
// object instead
|
||||
class ResouceCacheSharedItems : public Dependency {
|
||||
SINGLETON_DEPENDENCY
|
||||
public:
|
||||
QList<QPointer<Resource> > _pendingRequests;
|
||||
QList<Resource*> _loadingRequests;
|
||||
private:
|
||||
ResouceCacheSharedItems() { }
|
||||
virtual ~ResouceCacheSharedItems() { }
|
||||
};
|
||||
|
||||
|
||||
/// Base class for resource caches.
|
||||
class ResourceCache : public QObject {
|
||||
Q_OBJECT
|
||||
|
@ -51,9 +68,11 @@ public:
|
|||
void setUnusedResourceCacheSize(qint64 unusedResourcesMaxSize);
|
||||
qint64 getUnusedResourceCacheSize() const { return _unusedResourcesMaxSize; }
|
||||
|
||||
static const QList<Resource*>& getLoadingRequests() { return _loadingRequests; }
|
||||
static const QList<Resource*>& getLoadingRequests()
|
||||
{ return DependencyManager::get<ResouceCacheSharedItems>()->_loadingRequests; }
|
||||
|
||||
static int getPendingRequestCount() { return _pendingRequests.size(); }
|
||||
static int getPendingRequestCount()
|
||||
{ return DependencyManager::get<ResouceCacheSharedItems>()->_pendingRequests.size(); }
|
||||
|
||||
ResourceCache(QObject* parent = NULL);
|
||||
virtual ~ResourceCache();
|
||||
|
@ -90,8 +109,6 @@ private:
|
|||
int _lastLRUKey = 0;
|
||||
|
||||
static int _requestLimit;
|
||||
static QList<QPointer<Resource> > _pendingRequests;
|
||||
static QList<Resource*> _loadingRequests;
|
||||
};
|
||||
|
||||
/// Base class for resources.
|
||||
|
|
Loading…
Reference in a new issue