Browse Source

Fixed a bug limiting the extent of removeRange in ReferenceCountedArray

tags/2021-05-28
Tom Poole 7 years ago
parent
commit
bd211ce7df
3 changed files with 8 additions and 6 deletions
  1. +3
    -2
      modules/juce_core/containers/juce_Array.h
  2. +1
    -1
      modules/juce_core/containers/juce_OwnedArray.h
  3. +4
    -3
      modules/juce_core/containers/juce_ReferenceCountedArray.h

+ 3
- 2
modules/juce_core/containers/juce_Array.h View File

@@ -871,10 +871,11 @@ public:
auto endIndex = jlimit (0, values.size(), startIndex + numberToRemove);
startIndex = jlimit (0, values.size(), startIndex);
numberToRemove = endIndex - startIndex;
if (endIndex > startIndex)
if (numberToRemove > 0)
{
values.removeElements (startIndex, endIndex - startIndex);
values.removeElements (startIndex, numberToRemove);
minimiseStorageAfterRemoval();
}
}


+ 1
- 1
modules/juce_core/containers/juce_OwnedArray.h View File

@@ -606,7 +606,7 @@ public:
startIndex = jlimit (0, values.size(), startIndex);
numberToRemove = endIndex - startIndex;
if (endIndex > startIndex)
if (numberToRemove > 0)
{
if (deleteObjects)
{


+ 4
- 3
modules/juce_core/containers/juce_ReferenceCountedArray.h View File

@@ -650,12 +650,13 @@ public:
int numberToRemove)
{
const ScopedLockType lock (getLock());
auto start = jlimit (0, values.size(), startIndex);
startIndex = jlimit (0, values.size(), startIndex);
auto endIndex = jlimit (0, values.size(), startIndex + numberToRemove);
numberToRemove = endIndex - startIndex;
if (endIndex > start)
if (numberToRemove > 0)
{
for (int i = start; i < endIndex; ++i)
for (int i = startIndex; i < endIndex; ++i)
{
releaseObject (values[i]);
values[i] = nullptr; // (in case one of the destructors accesses this array and hits a dangling pointer)


Loading…
Cancel
Save