我正在使用Javascript for iPad进行多人游戏。我在多人游戏中使用Smartfox Server,在触摸事件中使用Hammer.js。
我遇到的问题是,当我在游戏的某个特定部分使用Hammer事件时,它会导致Mobile 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();
}
如果单击开始按钮,Mobile Safari会在大约80%的时间内崩溃。即使它没有立即在该点击上崩溃,它通常会在游戏后期的某个时刻崩溃。但是,如果我从不点击开始按钮(例如,如果我只是在没有触摸交互的情况下自动启动用户),则崩溃永远不会发生 - 甚至在游戏的后期点也不会发生。我甚至试图完全删除开始按钮,只是将触摸监听器添加到整个文档正文,它仍然崩溃,所以它似乎与按钮没有任何关系(它只是一个普通的HTML按钮包裹在一个jQuery对象)。
奇怪的是,如果我将Hammer.js事件更改为常规jQuery事件:
this.startButton.bind("click", this.onStartClickBind);
移动Safari永远不会崩溃。不是在开始点击...不是在游戏中的任何一点。它似乎解决了一切。另一个奇怪的事情是我在我的代码的其余部分使用Hammer事件,但它似乎是一个问题的唯一地方就是这个处理程序。我不知道游戏中这个处理程序与其他处理程序有什么不同,除非崩溃与Mobile 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
任何见解都会非常有帮助。谢谢!
答案 0 :(得分: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中的一个错误。您是否尝试过更新到更高版本的iOS?
另外,我在您的代码示例中注意到您要解除&#34;点击&#34;但不是来自&#34; tap&#34;。不确定这是否是故意的(可能只是一个复制粘贴问题,因为我也注意到你附加了#34;点击&#34;到handleStartClicked
,但你粘贴的功能是onStartClicked
。
答案 1 :(得分: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;
}
};