@ -360,27 +360,24 @@ bool DFHack::Job::removeJob(df::job* job) {
using df : : global : : world ;
using df : : global : : world ;
CHECK_NULL_POINTER ( job ) ;
CHECK_NULL_POINTER ( job ) ;
// cancel_job below does not clean up refs, so we have to do that first
// cancel_job below does not clean up all refs, so we have to do some work
// clean up general refs
// manually handle DESTROY_BUILDING jobs (cancel_job doesn't handle them)
for ( auto genRef : job - > general_refs ) {
if ( job - > job_type = = df : : job_type : : DestroyBuilding ) {
if ( ! genRef ) continue ;
for ( auto & genRef : job - > general_refs ) {
disconnectJobGeneralRef ( job , genRef ) ;
// disconnectJobGeneralRef only handles buildings and units
if ( genRef ) delete genRef ;
if ( genRef - > getType ( ) ! = general_ref_type : : BUILDING_HOLDER & &
}
genRef - > getType ( ) ! = general_ref_type : : UNIT_WORKER )
job - > general_refs . resize ( 0 ) ;
return false ;
}
for ( auto genRef : job - > general_refs ) {
// remove the job from the world
// this should always succeed because of the check in the preceding loop
job - > list_link - > prev - > next = job - > list_link - > next ;
bool success = disconnectJobGeneralRef ( job , genRef ) ;
delete job - > list_link ;
assert ( success ) ; ( void ) success ;
delete job ;
if ( genRef ) delete genRef ;
return true ;
}
}
job - > general_refs . resize ( 0 ) ;
// clean up item refs
// clean up item refs and delete them
for ( auto & item_ref : job - > items ) {
for ( auto & item_ref : job - > items ) {
disconnectJobItem ( job , item_ref ) ;
disconnectJobItem ( job , item_ref ) ;
if ( item_ref ) delete item_ref ;
if ( item_ref ) delete item_ref ;