Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: successive connect/disconnect crashes PyATEMMax #43

Open
secarica opened this issue Jul 18, 2023 · 2 comments
Open

Bug: successive connect/disconnect crashes PyATEMMax #43

secarica opened this issue Jul 18, 2023 · 2 comments

Comments

@secarica
Copy link

secarica commented Jul 18, 2023

This simple script is enough to chrash the program:

import PyATEMMax
import time

switcher = PyATEMMax.ATEMMax()

switcher.connect("192.168.1.192")
testing = switcher.waitForConnection()
print ("connect 1", testing)
time.sleep(2)

testing = switcher.disconnect()
print ("disconnect 1", testing)
time.sleep(2)

switcher.connect("192.168.1.192")
testing = switcher.waitForConnection()
print ("connect 2", testing)
time.sleep(2)

testing = switcher.disconnect()
print ("disconnect 2", testing)
time.sleep(2)

By running the above script, here is the result:

C:\temp>python test.py
connect 1 True
disconnect 1 None
Exception in thread Thread-9 (_commsThreadHandler):
Traceback (most recent call last):
    File "C:\python31.164\Lib\threading.py", line 1038, in _bootstrap_inner
        self.run()
    File "C:\python31.164\Lib\threading.py", line 975, in run
        self._target(*self._args, **self._kwargs)
    File "C:\python31.164\Lib\site-packages\pyatemmax-1.0b9-py3.11.egg\PyATEMMax\ATEMConnectionManager.py", line 313, in _commsThreadHandler
    File "C:\python31.164\Lib\site-packages\pyatemmax-1.0b9-py3.11.egg\PyATEMMax\ATEMConnectionManager.py", line 408, in _runLoop
IndexError: list index out of range

Happens the same on Windows 10 and on Linux / Raspberry Pi OS and the same when connecting to a physical ATEM 1 M/E Constellation HD and to the virtual pyAtemSim simulator.

??

(the goal here is to use this kind of sequence within a wxPython program that has explicit Connect / Disconnect buttons)

@secarica
Copy link
Author

secarica commented Aug 6, 2023

Could be (?) the packetSessionID is not properly initialized after closing and then reopening connection.

While sniffing after line 375 in module ATEMConnectionManager.py, after first program launch both self.sessionID and packetSessionID are 0; then, after disconnecting and reconnecting (but without leaving the main program), the self.sessionID is again 0, but packetSessionID seems to retain the previous ID – and so the following if not self.sessionID and packetSessionID: condition goes on another road, ending with a crash.

Not 100% sure though, still investigating...

@secarica secarica changed the title successive connect/disconnect crashes PyATEMMax Bug: successive connect/disconnect crashes PyATEMMax Aug 6, 2023
@coding-today
Copy link

I have also encountered this issue. Here is my code and log output

`import logging
import socket
import time

import PyATEMMax

logging.basicConfig(filename="test.log")
switcher = PyATEMMax.ATEMMax()
switcher.setLogLevel(logging.DEBUG)

def connect(ip):
global switcher
if switcher.connected:
pass
else:
switcher.connect(ip)
connected = switcher.waitForConnection()
print(f"connected:{connected}")
print(f"[{time.ctime()}] Connected to switcher at {ip}")

def listem_pgm():
lastPGM = switcher.programInput[0].videoSource
longname = switcher.inputProperties[lastPGM].longName
return longname

def set_pgm_source(pgm_source, channel=3):
if switcher.connected:
switcher.setProgramInputVideoSource(channel, pgm_source) # 第一个参数输出的路数编号,BMD输出4路
print(f"[{time.ctime()}] Changing PGM at Camera {pgm_source}")
else:
print(f"[{time.ctime()}] switcher not connected")

def set_pvw_source(pvm_source, channel=3):
if switcher.connected:
switcher.setPreviewInputVideoSource(channel, pvm_source) # 第一个参数输出的路数编号,BMD输出4路
print(f"[{time.ctime()}] Changing PVW at Camera {pvm_source}")
else:
print(f"[{time.ctime()}] switcher not connected")

def get_host_ip():
ip = ""
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip = s.getsockname()[0]
except Exception as e:
code = e.args[0]
if code == 51:
print("获取IP失败=============没有网络=============")
finally:
s.close()
return ip

if name == "main":
ip = "192.168.21.100"
BMDvideosource = {
"OB2": 2,
"OB5": 8,
"OB8": 11,
"OB1": 1,
"OB3": 3,
"OB4": 7,
"OB6": 9,
"OB7": 10,
"OB9": 12,
"OB10": 23,
"OB11": 24,
"OB12": 25,
"OB13": 26,
"OB14": 27,
"OB15": 28,
"OB16": 29,
"OB17": 30,
"OB18": 31,
"OB19": 33,
}
print(f"当前机器IP:{get_host_ip()}")
print(f"BMD-IP:{ip}")
connect(ip)

a = ["OB10", "OB11", "OB12"]
for item in a:
    time.sleep(2)
    set_pgm_source(BMDvideosource[item], channel=0)

switcher.disconnect()

`
and this is test.log
debug.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants