Creating objects from within a thread crashing max.


    Mar 01 2013 | 9:37 am
    I'm using the Max sdk for a small, networked, multi-threaded application. All these factors make it a hellish nightmare as it is, but the benefits outweigh the heartache.
    I'm attempting to create an object within a thread, and upon reaching the code:
    t_object* patcher;
    
    object_obex_lookup( &m_ob, gensym( "#P" ), &patcher );
    
     t_object* gain = newobject_sprintf( patcher, "@maxclass gain~ @patching_rect 100. 100. 20. 100."); /* This is the line that crashes */
    Within a thread, the application crashes.
    When I attempt to put this code within the perform method that is common with MSP objects, it also crashes.
    However, if I put the above code within one of my methods that is communicated with Max via messages (e.g., bang), the gain~ object appears.
    There's a few routes I could take with this, but I'd like to keep the multithreaded aspect alive and running.
    I've also attempted to use critical_enter and critical_exit to no avail.
    So, can Max objects not be created outside of a main thread or something?
    I'm also using the C++ wrapper API provided on googlecode for this as well.

    • Mar 01 2013 | 1:59 pm
      +1, and I also think that creating objects in a patcher should only be done from the main thread
      aa
    • Mar 01 2013 | 5:17 pm
      Thanks for all your guy's responses.
      I fixed it by taking Nicolas's advice and wrapping the code around a t_clock and scheduling it very quickly.
      I'm quite new to programming with Max but it's very awesome so far. :D