Fixed the problem with pixels missing in the message and prevented general exceptions from crashing the server.
This commit is contained in:
parent
060693625f
commit
d781d85745
2 changed files with 26 additions and 25 deletions
|
|
@ -14,7 +14,6 @@ import random
|
||||||
import time
|
import time
|
||||||
|
|
||||||
class MaxSizeList(list):
|
class MaxSizeList(list):
|
||||||
maxsize = 0
|
|
||||||
|
|
||||||
def __init__(self, maxcount=100):
|
def __init__(self, maxcount=100):
|
||||||
self.maxsize = maxcount
|
self.maxsize = maxcount
|
||||||
|
|
@ -25,7 +24,6 @@ class MaxSizeList(list):
|
||||||
if self.__len__() == self.maxsize:
|
if self.__len__() == self.maxsize:
|
||||||
raise IndexError('max size reached')
|
raise IndexError('max size reached')
|
||||||
|
|
||||||
|
|
||||||
def RGBPixel(x, y, r, g, b, a=None): # pylint: disable=C0103
|
def RGBPixel(x, y, r, g, b, a=None): # pylint: disable=C0103
|
||||||
"""Generates the packed data for a pixel"""
|
"""Generates the packed data for a pixel"""
|
||||||
if a:
|
if a:
|
||||||
|
|
@ -55,7 +53,7 @@ def RandomFill(width=640, height=480):
|
||||||
message.append(pixel)
|
message.append(pixel)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
yield ''.join(message)
|
yield ''.join(message)
|
||||||
message[:] = []
|
message[2:] = []
|
||||||
message.append(pixel)
|
message.append(pixel)
|
||||||
yield ''.join(message)
|
yield ''.join(message)
|
||||||
|
|
||||||
|
|
|
||||||
3
vloed.py
3
vloed.py
|
|
@ -91,6 +91,7 @@ class Canvas(object):
|
||||||
# while we have stuff in the queue, and its not our next time to draw a
|
# while we have stuff in the queue, and its not our next time to draw a
|
||||||
# frame, lets process packets from the queue
|
# frame, lets process packets from the queue
|
||||||
while time.time() < returntime and not self.queue.empty():
|
while time.time() < returntime and not self.queue.empty():
|
||||||
|
try:
|
||||||
data = self.queue.get()
|
data = self.queue.get()
|
||||||
preamble = struct.unpack_from("<?", data)[0]
|
preamble = struct.unpack_from("<?", data)[0]
|
||||||
protocol = struct.unpack_from("<B", data, 1)[0]
|
protocol = struct.unpack_from("<B", data, 1)[0]
|
||||||
|
|
@ -111,6 +112,8 @@ class Canvas(object):
|
||||||
if self.debug:
|
if self.debug:
|
||||||
print pixel
|
print pixel
|
||||||
self.Pixel(*pixel)
|
self.Pixel(*pixel)
|
||||||
|
except Exception as e: #All exceptions will be printed, but won't result in a crash.
|
||||||
|
print e
|
||||||
# indicate that we have been drawing stuff
|
# indicate that we have been drawing stuff
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue