# Bug in juce\_DrawableButton.cpp

**URL:** <https://forum.juce.com/t/bug-in-juce-drawablebutton-cpp/13812>\
**Category:** Audio Plugins\
**Created:** [November 4, 2014, 5:15pm UTC](https://forum.juce.com/t/bug-in-juce-drawablebutton-cpp/13812 "2014-11-04T17:15:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RiphRaph](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@RiphRaph](https://forum.juce.com/u/RiphRaph)\
**Post date:** [November 4, 2014, 5:15pm UTC](https://forum.juce.com/t/bug-in-juce-drawablebutton-cpp/13812/1 "2014-11-04T17:15:20Z")

</div>

In juce\_DrawableButton.cpp, setImages() calls copyDrawableIfNotNull for each Drawable pointer.

However the size of the Drawable&nbsp;component is not copied to the Drawable member pointer.

This leads to Drawable components with a zero size. As the result the button can disappear when turned on...

&nbsp;

I modified copyDrawableIfNotNull&nbsp; to copy the size of the drawable component into the new one and it fixes the problem :

static Drawable\* copyDrawableIfNotNull (const Drawable\* const d)  
{

&nbsp;&nbsp;&nbsp; // old code  
&nbsp;&nbsp; &nbsp;//return d != nullptr ? d-\>createCopy() : nullptr;

&nbsp;

&nbsp;&nbsp; // new code

&nbsp;&nbsp;&nbsp; Drawable\* pDrawable = nullptr;  
&nbsp;&nbsp; &nbsp;  
&nbsp;&nbsp; &nbsp;if(d != nullptr)  
&nbsp;&nbsp; &nbsp;{  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;pDrawable = d-\>createCopy();  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;pDrawable-\>setBounds(d-\>getBounds());  
&nbsp;&nbsp; &nbsp;}

&nbsp;&nbsp; &nbsp;return pDrawable;

}

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 4, 2014, 5:26pm UTC](https://forum.juce.com/t/bug-in-juce-drawablebutton-cpp/13812/2 "2014-11-04T17:26:33Z")

</div>

Ok, but I think you're fixing the wrong thing there. If a createCopy method is returning a new Drawable which isn't correct, then that would need to be fixed, it's not the responsibility of&nbsp;copyDrawableIfNotNull to fix it. If you let me know which Drawable subclass is the problem, I'll take a look..

---

<div class="post-metadata">

**Author:** ![RiphRaph](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@RiphRaph](https://forum.juce.com/u/RiphRaph)\
**Post date:** [November 5, 2014, 10:01am UTC](https://forum.juce.com/t/bug-in-juce-drawablebutton-cpp/13812/3 "2014-11-05T10:01:12Z")

</div>

Yes you're right.

It's the DrawableImage subclass.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 5, 2014, 10:32am UTC](https://forum.juce.com/t/bug-in-juce-drawablebutton-cpp/13812/4 "2014-11-05T10:32:35Z")

</div>

Ok, try it now.

---

<div class="post-metadata">

**Author:** ![RiphRaph](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@RiphRaph](https://forum.juce.com/u/RiphRaph)\
**Post date:** [November 5, 2014, 11:05am UTC](https://forum.juce.com/t/bug-in-juce-drawablebutton-cpp/13812/5 "2014-11-05T11:05:17Z")

</div>

Ok. It works
