Juce 7.0.5 juce::PixelRGB::set crashes randomly

I dont know the reason and root of the problem. The problem does not always repeat, but I encounter it randomly. What could be the problem? Did I corrupt the GDI, or is it related to the stack/heap?"

|>|juce::PixelRGB::set<juce::PixelARGB>(const juce::PixelARGB & src) Line 432|C++|
|---|---|---|
| |juce::RenderingHelpers::EdgeTableFillers::SolidColour<juce::PixelRGB,0>::replaceLine(juce::PixelRGB * dest, juce::PixelARGB colour, int width) Line 678|C++|
| |juce::RenderingHelpers::EdgeTableFillers::SolidColour<juce::PixelRGB,0>::handleEdgeTableRectangle(int x, int y, int width, int height, int alphaLevel) Line 639|C++|
| |juce::RenderingHelpers::EdgeTableFillers::SolidColour<juce::PixelRGB,0>::handleEdgeTableRectangleFull(int x, int y, int width, int height) Line 655|C++|
| |juce::RenderingHelpers::ClipRegions<juce::RenderingHelpers::SoftwareRendererSavedState>::RectangleListRegion::SubRectangleIterator::iterate<juce::RenderingHelpers::EdgeTableFillers::SolidColour<juce::PixelRGB,0>>(juce::RenderingHelpers::EdgeTableFillers::SolidColour<juce::PixelRGB,0> & r) Line 1922|C++|
| |juce::RenderingHelpers::EdgeTableFillers::renderSolidFill<juce::RenderingHelpers::ClipRegions<juce::RenderingHelpers::SoftwareRendererSavedState>::RectangleListRegion::SubRectangleIterator,juce::PixelRGB>(juce::RenderingHelpers::ClipRegions<juce::RenderingHelpers::SoftwareRendererSavedState>::RectangleListRegion::SubRectangleIterator & iter, const juce::Image::BitmapData & destData, juce::PixelARGB fillColour, bool replaceContents, juce::PixelRGB * __formal) Line 1562|C++|
| |juce::RenderingHelpers::SoftwareRendererSavedState::fillWithSolidColour<juce::RenderingHelpers::ClipRegions<juce::RenderingHelpers::SoftwareRendererSavedState>::RectangleListRegion::SubRectangleIterator>(juce::RenderingHelpers::ClipRegions<juce::RenderingHelpers::SoftwareRendererSavedState>::RectangleListRegion::SubRectangleIterator & iter, juce::PixelARGB colour, bool replaceContents) Line 2605|C++|
| |juce::RenderingHelpers::ClipRegions<juce::RenderingHelpers::SoftwareRendererSavedState>::RectangleListRegion::fillRectWithColour(juce::RenderingHelpers::SoftwareRendererSavedState & state, juce::Rectangle<int> area, juce::PixelARGB colour, bool replaceContents) Line 1855|C++|
| |juce::RenderingHelpers::SavedStateBase<juce::RenderingHelpers::SoftwareRendererSavedState>::fillTargetRect(juce::Rectangle<int> r, bool replaceContents) Line 2227|C++|
| |juce::RenderingHelpers::SavedStateBase<juce::RenderingHelpers::SoftwareRendererSavedState>::fillRect(juce::Rectangle<int> r, bool replaceContents) Line 2268|C++|
| |juce::RenderingHelpers::StackBasedLowLevelGraphicsContext<juce::RenderingHelpers::SoftwareRendererSavedState>::fillRect(const juce::Rectangle<int> & r, bool replace) Line 2720|C++|
| |juce::LowLevelGraphicsContext::fillAll() Line 89|C++|
| |juce::Graphics::fillAll(juce::Colour colourToUse) Line 552|C++|
| |juce::LookAndFeel_V2::fillResizableWindowBackground(juce::Graphics & g, int __formal, int __formal, const juce::BorderSize<int> & __formal, juce::ResizableWindow & window) Line 1865|C++|
| |juce::ResizableWindow::paint(juce::Graphics & g) Line 366|C++|
| |juce::DocumentWindow::paint(juce::Graphics & g) Line 191|C++|
| |juce::Component::paintComponentAndChildren(juce::Graphics & g) Line 2010|C++|
| |juce::Component::paintEntireComponent(juce::Graphics & g, bool ignoreAlphaLevel) Line 2111|C++|
| |juce::ComponentPeer::handlePaint(juce::LowLevelGraphicsContext & contextToPaintTo) Line 161|C++|
| |juce::HWNDComponentPeer::performPaint(HDC__ * dc, HRGN__ * rgn, int regionType, tagPAINTSTRUCT & paintStruct) Line 2946|C++|
| |juce::HWNDComponentPeer::handlePaintMessage() Line 2840|C++|
| |juce::HWNDComponentPeer::peerWindowProc(HWND__ * h, unsigned int message, unsigned int wParam, long lParam) Line 4005|C++|
| |juce::HWNDComponentPeer::windowProc(HWND__ * h, unsigned int message, unsigned int wParam, long lParam) Line 3940|C++|
| |[External Code]||
| |[Frames below may be incorrect and/or missing, no symbols loaded for user32.dll]||
| |juce::Component::setVisible(bool shouldBeVisible) Line 597|C++|
| |juce::Component::enterModalState(bool shouldTakeKeyboardFocus, juce::ModalComponentManager::Callback * callback, bool deleteWhenDismissed) Line 1774|C++|
| |juce::Component::runModalLoop() Line 1741|C++|
| |TOG::ComboComp::showPopup() Line 612|C++|
| |TOG::ComboComp::mouseDown(const juce::MouseEvent & e) Line 653|C++|
| |<lambda_07a134d247ffd4fe40128bb20a114eb9>::operator()<juce::Component,<lambda_d8c7b897c67fe267ec01e5b1dca0b4a7>>(juce::Component & parentComp, const juce::Component::MouseListenerList::sendMouseEvent::__l5::<lambda_d8c7b897c67fe267ec01e5b1dca0b4a7> findNumListeners) Line 134|C++|
| |juce::Component::MouseListenerList::sendMouseEvent<void (__thiscall juce::MouseListener::*)(juce::MouseEvent const &)>(juce::HierarchyChecker & checker, void(juce::MouseListener::*)(const juce::MouseEvent &) && eventMethod) Line 145|C++|
| |juce::Component::internalMouseDown(juce::MouseInputSource source, const juce::PointerState & relativePointerState, juce::Time time) Line 2531|C++|
| |juce::MouseInputSourceInternal::sendMouseDown(juce::Component & comp, const juce::PointerState & pointerState, juce::Time time) Line 127|C++|
| |juce::MouseInputSourceInternal::setButtons(const juce::PointerState & pointerState, juce::Time time, juce::ModifierKeys newButtonState) Line 208|C++|
| |juce::MouseInputSourceInternal::handleEvent(juce::ComponentPeer & newPeer, juce::Point<float> positionWithinPeer, juce::Time time, const juce::ModifierKeys newMods, float newPressure, float newOrientation, juce::PenDetails pen) Line 313|C++|
| |juce::MouseInputSource::handleEvent(juce::ComponentPeer & peer, juce::Point<float> pos, __int64 time, juce::ModifierKeys mods, float pressure, float orientation, const juce::PenDetails & penDetails) Line 611|C++|
| |juce::ComponentPeer::handleMouseEvent(juce::MouseInputSource::InputSourceType type, juce::Point<float> pos, juce::ModifierKeys newMods, float newPressure, float newOrientation, __int64 time, juce::PenDetails pen, int touchIndex) Line 90|C++|
| |juce::HWNDComponentPeer::doMouseEvent(juce::Point<float> position, float pressure, float orientation, juce::ModifierKeys mods) Line 2961|C++|
| |juce::HWNDComponentPeer::doMouseDown(juce::Point<float> position, const unsigned int wParam) Line 3110|C++|
| |juce::HWNDComponentPeer::peerWindowProc(HWND__ * h, unsigned int message, unsigned int wParam, long lParam) Line 4041|C++|
| |juce::HWNDComponentPeer::windowProc(HWND__ * h, unsigned int message, unsigned int wParam, long lParam) Line 3940|C++|
| |[External Code]||
| |juce::InternalMessageQueue::dispatchNextMessage(bool returnIfNoPendingMessages) Line 145|C++|
| |juce::dispatchNextMessageOnSystemQueue(bool returnIfNoPendingMessages) Line 266|C++|
| |juce::MessageManager::runDispatchLoop() Line 109|C++|
| |juce::JUCEApplicationBase::main() Line 269|C++|
| |WinMain(HINSTANCE__ * __formal, HINSTANCE__ * __formal, char * __formal, int __formal) Line 285|C++|
| |[External Code]||

