LuaEngineImpl synchronisation / accelerometer support

LuaEngineImpl synchronisation / accelerometer support
0.0 0



I began writing some accelerometer support by hijacking the existing touch/es infrastructure. My first stab (before re-factoring out the common script hook handling code to a seperate (touch-agnostic) location) can be found here :

This works, ‘woot!’ … however it suggests a somewhat fundamental issue. There appears to be no locking within LuaEngineImpl :frowning: Which means that I have both:

sceneLayer.CCTouchDelegate:registerScriptTouchHandler(cocos2d.CCDIDACCELERATE, “didAccelerate”)


cocos2d.CCScheduler:sharedScheduler():scheduleScriptFunc(“tick”, 0.01, false)

firing, sometimes (and oddly only for android?) they (I think) occur con-currently so lua’s global state ends up in an in-consistent manner (and seg-faults)

I’m not too clear on the threading models involved, can anyone explain them? … I’m surprised that I don’t see the issue on iOS tbh, so I can only assume that the thread-locking/spawning is being dealt with outside of the code, but not for the android, I also don’t understand why this doesn’t affect the touch/es handlers ?


Ok, so after adding CCLock->lock/unlock to LuaEngineImpl, I discover:

// cocos2d-x havn’t support multi-thread yet

So presumably, what I’m doing is wrong :slight_smile: … Any hints ??


CCLock isn’t implemented on ios. And on android port, I haven’t write a strict unit test on it.
We plan to do the multi-thread feature at first in #354, then #465.


Okay. in the meantime is there an approach you would suggest for doing synchronisation ? (I still don’t understand why the accelerometer -> lua is Ok for iOs,but not for android :frowning: !)