Wanted: Thread help


    Nov 29 2009 | 6:03 am
    Assumption: this is pretty classic situation.
    Assumption: this crash is due to threadA (triggered by jit.notify) and treadB (triggered by bang) attempting to access the same jit.render at the same time.
    I spent all day toying around and trying things and researching threads (I'm a noob at that)
    So I'm here to ask. Whats the best way to arrange things so this won't crash. In real life, This a UI like a step sequencer. So the jitter notifiable is like me editing it with a mouse (quicker), and the bangs are like the clock causing a line to go across it(slower).
    I was hoping to avoid repeatedly rendering al a qmetro because:
    A, it would look choppy when using it as a UI object
    B, it would be cpu intensive for times when I'm not using it.
    Steps to crash,
    instantiate mxj TestDrawCrash
    hook a metro up to it,
    drag around the jit.window
    import com.cycling74.jitter.*;
    import com.cycling74.max.*;
    public class TestDrawCrash extends MaxObject  implements JitterNotifiable{
    
    	JitterListener myListener;
    	String name = "IwillCrash";
    	CrashWindow cw; 
    
    	public void notify (JitterEvent e){
    		cw.draw();
    	}
    
    	public void bang(){
    		cw.draw();
    	}
    
    	public TestDrawCrash(){
    		myListener = new JitterListener(name,this);
    		cw= new CrashWindow(name,300,300 );
    	}
    
    	class CrashWindow  {
    		JitterObject myWindow;
    		JitterObject myRender;
    		String name;
    
    		public CrashWindow(String name, int width, int height) {
    			myRender = new JitterObject("jit.gl.render", name);
    			myWindow = new JitterObject("jit.window", name);
    			myWindow.setAttr("size", new Atom[] { Atom.newAtom(width),Atom.newAtom(height) });
    			myWindow.setAttr("pos",new Atom[] { Atom.newAtom(0), Atom.newAtom(800) });
    			myWindow.call("front");
    			this.name = name; 
    
    		}
    
    		public void draw() {
    				myRender.call("erase");
    				myRender.call("drawclients");
    				myRender.call("swap");
    		}
    
    	}
    }

    • Nov 29 2009 | 6:36 am
      Amazing how you can go for 24 hours wondering about something, finally post a question and come up with the answer a couple minutes later.
      DUH!!