mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-10-14 07:17:44 +00:00
Exact rooting for CallConstructor.
Refs #2415 Refs #2462 This was SVN commit r15601.
This commit is contained in:
@@ -708,6 +708,9 @@ void CComponentManager::AddSystemComponents(bool skipScriptedComponents, bool sk
|
||||
|
||||
IComponent* CComponentManager::ConstructComponent(CEntityHandle ent, ComponentTypeId cid)
|
||||
{
|
||||
JSContext* cx = m_ScriptInterface.GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
std::map<ComponentTypeId, ComponentType>::const_iterator it = m_ComponentTypesById.find(cid);
|
||||
if (it == m_ComponentTypesById.end())
|
||||
{
|
||||
@@ -729,11 +732,14 @@ IComponent* CComponentManager::ConstructComponent(CEntityHandle ent, ComponentTy
|
||||
std::map<entity_id_t, IComponent*>& emap2 = m_ComponentsByTypeId[cid];
|
||||
|
||||
// If this is a scripted component, construct the appropriate JS object first
|
||||
jsval obj = JSVAL_NULL;
|
||||
JS::RootedValue obj(cx);
|
||||
// TODO: Check if this temporary root can be removed after SpiderMonkey 31 upgrade
|
||||
JS::RootedValue tmpCtor(cx, ct.ctor.get());
|
||||
if (ct.type == CT_Script)
|
||||
{
|
||||
obj = m_ScriptInterface.CallConstructor(ct.ctor.get(), 0, JSVAL_VOID);
|
||||
if (JSVAL_IS_VOID(obj))
|
||||
JS::AutoValueVector argv(cx); // TODO: With SpiderMonkey 31, we can pass JS::HandleValueArray::empty()
|
||||
m_ScriptInterface.CallConstructor(tmpCtor, argv, &obj);
|
||||
if (obj.isNull())
|
||||
{
|
||||
LOGERROR(L"Script component constructor failed");
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user