damiensellier / CtrlrX

CtlrX is an alternative fork of Roman Kubiak's Ctrlr. This project is ONLY aimed at delivering updates, a wiki, documentations, tutorials or anything that the community cannot share on the original Ctrlr github due to credential restrictions.
BSD 3-Clause "New" or "Revised" License
16 stars 3 forks source link

CtrlrDocumentPanel::activeDocumentChanged() throws error on findColour(): Workaround: add IF for colourID == 16799763/5 #11

Open unityconstruct opened 4 months ago

unityconstruct commented 4 months ago

Running in debug mode and found the exceptions thrown for those two colors a nuisance, so added IF statement for the colourIDs specifically. Ultimate fix might be choosing a colour from the JUCE color list... I think they are HTML(websafe) colours. Might be able to just add them to the JUCE h file, but I didn't want to go mucking around in a bunch of places and diverge off your [master] branch.

Workaround

    if (index >= 0)
        return colours[index].colour;
    **if (colourID == 16799763 || colourID == 16799765)
        return Colours::black;**

    jassertfalse;
    return Colours::black;

Steps to Reproduce

  1. Start in Debug
  2. File>New Panel
// CtrlrManager::addPanel
void CtrlrManager::addPanel (CtrlrPanelEditor *panelToAdd)
{
    ctrlrDocumentPanel->addDocument ((Component *)panelToAdd, Colours::lightgrey, true);
}

// memory
    _NODISCARD pointer operator->() const noexcept {
        return _Mypair._Myval2;
    }

image

//juce_MultiDocumentPanel.cpp

bool MultiDocumentPanel::addDocument (Component* const component,
                                      Colour docColour,
                                      const bool deleteWhenRemoved)
{
    // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
    // with a frame-within-a-frame! Just pass in the bare content component.
    jassert (dynamic_cast<ResizableWindow*> (component) == nullptr);

    if (component == nullptr || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
        return false;

    components.add (component);
    component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
    component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());

// Autos: 
// juce::Colour::getARGB returned | 4292072403 | unsigned int

// CtrlrDocumentPanel::activeDocumentChanged
void CtrlrDocumentPanel::activeDocumentChanged()
{
    CtrlrEditor *ed = dynamic_cast <CtrlrEditor*> (getParentComponent());
    if (ed)
    {
        ed->activeCtrlrChanged();
        setBackgroundColour(Component::findColour(DocumentWindow::backgroundColourId));
    }
    if (getCurrentTabbedComponent()) {
        getCurrentTabbedComponent()->setTabBarDepth(owner.getProperty(Ids::ctrlrTabBarDepth));
        getCurrentTabbedComponent()->getTabbedButtonBar().setColour(TabbedButtonBar::tabTextColourId, **findColour(TabbedButtonBar::tabTextColourId)); // Not working
        getCurrentTabbedComponent()->getTabbedButtonBar().setColour(TabbedButtonBar::frontTextColourId, findColour(TabbedButtonBar::frontTextColourId)); // Not working**
    }
    setBackgroundColour(Colours::lightgrey); // Sets background colour behind main window by default on grey to please everyone :)
}

//Colour LookAndFeel::findColour 
Colour LookAndFeel::findColour (int colourID) const noexcept
{
    const ColourSetting c = { colourID, Colour() };
    auto index = colours.indexOf (c);

    if (index >= 0)
        return colours[index].colour;
    **if (colourID == 16799763 || colourID == 16799765)
        return Colours::black;**

    jassertfalse;
    return Colours::black;
}
damiensellier commented 1 month ago

Hi UC,

i have some trouble understanding what's the problem. how did you manage to get those colour index 16799763 & 16799765 errors ? Is it docColour having a problem in the declaration? https://docs.juce.com/master/classMultiDocumentPanel.html#a92a4b424c5d8eee7fb859e5a2e71bdad

backgroundColour the background colour to use to fill the component's window or tab

What is the result on the GUI? wrong colours? the app crashes?

It's always better to avoid injecting the workaround statement in the JUCE core module juce_lookandfeel.cpp. I'll try to find a way to implement that in the ctrlr files instead if I understand exactly what is going wrong with those colours.

Thanks

Damien

unityconstruct commented 1 month ago
unityconstruct commented 1 month ago

OK dusted off my VS box... (used the proteus panel in case there was something specific to the panel I'm working on.)

CtrlrX UI

Test Panel

Emu-Proteus-2_1_0.zip

System Specs

image

unityconstruct commented 1 month ago

Context on the logic in the method

damiensellier commented 1 month ago

Thanks for all the details, I'm not home for a while but I'll check the process once back.