Merge pull request #13709 from thoys/fix/require-load-queue

MS17041: Fix for require fail when the same script loaded simultaneously from another entity script
This commit is contained in:
John Conklin II 2018-08-01 11:15:32 -07:00 committed by GitHub
commit 7a635b6a57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 5 deletions

View file

@ -40,7 +40,6 @@
#include <PointerManager.h>
size_t std::hash<EntityItemID>::operator()(const EntityItemID& id) const { return qHash(id); }
std::function<bool()> EntityTreeRenderer::_entitiesShouldFadeFunction;
QString resolveScriptURL(const QString& scriptUrl) {

View file

@ -40,9 +40,6 @@ namespace render { namespace entities {
} }
// Allow the use of std::unordered_map with QUuid keys
namespace std { template<> struct hash<EntityItemID> { size_t operator()(const EntityItemID& id) const; }; }
using EntityRenderer = render::entities::EntityRenderer;
using EntityRendererPointer = render::entities::EntityRendererPointer;
using EntityRendererWeakPointer = render::entities::EntityRendererWeakPointer;

View file

@ -69,3 +69,4 @@ QVector<EntityItemID> qVectorEntityItemIDFromScriptValue(const QScriptValue& arr
return newVector;
}
size_t std::hash<EntityItemID>::operator()(const EntityItemID& id) const { return qHash(id); }

View file

@ -45,4 +45,7 @@ QScriptValue EntityItemIDtoScriptValue(QScriptEngine* engine, const EntityItemID
void EntityItemIDfromScriptValue(const QScriptValue &object, EntityItemID& properties);
QVector<EntityItemID> qVectorEntityItemIDFromScriptValue(const QScriptValue& array);
// Allow the use of std::unordered_map with QUuid keys
namespace std { template<> struct hash<EntityItemID> { size_t operator()(const EntityItemID& id) const; }; }
#endif // hifi_EntityItemID_h

View file

@ -219,6 +219,20 @@ ScriptEngine::ScriptEngine(Context context, const QString& scriptContents, const
}
logException(output);
});
if (_type == Type::ENTITY_CLIENT || _type == Type::ENTITY_SERVER) {
QObject::connect(this, &ScriptEngine::update, this, [this]() {
// process pending entity script content
if (!_contentAvailableQueue.empty()) {
EntityScriptContentAvailableMap pending;
std::swap(_contentAvailableQueue, pending);
for (auto& pair : pending) {
auto& args = pair.second;
entityScriptContentAvailable(args.entityID, args.scriptOrURL, args.contents, args.isURL, args.success, args.status);
}
}
});
}
}
QString ScriptEngine::getContext() const {
@ -2181,7 +2195,7 @@ void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString&
qCDebug(scriptengine) << "loadEntityScript.contentAvailable" << status << QUrl(url).fileName() << entityID.toString();
#endif
if (!isStopping() && _entityScripts.contains(entityID)) {
entityScriptContentAvailable(entityID, url, contents, isURL, success, status);
_contentAvailableQueue[entityID] = { entityID, url, contents, isURL, success, status };
} else {
#ifdef DEBUG_ENTITY_STATES
qCDebug(scriptengine) << "loadEntityScript.contentAvailable -- aborting";

View file

@ -12,6 +12,7 @@
#ifndef hifi_ScriptEngine_h
#define hifi_ScriptEngine_h
#include <unordered_map>
#include <vector>
#include <QtCore/QObject>
@ -71,6 +72,17 @@ public:
//bool forceRedownload;
};
struct EntityScriptContentAvailable {
EntityItemID entityID;
QString scriptOrURL;
QString contents;
bool isURL;
bool success;
QString status;
};
typedef std::unordered_map<EntityItemID, EntityScriptContentAvailable> EntityScriptContentAvailableMap;
typedef QList<CallbackData> CallbackList;
typedef QHash<QString, CallbackList> RegisteredEventHandlers;
@ -762,6 +774,7 @@ protected:
QHash<EntityItemID, EntityScriptDetails> _entityScripts;
QHash<QString, EntityItemID> _occupiedScriptURLs;
QList<DeferredLoadEntity> _deferredEntityLoads;
EntityScriptContentAvailableMap _contentAvailableQueue;
bool _isThreaded { false };
QScriptEngineDebugger* _debugger { nullptr };