Skip to content

Commit

Permalink
fix showstopper issue: ugen/shred interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
gewang committed Oct 7, 2023
1 parent abac294 commit af21080
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
15 changes: 13 additions & 2 deletions src/core/chuck_instr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4000,10 +4000,21 @@ t_CKBOOL initialize_object( Chuck_Object * object, Chuck_Type * type, Chuck_VM_S
assert( type != NULL );
assert( type->info != NULL );

// set origin shred | 1.5.1.5 (ge) was: ugen->shred = shred;
if( shred ) object->setOriginShred( shred );
// REFACTOR-2017: added | 1.5.1.5 (ge & andrew) moved here from instantiate_...
object->setOriginVM( vm );
// check if origin shred is available | 1.5.1.5 (ge)
if( shred )
{
// set the origin shred only in specific cases...
// UGens: needs shred for auto-disconnect when shred is removed
// user-defined classes (that refer to global-scope variables):
// ...needs shred to access the global-scope variables across sporking
if( type->ugen_info || type->originHint == te_originUserDefined )
{
// set origin shred | 1.5.1.5 (ge) was: ugen->shred = shred;
object->setOriginShred( shred );
}
}

// allocate virtual table
object->vtable = new Chuck_VTable;
Expand Down
30 changes: 27 additions & 3 deletions src/core/chuck_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,14 @@ void Chuck_VM::release_dump( )

// iterate through dump
for( t_CKUINT i = 0; i < m_shred_dump.size(); i++ )
{
// detach ugens | 1.5.1.5 (moved here from inside shred destructor)
// (ensure we always do this, even if release below doesn't
// actually delete the shred due to reference count)
m_shred_dump[i]->detach_ugens();
// release
CK_SAFE_RELEASE( m_shred_dump[i] );
}

// clear the dump
m_shred_dump.clear();
Expand Down Expand Up @@ -1780,10 +1787,10 @@ t_CKBOOL Chuck_VM_Shred::initialize( Chuck_VM_Code * c,


//-----------------------------------------------------------------------------
// name: shutdown()
// desc: shutdown a shred
// name: detach_ugens()
// desc: detach all associate ugens created on a shred
//-----------------------------------------------------------------------------
t_CKBOOL Chuck_VM_Shred::shutdown()
void Chuck_VM_Shred::detach_ugens()
{
// check if we have anything in ugen map for this shred
if( m_ugen_map.size() )
Expand All @@ -1808,6 +1815,10 @@ t_CKBOOL Chuck_VM_Shred::shutdown()

// disconnect
ugen->disconnect( TRUE );
// make sure if ugen has an origin shred, it is this one | 1.5.1.5
assert( !ugen->originShred() || ugen->originShred() == this );
// also clear reference to this shred | 1.5.1.5
ugen->setOriginShred( NULL );

// advance the iterator
iter++;
Expand All @@ -1825,6 +1836,19 @@ t_CKBOOL Chuck_VM_Shred::shutdown()
// clear the release vector
release_v.clear();
}
}




//-----------------------------------------------------------------------------
// name: shutdown()
// desc: shutdown a shred
//-----------------------------------------------------------------------------
t_CKBOOL Chuck_VM_Shred::shutdown()
{
// detach ugens
detach_ugens();

// check if we have parent object references to clean up
if( m_parent_objects.size() )
Expand Down
2 changes: 2 additions & 0 deletions src/core/chuck_vm.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ struct Chuck_VM_Shred : public Chuck_Object
t_CKBOOL add( Chuck_UGen * ugen );
// unassociate ugen with shred
t_CKBOOL remove( Chuck_UGen * ugen );
// detach all associate ugens | 1.5.1.5 (ge) added
void detach_ugens();

// add parent object reference (added 1.3.1.2)
t_CKVOID add_parent_ref( Chuck_Object * obj );
Expand Down
2 changes: 1 addition & 1 deletion src/core/ugen_xxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2564,7 +2564,7 @@ CK_DLL_CTRL( delayp_ctrl_delay )
d->offset_target = target;
d->offset_start = d->last_offset;

t_CKTIME snow = ((Chuck_UGen*)SELF)->originShred()->now;
t_CKTIME snow = SHRED->now; // 1.5.1.5 was: ((Chuck_UGen*)SELF)->originShred()->now;
d->move_end_time = snow + d->move_duration;
}
RETURN->v_dur = d->last_offset; // TODO:
Expand Down

0 comments on commit af21080

Please sign in to comment.