2.41 network bug?

hiya,
think ive found a bug in 2.41:

heres some script: (nicked from someone)


import socket, string

# referencia na hlavny objekt - reference to main object
contr = GameLogic.getCurrentController()
obj = contr.getOwner()
ip = "127.0.0.1"

# ak nie je pripojeny - if it's connected
if obj.connected == '':
  # nazov pocitaca a cislo portu - computer name and port name
  host = ip
  port = 4950
  # vytvorenie socketu pre protokol UDP - socket for UDP
  GameLogic.conn = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  # pripojenie klienta - connection to client
  GameLogic.conn.bind((host, port))
  # nastavenie socketu do neblokovacieho rezimu - nonblocking mode
  GameLogic.conn.setblocking(0)
  # oznam, ze je server pripraveny - be aware that server is connected
  obj.connected = 'c'

the above is used to initialise the connecetion [ run once]



import socket, OSC
import GameLogic

#print dir(OSC)
contr = GameLogic.getCurrentController()
obj = contr.getOwner()

# ak je pripojeny - if it's connected
if obj.connected == 'c':
  # prisli data - data is here
  rec = 1
  # ak prisli data - if data is here
  while rec == 1:
    try:
      data = GameLogic.conn.recvfrom(1024)[0]
      if data: 
        msg = OSC.decodeOSC(data) # decode data
        #print msg[2]
    except:
      rec = 0

print len(msg)
print msg


and that bit is constantly being run to ge the data coming in over OSC.

All works fine in 2.37,2.40 but in 2.41 and 2.41ultimate i get the :

PYTHON SCRIPT ERROR:
Traceback (most recent call last):
File “server.py”, line 30, in ?
NameError: name ‘msg’ is not defined

error.

Im using python 2.42 downloaded today and my pythonpath is set.

Any ideas on this one or anybody had similar netwrok problems with 2.41?

Will

I assume you second code set is server.py and I assume your line 30 is the one with print len(msg).

In this case msg is not set because you don’t have a variable named msg. Your msg exist only if the script enters the two “if” and the “while” statement. Otherwise it is not defined.

To get around that you can
-move your prints directly after your “msg = …” assignment as the commented print does it already or
-initialize msg before the first “if”.

Hi Monster, the thing is when running anything other than 2.41 the script does enter into the two if and while statements and so the msg variable is defined. Its just in 2.41 it doesnt get that far. Although the first script runs fine in all versions of blender, and obj.conneceted does equal “c”.

Where do i go to report the bug please?

Will

I’m not sure if I’m right but what if…
The connection is made, it checks if something comes in, if data msg = some stuff. And goes further and print len(msg) with no problem

Now we get again connection established, receive data, but there is no data for some reason, but well the loop goes further and wants to print len(msg) but there was not data which is no msg = stuff, so no print len(msg)

You can fix this with adding print len(msg) into a try/accept statement, so if there’s nothing received it gives no error, if received it prints.
I got this problem when I worked on my Multiplayer tests.

Anyways, whats OSC ? I never used that. :slight_smile:

Now we get again connection established, receive data, but there is no data for some reason, but well the loop goes further and wants to print len(msg) but there was not data which is no msg = stuff, so no print len(msg)

Hi Jd, yeh thats exactly right except there is data coming in… so msg should equal something.

Ok just played a bit more and its got even weirder, now msg data gets printed out to the console along with the error, “msg” is not defined:

PYTHON SCRIPT ERROR:
Traceback (most recent call last):
File “server.py”, line 23, in ?
NameError: name ‘msg’ is not defined
2
[[0, 1, 1], [0.15000000596046448, 0.5899999737739563, 0.45283019542694092, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 1.1000000238418579, 1.2000000476837158, 1.2999999523162
842, 1.3999999761581421, 1.5, 1, 0]]

So the data is getting in i guess? but the script as a whole still doesnt work as i use the msg variable to get at data later on. ie:

r0 = msg[0]
r1 = msg[1] etc…

from putting print commands in various places it looks like the script might be running through twice every cycle- is something like that possible.

ill try find somewhere to post the blend to…

oh yeh OSC is OpenSoundControl a network protocol i think, im using it to share data between MAX/MSP and Blender so i have a control surface running in Max triggering audio whilst triggering video at the same time in blender.

http://www.cnmat.berkeley.edu/OpenSoundControl/
and
http://wiretap.stetson.edu/index.php

Will

##############################################
so heres the blend.
http://www.upload2.net/download2/9lN0JyDDFEgkpaj/0.12modulestretch.blend.html

and heres the max/map patch which is sending data.
http://www.upload2.net/download2/dA75oWds17NuQiV/elysiun+trial.mxf.html

Python OSC and MAX/MSP externals will also be needed wihch can be got from.
http://www.cnmat.berkeley.edu/OpenSoundControl/Max/
and
http://wiretap.stetson.edu/index.php?portal_page=downloads

if anyone can be bothered with that it would be great otherwise just taking a look at the blend would be nice :smiley:

also where do i report bugs too please.

Will

Hi glitchCORD~,

I have written the original version of this script (without that OSC stuff). Variable rec means that data was received, so in while loop are processed all received data. While loop is ended when no further data are available. Real processing of received data should be done inside “if data:” condition - that’s point where msg variable is filled with current data. After ending the while loop there are last data in msg variable and maybe msg variable wasn’t created at all (when no data was received in current run of script).

Why it’s vorking on version 2.3x and isn’t on 2.4x? There can be changes in timing of script execution. If 2.4 runs faster, it can execute this script more frequently and it can happen that there are no data available from network source.

Hi ashsid,

Thanks for your input, ive tried a few things out but dont seem to be getting any closer to sorting it out.

After ending the while loop there are last data in msg variable and maybe msg variable wasn’t created at all (when no data was received in current run of script).

In 2.37/2.40 I tried stopping sending OSC data from MAX. The msg variable stayed at whatever the last recieved data was, it didnt disappear.

I tried replacing the while and try statements with if statements, the script ran but still gave the same errors.

I tried placing the workings of my script inside the if data: section but any more than one line of code below: msg = OSC.decodeOSC(data) # decode data, gave a syntax error for that line i.e

if data:
msg = OSC.decodeOSC(data) # decode data
print msg
print len(msg) ##* anything on this line or below gives a synatx error for this line.

I tried upping the output rate from my MAX patch which got rid of errors about msg not being defined but gave errors about other variables which get set when msg equals something.

any ideas?

print msg
print len(msg) ##* anything on this line or below gives a synatx error for this line.

It looks like you have problem with intendation of Python code (mixed spaces and tabs)?

Hi again,
sorry for being so long in replying ashsid, you were right i was using a mixture of spaces and tabs, thanks for that :slight_smile:

ive made a super-simple blend to demonstrate the problem im having, id be really grateful if people could run it in 2.37 and 2.40/2.41, in 2.37 it runs fine printing out 0,1,2 but in 2.40 it gives errors. could someone tell me whats changed for the new version and if its just a simple case of using a different “if” command.

thanks
will

the blends at: http://www.upload2.net/download2/kSavfpmlsScJlmO/trial.blend.html

ps how do you edit the title that shows up in the forum?

its only 88k ! :smiley: