界面库中值得注意的一点就是对象响应事件的时候自身被删除了,那么后续的访问自然就会出问题,所以需要在响应事件之后先添加引用,相关处理之后再查看自身是否已经被删除,如果已经被删除那么就直接退出。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 allow
the list iterator to stop cleanly if the component is deleted by a listener callback
while 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);
}
}

  

juce中的BailOutChecker的更多相关文章

  1. juce 中的WeakReference分析

    juce中的WeakReference设计得比较巧妙,巧妙就是使用delete之后就可以通知道WeakReference,原理其实也很间单,其实就是在对象里添加了一个子对象masterReferenc ...

  2. juce中的timer

    juce中timer总体说还是比较好用的,使用时只需继承timer类, 重写callback然后调用start就可以了,juce的timer比较特别,自己通过线程实现,starttimer的时候会创建 ...

  3. juce中的引用计数

    这个类提供了最基本的引用计数管理,界面库中,经常都需要消息发送,而带来的后果就是不知道消息中包含的对象是否还存在,如果不能很好管理的话就容易出现访问销毁了的对象这样的情况,所以,juce的界面无素也基 ...

  4. juce中的内存泄漏检测

    非常值得借鉴的做法,基于引用计数和局部静态变量,代码比较简单不加详解. //============================================================== ...

  5. juce中的Singleton

    说明上其实很明白,支持多线程,防止重复创建,同时支持如果删除以后就不在创建,利用局部静态变量进行标记.挺通用,看来下次写个c11版本的 //============================== ...

  6. juce 中的ReferenceCountedObjectPtr

    提供了对引用计数对象的管理,其实也就是操作引用计数对象,当引用计数为零的时候将对象销毁,值得学习的是juce是如果将引用计数对象和它的智能指针结合在一起的,这个后面再加分析 //=========== ...

  7. juce中的CallbackMessage

    这个类作为所有消息的基类,主要是包装了回调函数 virtual void messageCallback() = 0; /* ===================================== ...

  8. 一起学JUCE之HashMap

    基于哈希表的 Map 接口的实现.此实现提供所有可选的映射操作,并允许使用 null 值和 null 键.(除了非同步和允许使用 null 之外,HashMap 类与 Hashtable 大致相同.) ...

  9. Python开源框架

    info:更多Django信息url:https://www.oschina.net/p/djangodetail: Django 是 Python 编程语言驱动的一个开源模型-视图-控制器(MVC) ...

随机推荐

  1. web.xml中的主要元素说明(listener, filter, servlet)

    web.xml中加载的顺序为:context-param ---> listener ---> filter ---> servlet. listener:主要针对的是对象的操作,如 ...

  2. js 打开新页面 window.open()

    利用js打开一个新页面,而不是一个新窗口. 在网上各种东西啊,蛋疼了半天,还白疼了.. 后来看到a标签有target属性,然后又发现window.open()的第二个参数是target,然后我笑了(e ...

  3. 项目 Web 的 NuGet 程序包还原失败: 找不到“1.0.0”版本的程序包“Microsoft.Net.Compilers”。。 0

    项目   Web 的 NuGet 程序包还原失败: 找不到“1.0.0”版本的程序包“Microsoft.Net.Compilers”.. 0 使用vs的NutGet包管理器时,另一台电脑从svn下载 ...

  4. 初学swift笔记 继承(十)

    import Foundation /* 继承 class childClass: FatherClass{ } 优点 代码重用 缺点 增加程序的藕合度 父类的改变会影响子类 只能单继承 */ cla ...

  5. mono 判断系统的网络是否可用

    /**  * 判断系统的网络是否可用  * @return  */        private bool isNetworkConnected()        {            bool ...

  6. Oracle EBS-SQL (QA-1):检查超出检验周期的检验数据.sql

    select msi.segment1                                    物料编码,          msi.DESCRIPTION                ...

  7. Intuit Quicken Home & Business 2016(Manage your business and personal finances)

    Quicken Home & Business 2016 - Manage your business and personal finances all in one place. Cate ...

  8. Ubuntu Mysql开通外网访问权限

    Ubuntu Mysql开通外网访问权限   1.编辑 my.cnf 文件: sudo vi /etc/mysql/my.cnf   2.将绑定地址行注释掉或者修改为指定 IP #bind-addre ...

  9. Chapter 5. Label and Entry Widgets 标签和输入部件

    Chapter 5. Label and Entry Widgets  标签和输入部件 有时候,你需要用户输入特定的信息,比如他们的名字,地址或者 甚至序号. 简单的方式来实现这个是使用Enry 部件 ...

  10. 顶尖大数据挖掘实战平台(TipDM-H8)产品白皮书

        顶尖大数据挖掘实战平台 (TipDM-H8)           产  品  说  明  书 广州泰迪智能科技有限公司 版权所有 地址: 广州市经济技术开发区科学城232号 网址: http: ...