func (m *mainLoop) loop(init chan<- struct{}) { runtime.LockOSThread() defer runtime.UnlockOSThread() looper := C.ALooper_prepare(C.ALOOPER_PREPARE_ALLOW_NON_CALLBACKS) if looper == nil { panic("ALooper_prepare returned nil") } m.looper = looper init <- struct{}{} for { select { case <-m.quit: if m.renderState != nil && m.renderState.ctx != egl.Context(unsafe.Pointer(nil)) { if !egl.MakeCurrent(m.renderState.disp, egl.Surface(unsafe.Pointer(nil)), egl.Surface(unsafe.Pointer(nil)), egl.Context(unsafe.Pointer(nil))) { panic("Error: eglMakeCurrent() failed\n") } } m.ack <- struct{}{} break case <-m.resume: m.running = true m.ack <- struct{}{} case <-m.pause: m.running = false m.width, m.height = 0, 0 m.ack <- struct{}{} case m.focused = <-m.focus: m.width, m.height = 0, 0 m.ack <- struct{}{} case m.renderState = <-m.render: m.ack <- struct{}{} case inputQ := <-m.input: if inputQ != nil { C.AInputQueue_attachLooper(inputQ, m.looper, LOOPER_ID_INPUT, nil, nil) } else { C.AInputQueue_detachLooper(m.inputQ) } m.inputQ = inputQ m.ack <- struct{}{} default: m.frame() } } }
//export onNativeWindowDestroyed func onNativeWindowDestroyed(act *C.ANativeActivity, win unsafe.Pointer) { defer func() { handleCallbackError(act, recover()) }() log.Printf("onWindowDestroy...\n") state := states[act] state.mLoop.UpdateRenderState(nil) egl.DestroySurface(state.renderState.disp, state.renderState.surf) state.renderState.surf = egl.Surface(unsafe.Pointer(nil)) log.Printf("onWindowDestroy done\n") }