-
Notifications
You must be signed in to change notification settings - Fork 3
[2409] Csv Spawner Notification Bus #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: o3de-2409
Are you sure you want to change the base?
Changes from 1 commit
6470d8a
6ccf97e
915d029
1b9affd
57322f8
ee5c565
399c2d1
5b7dd26
3fc175d
9cf218a
4651355
45bd34c
ffa7f34
23e9891
7049997
c91a03a
f70295a
5373024
09e44bf
ee39e1c
2fbc807
002c35b
139bb38
318d19f
0c45656
bb29e40
5a24a36
54e6f12
22c3628
51e1941
476f2b4
26cb4bd
62358ef
9e3cf1a
95b70d1
b30aac2
75e3739
61fc9aa
13671a4
2c17d49
896f067
687aff9
b30dda3
3694333
2e4d01a
3345918
48cd8d2
24c4e8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,6 +252,10 @@ namespace CsvSpawner::CsvSpawnerUtils | |
} | ||
} | ||
|
||
// Track how many tickets are spawned and how many have completed | ||
size_t totalTickets = 0; | ||
std::atomic_size_t completedTickets = 0; | ||
|
||
for (const auto& entityConfig : entitiesToSpawn) | ||
{ | ||
if (!spawnableAssetConfiguration.contains(entityConfig.m_name)) | ||
|
@@ -317,7 +321,7 @@ namespace CsvSpawner::CsvSpawnerUtils | |
transformInterface->SetWorldTM(transform); | ||
}; | ||
optionalArgs.m_completionCallback = | ||
[parentId, &spawnStatusCode]( | ||
[parentId, &spawnStatusCode, &broadcastSpawnInfo, &tickets, totalTickets, &completedTickets]( | ||
|
||
[[maybe_unused]] AzFramework::EntitySpawnTicket::Id ticketId, AzFramework::SpawnableConstEntityContainerView view) | ||
{ | ||
if (view.empty()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code within this if statement exhibits undefined behavior because |
||
|
@@ -329,16 +333,28 @@ namespace CsvSpawner::CsvSpawnerUtils | |
} | ||
const AZ::Entity* root = *view.begin(); | ||
AZ::TransformBus::Event(root->GetId(), &AZ::TransformBus::Events::SetParent, parentId); | ||
|
||
completedTickets++; | ||
if (completedTickets == totalTickets) | ||
{ | ||
// Call CsvSpawner EBus notification - Finished | ||
CsvSpawnerNotificationBus::Broadcast(&CsvSpawnerInterface::OnEntitiesSpawnFinished, broadcastSpawnInfo, spawnStatusCode); | ||
} | ||
|
||
}; | ||
optionalArgs.m_priority = AzFramework::SpawnablePriority_Lowest; | ||
spawner->SpawnAllEntities(ticket, optionalArgs); | ||
tickets[entityConfig.m_id] = AZStd::move(ticket); | ||
|
||
totalTickets++; | ||
} | ||
|
||
// Check is success spawn | ||
tickets.empty() ? spawnStatusCode |= SpawnStatus::Fail : spawnStatusCode |= SpawnStatus::Success; | ||
// Call CsvSpawner EBus notification - Finished | ||
CsvSpawnerNotificationBus::Broadcast(&CsvSpawnerInterface::OnEntitiesSpawnFinished, broadcastSpawnInfo, spawnStatusCode); | ||
// If no tickets were created at all (no entities spawned), send finish immediately | ||
if (totalTickets == 0) | ||
{ | ||
spawnStatusCode |= SpawnStatus::Fail; | ||
// Call CsvSpawner EBus notification - Finished | ||
CsvSpawnerNotificationBus::Broadcast(&CsvSpawnerInterface::OnEntitiesSpawnFinished, broadcastSpawnInfo, spawnStatusCode); | ||
} | ||
|
||
return tickets; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that the four references in question are currently dangling. This arises because local variables are being passed to the completion callback, which is executed after the
SpawnEntities
function has ended. Once the function finishes, the references to the callback become invalid since the variables they point to no longer exist. It is important to address this issue to ensure the code functions as intended.