The JUCE 8 Preview branch is available now!

Regarding the Image::clear problem, it looks like I forgot a part of my response: it is partially fixed as calling clear() now does clear the image properly, but setting the constructor flag does not.

Here is a small example demonstrating the porblem, following the same structure as the one provided today in another report here.

class TestComponent : public juce::Component {
public:
	TestComponent() {}

	void paint(juce::Graphics& g) override {
		g.fillAll(juce::Colours::white);

		auto bounds = getLocalBounds();
		auto removedIntTestBounds = bounds.removeFromTop(60);
		auto removedFloatTestBounds = bounds.removeFromTop(60);
		auto imageTestBounds = bounds.removeFromTop(60);

		{ // removeFrom int Rectangle
			auto b = removedIntTestBounds;

			g.setColour(juce::Colours::black.withAlpha(.8f));
			while (!b.isEmpty())
				g.fillRect(b.removeFromLeft(100));

			g.setColour(juce::Colours::red);
			g.drawText("removeFrom int Rectangle: seams between rectangles when != 100% for all renderers", removedIntTestBounds, juce::Justification::centred);
		}

		{ // removeFrom float Rectangle
			auto b = removedFloatTestBounds.toFloat();

			g.setColour(juce::Colours::black.withAlpha(.8f));
			while (!b.isEmpty())
				g.fillRect(b.removeFromLeft(100.f));

			g.setColour(juce::Colours::red);
			g.drawText("removeFrom float Rectangle: seams between rectangles when != 100% for all renderers", removedFloatTestBounds, juce::Justification::centred);
		}

		{ // image

			//auto type = juce::SoftwareImageType(); // ok
			auto type = juce::NativeImageType(); // nok
			juce::Image img{ juce::Image::ARGB, imageTestBounds.getWidth(), imageTestBounds.getHeight(), true, type};

			// if we call clear the problem goes away:
			//img.clear({ 0,0,img.getWidth(), img.getHeight() });

			{
				juce::Image::BitmapData destData{ img, juce::Image::BitmapData::writeOnly };

				for (int y = 0; y < img.getHeight(); ++y) {
					for (int x = 0; x < img.getWidth(); ++x) {
						if (x % 20 == y % 20) destData.setPixelColour(x, y, juce::Colours::black);
					}
				}
			}

			g.drawImageAt(img, imageTestBounds.getX(), imageTestBounds.getY());

			g.setColour(juce::Colours::red);
			g.drawText("junk in NativeImageType image when not clear manually", imageTestBounds, juce::Justification::centred);

		}
	}

private:

	JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TestComponent)
};

class MainComponent  : public juce::Component {
public:
	MainComponent() {

		//juce::Timer::callAfterDelay(0, [this] {
		//	auto* peer = getPeer();
		//	jassert(peer);
		//	if (peer) peer->setCurrentRenderingEngine(0);
		//});

		setSize(referenceWidth, referenceWidth);
		addAndMakeVisible(component);
		addAndMakeVisible(zoomLabel);
		refreshZoomLabel();
	}

	void paint(juce::Graphics& g) override {
		g.fillAll(juce::Colours::black);
	}

	void resized() override {
		refreshZoomLabel();
		zoomLabel.setBounds(getLocalBounds().removeFromTop(30));
		component.setBounds(0, 0, referenceWidth, referenceWidth);
		component.setTransform(juce::AffineTransform::scale(getScale()).followedBy(juce::AffineTransform::translation(0,30)));
	}

private:
	void refreshZoomLabel() {
		zoomLabel.setText("zoom: " + juce::String(juce::roundToInt(100 * getScale())) + "%", juce::dontSendNotification);
	}

	float getScale() {
		return (float)getWidth() / referenceWidth;
	}

	juce::Label zoomLabel;
	TestComponent component;

	int referenceWidth = 600;

	JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)
};

I also included the “removeFrom” example which is most probably related to the aforementioned issue I reported today, just because it looks like having other things happening in the windows “help” making the junk appear in the image (I get more junk in a real project, because more GPU memory is reused).

→ Please only consider the hatch image at the bottom for this particular issue

So, the junk seem to appear randomly when repainting/resizing the window.

  • It does go away when using the software image type of when calling clear.
  • It is present with all renderers (I use another component to switch between renderers, but I guess you already have that)

So here is what is is supposed to look like (100% so solve the removeFrom issue, and software image type to solve the image one).
image ok

And what it looks like when playing with it a bit (and using native image type):
image nok