Problems with Threading
in
Programming Questions
•
4 months ago
Hi All,
I'm trying to run one of my projects in P3D, I am trying to make interesting effects based on certain events and testing in P2D works great, but once I switch over I get this error when I click and the program crashes.
Invalid memory access of location 0x0 eip=0x921c6b50
I'm not entirely sure what's going on, but it seems to be a problem with threading, I've tried a number of things, println() throughout to try to determine where it's stopping, combining PGraphics images instead of using the main Applet one. I've hit a bit of a wall, any help is greatly appreciated.
Main Class(EffectToolkit2)
- DrawableControl dc;
- void setup()
- {
- size(600, 600, P3D);
- dc = new DrawableControl(color(255), 25);
- dc.start();
- }
- void draw()
- {
- }
- void mousePressed()
- {
- dc.add(new Pulse(mouseX, mouseY, 1, 100));
- }
DrawableControl
- public class DrawableControl extends Thread
- {
- private color background;
- private int ms;
- private ArrayList<IDrawable> list;
- public DrawableControl(color background, int ms)
- {
- this.background = background;
- this.ms = ms;
- list = new ArrayList<IDrawable>();
- }
- public void run()
- {
- while(true)
- {
- if(list.size() != 0)
- {
- for(int i = 0; i < list.size(); i++)
- {
- if(list.get(i).step())
- {
- list.remove(i);
- }
- }
- try
- {
- Thread.sleep(ms);
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- background(background);
- }
- }
- }
- public void add(IDrawable id)
- {
- list.add(id);
- }
- }
- public interface IDrawable
- {
- public boolean step();
- }
Pulse
- public class Pulse implements IDrawable
- {
- private int x;
- private int y;
- private int currentRadius;
- private int maxSteps;
- public Pulse(int x, int y, int startRadius, int maxSteps)
- {
- this.x = x;
- this.y = y;
- this.currentRadius = startRadius;
- this.maxSteps = maxSteps;
- }
- public boolean step()
- {
- stroke(0);
- noFill();
- strokeWeight(2);
- currentRadius++;
- translate(x, y, 0);
- arc(0, 0, currentRadius, currentRadius, 0, 360);
- if(currentRadius >= maxSteps)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
-Brad
1