Merge pull request #199 from knoxHuang/v1.1

fix used spine.getCurrent cause the emulator to crash for #fireball/i…
This commit is contained in:
pandamicro
2016-07-06 16:26:21 +08:00
committed by GitHub
@@ -28,6 +28,8 @@
using namespace spine;
std::unordered_map<spTrackEntry*, jsval> _spTrackEntryMap;
jsval speventdata_to_jsval(JSContext* cx, spEventData& v)
{
JS::RootedObject tmp(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
@@ -278,11 +280,35 @@ jsval sptrackentry_to_jsval(JSContext* cx, spTrackEntry& v)
JS::RootedValue nextVal(cx);
if (v.next)
nextVal = sptrackentry_to_jsval(cx, *v.next);
{
auto nextPtr = v.next;
auto entry = _spTrackEntryMap.find(nextPtr);
if (entry == _spTrackEntryMap.end())
{
_spTrackEntryMap.emplace(nextPtr, nextVal.get());
nextVal = sptrackentry_to_jsval(cx, *v.next);
}
else
{
nextVal.set(entry->second);
}
}
JS::RootedValue previousVal(cx);
if (v.previous)
previousVal = sptrackentry_to_jsval(cx, *v.previous);
{
auto previousPtr = v.previous;
auto entry = _spTrackEntryMap.find(previousPtr);
if (entry == _spTrackEntryMap.end())
{
_spTrackEntryMap.emplace(previousPtr, previousVal.get());
previousVal = sptrackentry_to_jsval(cx, *previousPtr);
}
else
{
previousVal.set(entry->second);
}
}
JS::RootedValue jsanimation(cx, spanimation_to_jsval(cx, *v.animation));
bool ok = JS_DefineProperty(cx, tmp, "delay", v.delay, JSPROP_ENUMERATE | JSPROP_PERMANENT) &&
@@ -449,6 +475,7 @@ bool jsb_cocos2dx_spine_getCurrent(JSContext *cx, uint32_t argc, jsval *vp)
if (ret)
{
jsret = sptrackentry_to_jsval(cx, *ret);
_spTrackEntryMap.clear();
}
} while (0);
@@ -462,6 +489,7 @@ bool jsb_cocos2dx_spine_getCurrent(JSContext *cx, uint32_t argc, jsval *vp)
if (ret)
{
jsret = sptrackentry_to_jsval(cx, *ret);
_spTrackEntryMap.clear();
}
} while (0);
@@ -498,6 +526,7 @@ bool jsb_cocos2dx_spine_setAnimation(JSContext *cx, uint32_t argc, jsval *vp)
if (ret)
{
jsret = sptrackentry_to_jsval(cx, *ret);
_spTrackEntryMap.clear();
}
} while(0);
@@ -535,6 +564,7 @@ bool jsb_cocos2dx_spine_addAnimation(JSContext *cx, uint32_t argc, jsval *vp)
if (ret)
{
jsret = sptrackentry_to_jsval(cx, *ret);
_spTrackEntryMap.clear();
}
} while(0);
@@ -560,6 +590,7 @@ bool jsb_cocos2dx_spine_addAnimation(JSContext *cx, uint32_t argc, jsval *vp)
if (ret)
{
jsret = sptrackentry_to_jsval(cx, *ret);
_spTrackEntryMap.clear();
}
} while(0);