Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

c#: Receiving OSC/TUIO Data works not after build

Discussion in 'Scripting' started by TobiTobsenL, Sep 19, 2015.

  1. TobiTobsenL


    Sep 19, 2015
    Hi Community,
    I am trying to receive raw TUIO data, underlying structure is as known OSC. It works when I am testing it in the unity development environment but fails when i am trying to run my builded exe file.

    I am scipting with c# and I am using the c# reference implementation which can be found here:
    From here:

    What I did was to copy the folder TUIO and OSC.NET to my Assets folder. From there I can use them in my scripts.

    Hmm so its working fine when running the project within the unity development environment... After build and starting the exe no reaction when sending TUIO data. Looking into the output_log.txt file that was created by the .exe, I see an excepion that comes up with the first TUIO message sent, saying this:

    An exception was thrown by the type initializer for OSC.NET.OSCPacket
    null packet

    This seems to come up with every TUIO data that was sent.

    The class OSCPacket is abstact:
    abstract public class OSCPacket

    Could this cause the problem?
    Not sure as its running fine when not starting the exe, so i was thinking it might be some missing ressources or sth?

    Maybe someone else has a smart idea?

    Thanks & Cheers,
  2. TobiTobsenL


    Sep 19, 2015
    Hi There,
    so I did change to another, more simple, Tuio C# implementation:

    It needed a bit more programming on my side but now its working fine also after building the exe file.

    Still I don't know why it did not work with the other implementation.

  3. Surg


    Jun 29, 2013
    @TobiTobsenL Do you have any explanation/tutorial how to use your library.
    Very interested in testing out TUIO using unity!
    kenshin likes this.
  4. TobiTobsenL


    Sep 19, 2015
    Hi Surg,
    so like I wrote, the standard TUIO C# implentation did crash after buidling the exe file and trying to run this.

    So I was using this more simple implementation:

    I added the folders OSCsharp and TUIOsharp to my Assets.
    TUIO uses the OSC implementation, so you need both although you will only talk to TUIOsharp.
    I wrote a class called TuioHandling() that does the TUIO handling and attached this one to the MainCamera.

    In this skrip you have to create a TuioServer:
    TuioServer tuioserver;

    Now this is not the nicest programming design but was ok for my purpose: The TuioServer needs to know who to call when there are new TUIO data - this is why I added a TuioHandling() object to the TuioServer() class. This TuioHandling() object is called when there are new data available, this happens in TuioServer():

    private void handlerOscMessageReceived(object sender, OscMessageReceivedEventArgs oscMessageReceivedEventArgs)
    this.tuioMain.callMeOnNewCursors(this.updatedCursors, this.addedCursors, this.removedCursors);

    the method callMeOnNewCursors() is in my TuioHandling class and this is where I process the Tuio data.

    Now you have to create the TuioServer, I did init this in the Start() method in TuioHandling:
    tuioServer = new TuioServer(this);

    You can see with (this) the TuioServer() gets the link to the TuioHandling().

    OnApplicationQuit() you should disconnect:

    If I find time I will prepare a clean version of my implementation and upload it, this will make things easier.
    But in the end you will only receive raw TUIO data, thats pretty low level data that need to be processed somehow.

    Best regards
  5. glvenlan


    Mar 31, 2013
    For my case, the Encoding.GetEncoding(1252) function at static OSCPacket() in class OSC.NET.OSCPacket caused the problem above.
    Log all exception would show that the builded exe file could not find the specified code page 1252.
    Just change to ASCIIEncoding8Bit = Encoding.Default would fixed the problem.
    svnsms, Deleted User and oculartech like this.
  6. tabulatouch


    Mar 12, 2015
    Saved my day, thank you!
  7. oculartech


    Jan 9, 2020