Why am I getting a crash in P3D but not P2D.
in
Programming Questions
•
1 year ago
My uni project is to create some music visualizations using processing, which is going well. Until now.
If I run my 2D sketches in P3D they cause the sketch to crash (outside of the PDE).
Strangely this is only happening when I hit 'esc'
An example of my code:
//graph
void graph()
{
if (isPlaying) //if music is "playing" and not paused
{
lastPosition = player.position()/1000; //remember position
colorMode(RGB); //set color mode
//set up FFT and drawing modes
fftLog.forward(player.mix);
smooth(); //for smooth drawing
noStroke();
colorMode(HSB, 100);
rectMode(CORNER);
for(int i = 0; i < fftLog.avgSize(); i++)
{
if(i < fftLog.avgSize() - 29)
{
background(0); //refresh screen
}
float amp = sqrt(sqrt(fftLog.getAvg(i)))*150; //set amp according to fft
float h = i * 100/fftLog.avgSize() + 20; //set colour according to band (add 20 to shift colours over)
h = 100 - h; //reverse colour spectrum, blues for bass, reds for treble.
float s = 80; //saturation of colour
float b = amp/3 * 100; //for fading of drawings
float alp = 90; //opacity
fill(color(h,s,b,alp)); //set colours according to band and amp
stroke(color(h,s,b,alp)); //set colours according to band and amp
float x = canvasW/30 * i + 30; //set location to draw according to band
float y = canvasH - amp-60; //set drawing height according to amp and canvas size
int z = 10;
//change drawing mode for fft drawings
rectMode(CENTER);
ellipseMode(CENTER);
//draw
if (rectOn == true && lineGrOn == false) //user choice of rec or elip or line
{
translate(x,y,10);
box(sizew, sizeh, z);
translate(-x,-y,-10);
}
else if (rectOn == false && lineGrOn == false)
{
sphereDetail(25);
translate(x,y,10);
sphere(sizew/2);
translate(-x,-y,-10);
}
else if (rectOn == false && lineGrOn == true)
line(x-sizew/2,y,z,x+sizew/2,y,z);
}//for
}
}//graph
if I run the sketch and default to the box or sphere method, it works fine, but as soon as I default or switch to the line method and hit 'esc' it crashes.
I have another sketch which involves drawing fireworks which acts the same way.
here's my stop():
//stop
void stop() //stop function
{
if (hasOpened == true && !cancelled)
{
player.close(); //must stop player and minim before close
minim.stop();
}
super.stop();
}//stop
Any ideas on where this bug is would be great.
Thanks in advance to anyone who finds the time to help with this.
Joni
If I run my 2D sketches in P3D they cause the sketch to crash (outside of the PDE).
Strangely this is only happening when I hit 'esc'
An example of my code:
//graph
void graph()
{
if (isPlaying) //if music is "playing" and not paused
{
lastPosition = player.position()/1000; //remember position
colorMode(RGB); //set color mode
//set up FFT and drawing modes
fftLog.forward(player.mix);
smooth(); //for smooth drawing
noStroke();
colorMode(HSB, 100);
rectMode(CORNER);
for(int i = 0; i < fftLog.avgSize(); i++)
{
if(i < fftLog.avgSize() - 29)
{
background(0); //refresh screen
}
float amp = sqrt(sqrt(fftLog.getAvg(i)))*150; //set amp according to fft
float h = i * 100/fftLog.avgSize() + 20; //set colour according to band (add 20 to shift colours over)
h = 100 - h; //reverse colour spectrum, blues for bass, reds for treble.
float s = 80; //saturation of colour
float b = amp/3 * 100; //for fading of drawings
float alp = 90; //opacity
fill(color(h,s,b,alp)); //set colours according to band and amp
stroke(color(h,s,b,alp)); //set colours according to band and amp
float x = canvasW/30 * i + 30; //set location to draw according to band
float y = canvasH - amp-60; //set drawing height according to amp and canvas size
int z = 10;
//change drawing mode for fft drawings
rectMode(CENTER);
ellipseMode(CENTER);
//draw
if (rectOn == true && lineGrOn == false) //user choice of rec or elip or line
{
translate(x,y,10);
box(sizew, sizeh, z);
translate(-x,-y,-10);
}
else if (rectOn == false && lineGrOn == false)
{
sphereDetail(25);
translate(x,y,10);
sphere(sizew/2);
translate(-x,-y,-10);
}
else if (rectOn == false && lineGrOn == true)
line(x-sizew/2,y,z,x+sizew/2,y,z);
}//for
}
}//graph
if I run the sketch and default to the box or sphere method, it works fine, but as soon as I default or switch to the line method and hit 'esc' it crashes.
I have another sketch which involves drawing fireworks which acts the same way.
here's my stop():
//stop
void stop() //stop function
{
if (hasOpened == true && !cancelled)
{
player.close(); //must stop player and minim before close
minim.stop();
}
super.stop();
}//stop
Any ideas on where this bug is would be great.
Thanks in advance to anyone who finds the time to help with this.
Joni
1