refreshComponentForCell custom component bug


#1

Hello Jules & all,

 

Long time juce guy, first time forum poster ;).  Apologies if this has already been reported but I don't think so and it would be good for me to have it confirmed.

I'm having an issue when trying to put a custom component into a table.  The refreshComponentForCell call is returning existingComponentToUpdate components for rows that don't have one, and returning a NULL existingComponentToUpdate for rows that do.  This is on both the official release and the git latest.

Easy to reproduce in the demo:

In the TableDemoComponent in WidgetsDemo.cpp, just do something like rowNumber%3 == 0 in the call to give the custom component to every third row instead of every row.  Then in the demo, start resizing and scrolling and the assertion will hit rather quickly, either in the refreshComponentForCell or because of leaked objects (since they keep getting created since the function reports that existingComponent to update is NULL).

 

i.e.

    Component* refreshComponentForCell (int rowNumber, int columnId, bool /*isRowSelected*/,

                                        Component* existingComponentToUpdate) override

    {

        if ( rowNumber%3 == 0 && columnId == 5) // If it's the ratings column, we'll return our custom component..

        {

...

 

Hope that's enough to go on.. I haven't gone about trying to fix it myself, but that'd be the next thing unless there's a fix underway or if I'm doing something wrong of course ;).

 

Thanks!

Steve


#2

If the only change you made to the code is what's shown above, then the method wouldn't be doing its job properly. The method is responsible for deleting any custom components that aren't needed, so in the cells where you don't want one, you'd need to make sure it deletes the object that's passed in instead of the assertion. The whole reason the assertion is there is because this code never expects to have to deal with that situation, because it always returns a component.