we see this in JUCE 6.1.4 in multiple products. Probably the same.

Fatal Error: EXCEPTION_ACCESS_VIOLATION_WRITE / 0x76200

Thread 2068 Crashed:
0  juce::RenderingHelpers::EdgeTableFillers::SolidColour<T>::handleEdgeTableRectangle
1  juce::RenderingHelpers::EdgeTableFillers::renderSolidFill<T>
2  juce::RenderingHelpers::ClipRegions<T>::RectangleListRegion::fillRectWithColour
3  juce::RenderingHelpers::SavedStateBase<T>::fillTargetRect
4  juce::RenderingHelpers::StackBasedLowLevelGraphicsContext<T>::fillRect
5  juce::Graphics::fillAll
6  juce::LookAndFeel_V2::fillResizableWindowBackground
7  juce::DocumentWindow::paint
8  juce::Component::paintComponentAndChildren
9  juce::Component::paintEntireComponent
10 juce::HWNDComponentPeer::performPaint
11 juce::HWNDComponentPeer::handlePaintMessage
12 juce::HWNDComponentPeer::peerWindowProc
13 juce::HWNDComponentPeer::windowProc

Can you try making this change to your juce codebase and see if it fixes the crash:

I can cause the crash by drawing a rect so big that the math that calculates the intersection overflows and gives nonsense results.

I found a few places in my code where I cause this but drawing a really big rect at extreme zooms. But I’m also seeing it in fillAll. I’m not sure how the clipping rect gets calculated, but maybe there is some case where it’s too big for some reason, and then it crashes.