Juce - setLookAndFeel - 错误

时间:2017-12-16 13:17:09

标签: xcode slider juce

我使用Projucer(Juce v5.2.0)和xCode 9.2,当我在Slider上使用setLookAndFeel时,我有一些奇怪的错误。

我一步一步地学习该教程: https://www.youtube.com/watch?v=po46y8UKPOY&t=1020s

我制作完全相同的代码。在视频上没有问题。当我在电影的17:13持续时间内编译相同的代码时,会出现我的错误。

我的问题是:当我编译代码时,一切正常,我编译的应用程序运行良好," setLookAndFeel"按预期工作。但问题是当我关闭app时。然后app看起来像关闭,但图标在停靠栏上,xCode显示"停止"按钮处于活动状态,所以看起来我的应用仍然以某种方式工作。而xCode会自动将我带到一个名为" Juce Massage Thread(1)"并且有错误: Juce Message Thread (1): EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0

该代码旁边是:

jassert (masterReference.getNumActiveWeakReferences() == 0
          || (masterReference.getNumActiveWeakReferences() == 1
               && this == &getDefaultLookAndFeel()));

有人能帮帮我吗? 提前谢谢。

1 个答案:

答案 0 :(得分:0)

在断言之上有一个很大的评论块,你已经解释了为什么你会发现它:

/* This assertion is triggered if you try to delete a LookAndFeel object while something
   is still using it!

   Reasons may be:
     - it's still being used as the default LookAndFeel; or
     - it's set as a Component's current lookandfeel; or
     - there's a WeakReference to it somewhere else in your code

   Generally the fix for this will be to make sure you call
   Component::setLookandFeel (nullptr) on any components that were still using
   it before you delete it, or call LookAndFeel::setDefaultLookAndFeel (nullptr)
   if you had set it up to be the default one. This assertion can also be avoided by
   declaring your LookAndFeel object before any of the Components that use it as
   the LookAndFeel will be destroyed before the Components.

   Deleting a LookAndFeel is unlikely to cause a crash since most things will use a
   safe WeakReference to it, but it could cause some unexpected graphical behaviour,
   so it's advisable to clear up any references before destroying them!
*/

因此,您需要在删除滑块之前调用setLookAndFeel (nullptr),可能在其父组件的析构函数中。