using threads with library

Issue #4 new
Amy Traylor created an issue

Hi James,

I keep getting the error "VRdraw function does not exist in MainApp," which I found is an exception thrown in the runVRdrawMethod() and getMethodRef() classes.

I have multiple scenes and I am trying to use the Processing thread() function to load new movies, models, and scenes. Thread() works when I use it in the setup() but if I call it after the program has started I get the error. Maybe the thread() is no longer connected to the mainApp so it can no longer see VRdraw?

My question is do you have an idea of how to use threads while referencing the MainApp or VRdraw function so I don't get the error?

I also get the error intermittently when I attempt to use code in a different tab than the main draw() but we can tackle that problem after the first one.

Thank you,

Amy

Comments (6)

  1. James Pazzi repo owner

    Hi Amy,

    I've been trying to recreate your error using the thread function, but I haven't been able to recreate your error. I'm running really simple threads that take some time using arbitrary math functions, pull images from websites. Nothing seems to throw an error.

    I'm having trouble understanding your question "how to use threads while referencing the MainApp or VRdraw function so I don't get the error?"

    If you're referring to where you should run threads you should definitely do this from the draw loop in your MainApp. To run thread commands inside VRdraw would likely cause some sort of concurrent modification error or just break something because it would run the thread twice in a single frame. This could be why you're getting errors.

    As a rule of thumb for this library (from what I remember) - anything that doesn't need to be drawn on the vr headset, such as running a thread should be left in the draw section. Anything in the VRdraw section is processed twice - once for each eye - so it should be confined to drawing functions only.

    Hope this helps. Let me know if it doesn't fix your problem.

  2. Amy Traylor reporter

    Hi James,

    I thought the thread function was the problem because I started getting the error shortly after I started using them. I was using a thread to load a new random video into my scene. Now the only hypothesis I have about the "VRdraw function does not exist in MainApp" error message is that it happens when the sketch is using upwards of 99% of the available memory when trying to load new assets, etc. So basically if I tax the system too much then the thread throws that error. Do you have some idea of what causes that message? I can also send you the code folder.

    Amy

  3. James Pazzi repo owner

    Feel free to email me the code. Sounds like there are a lot of complex functions at play. The processing reference states that the thread function isn't particularly robust. Have you tested running these threads without running VRdraw? Do you still get the same memory issue?

  4. Amy Traylor

    Hi James,

    I have been working with the library since July and I still sometimes get the "VRdraw function does not exist in MainApp" exception but I can't figure out why the exception is triggered. Two different functions return the same exception. It seems to get triggered when I am trying to load new files or otherwise taxing the system.

    These are the functions:

    vivep5.png

    runVRdrawMethod() gets called in the draw method and getMethodRef() from the constructor.

    I don't understand why the sketch wouldn't be able to complete the line: VRdrawMethod.invoke(parent);

    So my sketch keeps hitting that exception and ceasing to play. Any thoughts? I don't know how to compile jar files I would try to rewrite the excpetion so it doesn't make VRdraw false.

    Amy

  5. James Pazzi repo owner

    Hi Amy,

    Have you tried invoking your large loading functions during setup before initializing vivep5?

    I'm not sure how to overcome this one without a little bit more context as I've been unable to recreate the error.

    If you wanted to make changes to the library locally without compiling the jar, if I recall correctly, it's actually pretty easy. You can simply take the Controller.java and Vive.java files from here, add them as classes to a new sketch and reference them from your mainapp rather than importing the library.

    Apologies for the late response.

    James

  6. Amy Traylor

    Hi James,

    I am going to send you my whole project if you don't mind. I tried using the source Java files as classes which worked except the scene was only showing in one eye.

    Thank you, Amy

  7. Log in to comment