Skip to content

Commit f2e2315

Browse files
Gene WaltersGene Walters
authored andcommitted
Fix a asset prioritization crash fix related to sort function inconistently returning true or false
Signed-off-by: Gene Walters <[email protected]>
1 parent 662f8cd commit f2e2315

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Code/Framework/AzCore/AzCore/IO/Streamer/Scheduler.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,11 @@ namespace AZ::IO
501501

502502
auto Scheduler::Thread_PrioritizeRequests(const FileRequest* first, const FileRequest* second) const -> Order
503503
{
504+
if (first == second)
505+
{
506+
return Order::Equal;
507+
}
508+
504509
// Sort by order priority of the command in the request. This allows to for instance have cancel request
505510
// always happen before any other requests.
506511
auto order = [](auto&& args)
@@ -544,7 +549,7 @@ namespace AZ::IO
544549
}
545550

546551
// If neither has started and have the same priority, prefer to start the closest deadline.
547-
return firstRead->m_deadline <= secondRead->m_deadline ? Order::FirstRequest : Order::SecondRequest;
552+
return firstRead->m_deadline < secondRead->m_deadline ? Order::FirstRequest : Order::SecondRequest;
548553
}
549554

550555
// Check if one of the requests is in panic and prefer to prioritize that request
@@ -593,7 +598,7 @@ namespace AZ::IO
593598
s64 secondReadOffset = AZStd::visit(offset, second->GetCommand());
594599
s64 firstSeekDistance = abs(aznumeric_cast<s64>(m_threadData.m_lastFileOffset) - firstReadOffset);
595600
s64 secondSeekDistance = abs(aznumeric_cast<s64>(m_threadData.m_lastFileOffset) - secondReadOffset);
596-
return firstSeekDistance <= secondSeekDistance ? Order::FirstRequest : Order::SecondRequest;
601+
return firstSeekDistance < secondSeekDistance ? Order::FirstRequest : Order::SecondRequest;
597602
}
598603

599604
// Prefer to continue in the same file so prioritize the request that's in the same file
@@ -625,6 +630,13 @@ namespace AZ::IO
625630
"Scheduler::Thread_ScheduleRequests - Sorting %i requests", m_context.GetNumPreparedRequests());
626631
auto sorter = [this](const FileRequest* lhs, const FileRequest* rhs) -> bool
627632
{
633+
if (lhs == rhs)
634+
{
635+
// AZStd::sort may compare an element to itself;
636+
// it's required this condition remain consistent and return false.
637+
return false;
638+
}
639+
628640
Order order = Thread_PrioritizeRequests(lhs, rhs);
629641
switch (order)
630642
{

0 commit comments

Comments
 (0)