Skip to content

Commit dbfe12f

Browse files
committed
map: fixed mp_icon on arch linux
the np.fromstring was not working on arch.
1 parent 47a588e commit dbfe12f

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

MAVProxy/modules/mavproxy_map/mp_tile.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -617,21 +617,27 @@ def mp_icon(filename):
617617
'''load an icon from the data directory'''
618618
# we have to jump through a lot of hoops to get an OpenCV image
619619
# when we may be in a package zip file
620+
raw = None
620621
try:
621622
import pkg_resources
622623
name = __name__
623624
if name == "__main__":
624625
name = "MAVProxy.modules.mavproxy_map.mp_tile"
625-
stream = pkg_resources.resource_stream(name, "data/%s" % filename).read()
626-
raw = np.fromstring(stream, dtype=np.uint8)
626+
stream = pkg_resources.resource_stream(name, f"data/{filename}")
627+
raw = np.frombuffer(stream.read(), dtype=np.uint8)
627628
except Exception:
628629
try:
629-
stream = open(os.path.join(os.path.dirname(__file__), 'data', filename)).read()
630-
raw = np.fromstring(stream, dtype=np.uint8)
630+
with open(os.path.join(os.path.dirname(__file__), 'data', filename), 'rb') as f:
631+
raw = np.frombuffer(f.read(), dtype=np.uint8)
631632
except Exception:
632-
#we're in a Windows exe, where pkg_resources doesn't work
633-
import pkgutil
634-
raw = pkgutil.get_data( 'MAVProxy', 'modules//mavproxy_map//data//' + filename)
633+
try:
634+
import pkgutil
635+
stream = pkgutil.get_data('MAVProxy', f'modules/mavproxy_map/data/{filename}')
636+
raw = np.frombuffer(stream, dtype=np.uint8)
637+
except Exception as e:
638+
print(f"Failed to load image '{filename}': {e}")
639+
return None
640+
635641
img = cv2.imdecode(raw, cv2.IMREAD_COLOR)
636642
return img
637643

0 commit comments

Comments
 (0)