hoijui / JavaOSC

OSC content format/"protocol" library for JVM languages
http://www.illposed.com/software/javaosc.html
BSD 3-Clause "New" or "Revised" License
156 stars 43 forks source link

Issues while sending messages when arguments size is 3, 7 etc. #25

Closed anurooppv closed 7 years ago

anurooppv commented 8 years ago

Hi,

I faced issues when I used JavaOSC library to send messages across different devices. It works fine for all argument sizes expect 3 , 7 etc. Please find below the results:

size = 1 data sent: [move] Received : [move]

size = 2 data sent: [move, 10.4] Received : [move, 10.4]

size = 3 data sent: [move, 10.4, 10.5] Received : [@$������@%, 0.0, 2.12199579146E-313, null, null, null, null]

size = 4 data sent: [move, 10.4, 10.5, 10] Received : [move, 10.4, 10.5, 10]

size = 5 data sent: [move, 10.4, 10.5, 10, 10] Received : [move, 10.4, 10.5, 10, 10]

size = 6 data sent: [move, 10.4, 10.5, 10, 10, 10] Received : [move, 10.4, 10.5, 10, 10, 10]

size = 7 data sent: [move, 10.4, 10.5, 10, 10, 10, 10] Received : [@$������@%, 5.0E-323, 2.12199579146E-313, 10, 0, 0, 0, null, null, null, null]

I tried to find out the reason behind these failures and I believe the error is happening because of the below method in OSCJavaToByteArrayConverter() class.

public void appendNullCharToAlignStream() {
        final int alignmentOverlap = stream.size() % 4;
        final int padLen = (4 - alignmentOverlap) % 4;
        for (int pci = 0; pci < padLen; pci++) {
            stream.write(0);
        }
}

So when the arguments size is 3, stream size becomes 12 and hence no zeroes are added. Thus the byte array sent will be not be the correct one. I believe we need to append 4 zeroes if the field alignmentOverlap becomes 0.

hoijui commented 8 years ago

hey @anurooppv ! :-) thanks for reporting! .. i am pretty sure this issue is already solved. i guess you tested with the latest release (0.3). this should be fixed in the master branch, which should still have the same API/interface. .. please test, and i might make a new release then.

anurooppv commented 8 years ago

Hi,

Thanks for the reply. As suggested by you, I checked the master branch. However I found the below method in OSCJavaToByteArrayConverter()

private void alignStream() { final int alignmentOverlap = stream.size() % 4; final int padLen = (4 - alignmentOverlap) % 4; for (int pci = 0; pci < padLen; pci++) { stream.write(0); } }

So when the argument size is 3 or 7, no zeroes will be appended and I guess it will fail.

Did you make any other change in any of the classes to fix this issue? Then I might be wrong. Please advise.

Regards, Anuroop

From: hoijui [mailto:notifications@github.com] Sent: Friday, 1 July, 2016 7:13 PM To: hoijui/JavaOSC JavaOSC@noreply.github.com Cc: Anuroop PATTENA VANIYAR anurooppv@smu.edu.sg; Mention mention@noreply.github.com Subject: [Marketing Mail] Re: [hoijui/JavaOSC] Issues while sending messages when arguments size is 3, 7 etc. (#25)

hey @anurooppvhttps://github.com/anurooppv ! :-) thanks for reporting! .. i am pretty sure this issue is already solved. i guess you tested with the latest release (0.3). this should be fixed in the master branch, which should still have the same API/interface. .. please test, and i might make a new release then.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/hoijui/JavaOSC/issues/25#issuecomment-229921589, or mute the threadhttps://github.com/notifications/unsubscribe/ANoQMdVAgQP-IVJZUV0mGLlYT6fTfkxjks5qRPZCgaJpZM4I_xj0.

hoijui commented 8 years ago

yes, there are other changes, please test. :-) ... i think this is the relevant change: https://github.com/hoijui/JavaOSC/commit/c1c0f46aaad001a26f9b1a066e4b9e798c7c4289