Crash when changing lightpulse example
#1
Exclamation 
Hi!

I am very fascinated by the lightpulse scripting example, and I was trying to see if I could use it to generate lichen growth!

I tried changing the script so that the leading edge of the light pulse emits particles into a new event. I did that by editing the "pulse" function. But I am not 100% sure if the code I made is valid, and 3ds Max crashes after I made the change.

This is the new function:

void pulse(int sInx, float pulseID) //this function initializes the pulse of a particular particle
{
tf.SetCustomFloat(sInx, "pulseID", pulseID); //assign the specified pulse value to a particle
tf.SetUVW(sInx, 1, new Point3(1, 0, 0)); //set the x-axis of a particle's UVW value to 1

int newSInx = tf.NewParticle(); //create a new particle
tf.SetPos(newSInx, tf.GetPos(sInx)); //assign the current position to the new particle
tf.OutputParticle(newSInx); //output the new particle
}

I have almost zero experience with C#, so there's probably something very wrong here. Can anyone help me out?
  Reply
#2
"NewParticle()" is not thread safe (this is stated in the new Script API window, but now in the old Script API listed below the main script, so I understand why it would not seem to be a problem at first)...so it's crashing due to a race condition.

You could either run the script single-threaded, or track when you want to spawn a particle in a thread-safe manner and then create them in 'postSimulationStep'.
  Reply
#3
Ahhh, gotcha! Thanks, will see if I can work around this.

Cheers!
  Reply


Forum Jump: