juce中的BailOutChecker
生活随笔
收集整理的這篇文章主要介紹了
juce中的BailOutChecker
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
界面庫中值得注意的一點就是對象響應事件的時候自身被刪除了,那么后續的訪問自然就會出問題,所以需要在響應事件之后先添加引用,相關處理之后再查看自身是否已經被刪除,如果已經被刪除那么就直接退出。juce中通過BailOutChecker來進行這處檢查,內部實現很簡單也就是通過弱引用來進行,關于弱引用請看上一篇文章
//==============================================================================/** A class to keep an eye on a component and check for it being deleted.This is designed for use with the ListenerList::callChecked() methods, to allowthe list iterator to stop cleanly if the component is deleted by a listener callbackwhile the list is still being iterated.*/class JUCE_API BailOutChecker{public:/** Creates a checker that watches one component. */BailOutChecker (Component* component);/** Returns true if either of the two components have been deleted since this object was created. */bool shouldBailOut() const noexcept;private:const WeakReference<Component> safePointer;JUCE_DECLARE_NON_COPYABLE (BailOutChecker)};紅色部份標識了進行檢查的部份:
void Component::internalMouseWheel (MouseInputSource source, Point<float> relativePos,Time time, const MouseWheelDetails& wheel) {Desktop& desktop = Desktop::getInstance(); BailOutChecker checker (this);const MouseEvent me (source, relativePos, source.getCurrentModifiers(), MouseInputSource::invalidPressure,this, this, time, relativePos, time, 0, false);if (isCurrentlyBlockedByAnotherModalComponent()){// allow blocked mouse-events to go to global listeners..desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheel);}else{mouseWheelMove (me, wheel); if (checker.shouldBailOut())return;//歷遍的過程中同樣需要檢查desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheel);if (! checker.shouldBailOut())MouseListenerList::sendWheelEvent (*this, checker, me, wheel);} }
轉載于:https://www.cnblogs.com/csxy/p/5472362.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的juce中的BailOutChecker的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么修改android内存,安卓内存修改
- 下一篇: dubbo 整合 zipkin,最简单的