移动版Safari使用Hammer.js时崩溃

26

我正在为iPad编写一个JavaScript多人游戏。我在使用Smartfox服务器进行多人游戏,同时使用Hammer.js处理触摸事件。

当我在游戏的某个特定部分使用Hammer事件时,会导致移动版Safari崩溃。在PC上完全正常,但在iPad上会引起崩溃。

问题出现在以下代码中:

this.startButton.hammer().on("tap", this.handleStartClicked);

在“handleStartClicked”函数中,我所做的一切就是从输入框中获取用户的名称和密码,将它们保存到本地存储(如果可用),并调用Smartfox的“connect”函数,该函数连接用户到Smartfox并开始登录过程。这是函数:

onStartClicked:function(e){
  if(this.nameInput.val() == "" || this.pwInput.val() == "") {return;}

  this.startButton.unbind("click", this.onStartClickBind);

  if(window.localStorage != null && window['localStorage'] != null){
    window.localStorage.username = this.nameInput.val();
    window.localStorage.password = this.pwInput.val();
  }

  this.sfs.connect();

如果我点击“开始”按钮,移动版Safari有80%的概率崩溃。 即使它不会立即在该单击上崩溃,但通常在游戏的某个时候崩溃。 但是,如果我从不单击“开始”按钮(例如,如果我只是自动启动用户而没有触摸交互),则崩溃永远不会发生-甚至在游戏的后期也不会发生。 我甚至尝试完全删除“开始”按钮,只向整个文档添加触摸监听器,它仍然崩溃,因此似乎与特定按钮无关(它只是包装在jQuery对象中的普通HTML按钮)。

有趣的是,如果我将Hammer.js事件更改为常规的jQuery事件:

this.startButton.bind("click", this.onStartClickBind);

移动版Safari从未崩溃。无论是在启动点击时...还是在游戏的任何时候。它似乎可以修复所有问题。另一个奇怪的事情是,我在我的其他代码中到处使用Hammer事件,但唯一出现问题的地方是这个处理程序。我不知道与其他处理程序不同的是什么,除非崩溃与移动版Safari、Hammer.js和Smartfox之间的交互有关。不过,在游戏中的其他Hammer处理程序中,我也向Smartfox发送调用,它们并没有使Safari崩溃,因此这似乎不太可能。

另外,下面是iPad的崩溃日志,如果有更多信息,请参考:

Incident Identifier: 540C3060-271F-468E-9DF8-DA641DACA406
CrashReporter Key:   a5c833f7168137e99d3c8aa6a4d35804a584b7b4
Hardware Model:      iPad3,1
Process:             Web [210]
Path:                /var/mobile/Applications/327316BD-8A50-4245-B728-  
E6504C19A76D/Web.app/Web
Identifier:          com.apple.webapp
Version:             1.0 (1.0)
Code Type:           ARM (Native)
Parent Process:      launchd [1]

Date/Time:           2014-01-13 14:01:50.112 -0800
OS Version:          iOS 7.0.4 (11B554a)
Report Version:      104

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000000000defe
Triggered by Thread:  4

Thread 0:
0   JavaScriptCore                  0x306a61f2 JSC::JSValue::get(JSC::ExecState*,   
JSC::PropertyName, JSC::PropertySlot&) const + 678
1   JavaScriptCore                  0x3069a5de llint_slow_path_get_by_id + 162
2   JavaScriptCore                  0x3069fbaa llint_op_get_by_id + 132
3   JavaScriptCore                  0x306ab434 JSC::call(JSC::ExecState*, JSC::JSValue,  
JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) + 52
4   WebCore                         0x37787ad2  
WebCore::JSMainThreadExecState::call(JSC::ExecState*, JSC::JSValue, JSC::CallType,   
JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) + 142
5   WebCore                         0x379707bc  
WebCore::JSEventListener::handleEvent(WebCore::ScriptExecutionContext*,   
WebCore::Event*) + 516
6   WebCore                         0x3792edca     
WebCore::EventTarget::fireEventListeners(WebCore::Event*, WebCore::EventTargetData*,  
WTF::Vector<WebCore::RegisteredEventListener, 1ul, WTF::CrashOnOverflow>&) + 482
7   WebCore                         0x3782ea2a   
WebCore::EventTarget::fireEventListeners(WebCore::Event*) + 174
8   WebCore                         0x379e7f24 
WebCore::EventTarget::dispatchEvent(WTF::PassRefPtr<WebCore::Event>) + 60
9   WebCore                         0x380e56e0 
WebCore::WebSocket::didReceiveMessage(WTF::String const&) + 68
10  WebCore                         0x380e7ef0  
WebCore::WebSocketChannel::processFrame() + 2292
11  WebCore                         0x380e71a0  
WebCore::WebSocketChannel::processBuffer() + 80
12  WebCore                         0x380e713c 
WebCore::WebSocketChannel::didReceiveSocketStreamData(WebCore::SocketStreamHandle*, 
char const*, int) + 232
13  WebCore                         0x37fdc5c4    
WebCore::SocketStreamHandle::readStreamCallback(unsigned long) + 236
14  CoreFoundation                  0x2f68f918 _signalEventSync + 116
15  CoreFoundation                  0x2f698ee8 _cfstream_solo_signalEventSync + 192
16  CoreFoundation                  0x2f68f5c8 _CFStreamSignalEvent + 324
17  CFNetwork                       0x2f2f277a  
CoreReadStreamCFStreamSupport::coreStreamReadEvent(__CoreReadStream*, unsigned long) +   
70
18  CFNetwork                       0x2f2f2726    
CoreReadStreamClient::coreStreamEventsAvailable(unsigned long) + 34
19  CFNetwork                       0x2f399110 
CoreStreamBase::_callClientNow(CoreStreamClient*) + 40
20  CFNetwork                       0x2f2f24ca  
CoreStreamBase::_streamSetEventAndScheduleDelivery(unsigned long, unsigned char) + 118
21  CFNetwork                       0x2f2f2376 
CoreStreamBase::_streamInterface_SignalEvent(unsigned long, CFStreamError const*) + 30
22  CFNetwork                       0x2f2f2312  
SocketStream::dispatchSignalFromSocketCallbackUnlocked(SocketStreamSignalHolder*) + 50
23  CFNetwork                       0x2f2f1db4 
SocketStream::socketCallback(__CFSocket*, unsigned long, __CFData const*, void const*)   
+ 140
24  CFNetwork                       0x2f2f1cee  
SocketStream::_SocketCallBack_stream(__CFSocket*, unsigned long, __CFData const*, void    
const*, void*) + 54
25  CoreFoundation                  0x2f6cb334 __CFSocketPerformV0 + 576
26  CoreFoundation                  0x2f6c9180 
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12
27  CoreFoundation                  0x2f6c864e __CFRunLoopDoSources0 + 202
28  CoreFoundation                  0x2f6c6e42 __CFRunLoopRun + 618
29  CoreFoundation                  0x2f631c22 CFRunLoopRunSpecific + 518
30  CoreFoundation                  0x2f631a06 CFRunLoopRunInMode + 102
31  GraphicsServices                0x3432527e GSEventRunModal + 134
32  UIKit                           0x31ed5044 UIApplicationMain + 1132
33  Web                             0x000821f6 0x81000 + 4598
34  libdyld.dylib                   0x3a374ab4 start + 0

Thread 1:
0   libsystem_kernel.dylib          0x3a41883c kevent64 + 24
1   libdispatch.dylib               0x3a359210 _dispatch_mgr_invoke + 228
2   libdispatch.dylib               0x3a358f96 _dispatch_mgr_thread$VARIANT$mp + 34

Thread 2:
0   libsystem_kernel.dylib          0x3a42bc7c __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x3a491dc6 _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x3a491c80 start_wqthread + 4

Thread 3:
0   libsystem_kernel.dylib          0x3a42bc7c __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x3a491dc6 _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x3a491c80 start_wqthread + 4

Thread 4 name:  WebThread
Thread 4 Crashed:
0   CoreFoundation                  0x2f62e894 CFRelease + 1132
1   WebCore                         0x37814010 WebCore::stopSharedTimer() + 28
2   WebCore                         0x37a58150  
WebCore::DeferrableOneShotTimer<WebCore::CachedResource>::fired() + 40
3   WebCore                         0x377863fc  
WebCore::ThreadTimers::sharedTimerFiredInternal() + 132
4   WebCore                         0x3778634e WebCore::timerFired(__CFRunLoopTimer*,  
void*) + 22
5   CoreFoundation                  0x2f6c90dc 
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 12
6   CoreFoundation                  0x2f6c8cf2 __CFRunLoopDoTimer + 778
7   CoreFoundation                  0x2f6c708e __CFRunLoopRun + 1206
8   CoreFoundation                  0x2f631c22 CFRunLoopRunSpecific + 518
9   CoreFoundation                  0x2f631a06 CFRunLoopRunInMode + 102
10  WebCore                         0x37814266 RunWebThread(void*) + 414
11  libsystem_pthread.dylib         0x3a493c1a _pthread_body + 138
12  libsystem_pthread.dylib         0x3a493b8a _pthread_start + 98
13  libsystem_pthread.dylib         0x3a491c8c thread_start + 4

Thread 5 name:  com.apple.NSURLConnectionLoader
Thread 5:
0   libsystem_kernel.dylib          0x3a418a8c mach_msg_trap + 20
1   libsystem_kernel.dylib          0x3a418888 mach_msg + 44
2   CoreFoundation                  0x2f6c87be __CFRunLoopServiceMachPort + 150
3   CoreFoundation                  0x2f6c6ee4 __CFRunLoopRun + 780
4   CoreFoundation                  0x2f631c22 CFRunLoopRunSpecific + 518
5   CoreFoundation                  0x2f631a06 CFRunLoopRunInMode + 102
6   Foundation                      0x3006c2f2 +[NSURLConnection(Loader) 
_resourceLoadLoop:] + 314
7   Foundation                      0x300e1c82 __NSThread__main__ + 1058
8   libsystem_pthread.dylib         0x3a493c1a _pthread_body + 138
9   libsystem_pthread.dylib         0x3a493b8a _pthread_start + 98
10  libsystem_pthread.dylib         0x3a491c8c thread_start + 4

Thread 6:
0   libsystem_kernel.dylib          0x3a418a8c mach_msg_trap + 20
1   libsystem_kernel.dylib          0x3a418888 mach_msg + 44
2   CoreFoundation                  0x2f6c87be __CFRunLoopServiceMachPort + 150
3   CoreFoundation                  0x2f6c6ee4 __CFRunLoopRun + 780
4   CoreFoundation                  0x2f631c22 CFRunLoopRunSpecific + 518
5   CoreFoundation                  0x2f631a06 CFRunLoopRunInMode + 102
6   libAVFAudio.dylib               0x2e6b4584 GenericRunLoopThread::Entry(void*) + 124
7   libAVFAudio.dylib               0x2e6a899c CAPThread::Entry(CAPThread*) + 176
8   libsystem_pthread.dylib         0x3a493c1a _pthread_body + 138
9   libsystem_pthread.dylib         0x3a493b8a _pthread_start + 98
10  libsystem_pthread.dylib         0x3a491c8c thread_start + 4

Thread 7:
0   libsystem_kernel.dylib          0x3a42bc7c __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x3a491dc6 _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x3a491c80 start_wqthread + 4

Thread 8:
0   libsystem_kernel.dylib          0x3a42bc7c __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x3a491dc6 _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x3a491c80 start_wqthread + 4

Thread 9 name:  JavaScriptCore::BlockFree
Thread 9:
0   libsystem_kernel.dylib          0x3a42af38 __psynch_cvwait + 24
1   libsystem_pthread.dylib         0x3a493224 _pthread_cond_wait + 536
2   libsystem_pthread.dylib         0x3a494040 pthread_cond_timedwait + 40
3   JavaScriptCore                  0x30656eb0  
WTF::ThreadCondition::timedWait(WTF::Mutex&, double) + 104
4   JavaScriptCore                  0x30656cdc   
JSC::BlockAllocator::blockFreeingThreadMain() + 88
5   JavaScriptCore                  0x306543a0 WTF::wtfThreadEntryPoint(void*) + 12
6   libsystem_pthread.dylib         0x3a493c1a _pthread_body + 138
7   libsystem_pthread.dylib         0x3a493b8a _pthread_start + 98
8   libsystem_pthread.dylib         0x3a491c8c thread_start + 4

Thread 10 name:  JavaScriptCore::Marking
Thread 10:
0   libsystem_kernel.dylib          0x3a42af38 __psynch_cvwait + 24
1   libsystem_pthread.dylib         0x3a493224 _pthread_cond_wait + 536
2   libsystem_pthread.dylib         0x3a494000 pthread_cond_wait + 36
3   JavaScriptCore                  0x307f2236 JSC::GCThread::waitForNextPhase() + 74
4   JavaScriptCore                  0x307f2290 JSC::GCThread::gcThreadMain() + 48
5   JavaScriptCore                  0x306543a0 WTF::wtfThreadEntryPoint(void*) + 12
6   libsystem_pthread.dylib         0x3a493c1a _pthread_body + 138
7   libsystem_pthread.dylib         0x3a493b8a _pthread_start + 98
8   libsystem_pthread.dylib         0x3a491c8c thread_start + 4

Thread 11 name:  WebCore: CFNetwork Loader
Thread 11:
0   libsystem_kernel.dylib          0x3a418a8c mach_msg_trap + 20
1   libsystem_kernel.dylib          0x3a418888 mach_msg + 44
2   CoreFoundation                  0x2f6c87be __CFRunLoopServiceMachPort + 150
3   CoreFoundation                  0x2f6c6ee4 __CFRunLoopRun + 780
4   CoreFoundation                  0x2f631c22 CFRunLoopRunSpecific + 518
5   CoreFoundation                  0x2f631a06 CFRunLoopRunInMode + 102
6   WebCore                         0x3785cd5a WebCore::runLoaderThread(void*) + 250
7   JavaScriptCore                  0x306543a0 WTF::wtfThreadEntryPoint(void*) + 12
8   libsystem_pthread.dylib         0x3a493c1a _pthread_body + 138
9   libsystem_pthread.dylib         0x3a493b8a _pthread_start + 98
10  libsystem_pthread.dylib         0x3a491c8c thread_start + 4

Thread 12 name:  com.apple.CFSocket.private
Thread 12:
0   libsystem_kernel.dylib          0x3a42b440 select$DARWIN_EXTSN + 20
1   CoreFoundation                  0x2f6cc680 __CFSocketManager + 480
2   libsystem_pthread.dylib         0x3a493c1a _pthread_body + 138
3   libsystem_pthread.dylib         0x3a493b8a _pthread_start + 98
4   libsystem_pthread.dylib         0x3a491c8c thread_start + 4

Thread 13:
0   libsystem_kernel.dylib          0x3a42bc7c __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x3a491dc6 _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x3a491c80 start_wqthread + 4

Thread 14:
0   libsystem_kernel.dylib          0x3a42bc7c __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x3a491dc6 _pthread_wqthread + 306
2   libsystem_pthread.dylib         0x3a491c80 start_wqthread + 4

Thread 15 name:  WebCore: LocalStorage
Thread 15:
0   libsystem_kernel.dylib          0x3a42af38 __psynch_cvwait + 24
1   libsystem_pthread.dylib         0x3a493224 _pthread_cond_wait + 536
2   libsystem_pthread.dylib         0x3a494000 pthread_cond_wait + 36
3   JavaScriptCore                  0x30656e82 
WTF::ThreadCondition::timedWait(WTF::Mutex&, double) + 58
4   WebCore                         0x379473a8 WTF::PassOwnPtr<WTF::Function<void ()> >   
WTF::MessageQueue<WTF::Function<void ()> >::waitForMessageFilteredWithTimeout<bool  
(WTF::Function<void ()>*)>(WTF::MessageQueueWaitResult&, bool (&)(WTF::Function<void   
()>*), double) + 104
5   WebCore                         0x3794732e   
WebCore::StorageThread::threadEntryPoint() + 162
6   JavaScriptCore                  0x306543a0 WTF::wtfThreadEntryPoint(void*) + 12
7   libsystem_pthread.dylib         0x3a493c1a _pthread_body + 138
8   libsystem_pthread.dylib         0x3a493b8a _pthread_start + 98
9   libsystem_pthread.dylib         0x3a491c8c thread_start + 4

Thread 16 name:  WebCore: LocalStorage
Thread 16:
0   libsystem_kernel.dylib          0x3a42af38 __psynch_cvwait + 24
1   libsystem_pthread.dylib         0x3a493224 _pthread_cond_wait + 536
2   libsystem_pthread.dylib         0x3a494000 pthread_cond_wait + 36
3   JavaScriptCore                  0x30656e82  
WTF::ThreadCondition::timedWait(WTF::Mutex&, double) + 58
4   WebCore                         0x379473a8 WTF::PassOwnPtr<WTF::Function<void ()> >    
WTF::MessageQueue<WTF::Function<void ()> >::waitForMessageFilteredWithTimeout<bool  
(WTF::Function<void ()>*)>(WTF::MessageQueueWaitResult&, bool (&)(WTF::Function<void  
()>*), double) + 104
5   WebCore                         0x3794732e  
WebCore::StorageThread::threadEntryPoint() + 162
6   JavaScriptCore                  0x306543a0 WTF::wtfThreadEntryPoint(void*) + 12
7   libsystem_pthread.dylib         0x3a493c1a _pthread_body + 138`enter code here`
8   libsystem_pthread.dylib         0x3a493b8a _pthread_start + 98
9   libsystem_pthread.dylib         0x3a491c8c thread_start + 4

Thread 4 crashed with ARM Thread State (32-bit):
r0: 0x00000000    r1: 0x7e190594      r2: 0x155bc514      r3: 0x00000001
r4: 0x3bfa51ec    r5: 0x0275793c      r6: 0x00000000      r7: 0x028ee074
r8: 0x155bc568    r9: 0x03002c80     r10: 0x028ee128     r11: 0x155bc510
ip: 0x3bee191c    sp: 0x028ee034      lr: 0x37814015      pc: 0x2f62e894
cpsr: 0x60000030

任何见解都将非常有帮助。谢谢!


可能有越狱iOS的方法:D 真的向Hammer开发者求助。 - jmp
2个回答

0

从崩溃日志:

Triggered by Thread:  4

...

Thread 4 name:  WebThread
Thread 4 Crashed:
0   CoreFoundation                  0x2f62e894 CFRelease + 1132
1   WebCore                         0x37814010 WebCore::stopSharedTimer() + 28
2   WebCore                         0x37a58150 WebCore::DeferrableOneShotTimer<WebCore::CachedResource>::fired() + 40

看起来CFRelease失败了,可能是由于释放了已经被释放的东西(尽管CFRelease的偏移量看起来很高)。无论如何,这真的是WebKit中的一个bug。您尝试过更新到较新版本的iOS吗?

此外,我注意到在您的代码示例中,您正在取消绑定“click”,但没有取消绑定“tap”。不确定这是否是有意为之(可能只是复制粘贴问题,因为我还注意到您将“tap”附加到handleStartClicked,但您粘贴的函数是onStartClicked)。


0

我在移动版Safari和HammerJS中遇到了类似的问题,使用localStorage导致了随机崩溃。我仍然不确定为什么会发生这种情况,但是一旦我们将localstorage抽象到其他地方并使用eventemitter与hammerjs监听器一起使用,它就可以正常工作了。

Hammer(this.startButton).on('press tap', function(){
    that.emit('handleClickStart', this.sfs);
}

Controller.prototype.__proto__ = EventEmitter2.prototype; 

Controller.prototype.handleClickStart = function(sfs){
    if (!credential) return;

    storageLib.set('credentials', credentials);

    sfs.connect();
};

var storageLib = {
    localStorage: localStorage,
    set: function(key, val) {
        if(val instanceof Object) val = JSON.stringify(val);
        this.localStorage.setItem(key, val);
        return this.isSet(key);
    },
    isSet: function(key){
        var item = this.localStorage.getItem(key);
        if(item) return true;
        else return false;
    }
};

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接