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

AttributeError: 'array.array' object has no attribute 'tostring' #2

Open
DiabloFox opened this issue Jun 1, 2023 · 2 comments
Open

Comments

@DiabloFox
Copy link

DiabloFox commented Jun 1, 2023

Hi ! I was testing this tool but after getting the MainField in the terrain file and executing the "gen_map_gui.py" with LOD 8 to try I'm left with an error and I can't find how to fix it.

Here the error message :

Traceback (most recent call last):
File "C:\BOTWHeightmap_Project\gen_map_gui.py", line 196, in
Main().run()
File "C:\Users{USER}\AppData\Local\Programs\Python\Python311\Lib\site-packages\kivy\app.py", line 956, in run
runTouchApp()
File "C:\Users{USER}\AppData\Local\Programs\Python\Python311\Lib\site-packages\kivy\base.py", line 574, in runTouchApp
EventLoop.mainloop()
File "C:\Users{USER}\AppData\Local\Programs\Python\Python311\Lib\site-packages\kivy\base.py", line 339, in mainloop
self.idle()
File "C:\Users{USER}\AppData\Local\Programs\Python\Python311\Lib\site-packages\kivy\base.py", line 383, in idle
self.dispatch_input()
File "C:\Users{USER}\AppData\Local\Programs\Python\Python311\Lib\site-packages\kivy\base.py", line 334, in dispatch_input
post_dispatch_input(*pop(0))
File "C:\Users{USER}\AppData\Local\Programs\Python\Python311\Lib\site-packages\kivy\base.py", line 302, in post_dispatch_input
wid.dispatch('on_touch_up', me)
File "kivy_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "C:\Users{USER}\AppData\Local\Programs\Python\Python311\Lib\site-packages\kivy\uix\behaviors\button.py", line 179, in on_touch_up
self.dispatch('on_release')
File "kivy_event.pyx", line 727, in kivy._event.EventDispatcher.dispatch
File "kivy_event.pyx", line 1307, in kivy._event.EventObservers.dispatch
File "kivy_event.pyx", line 1231, in kivy._event.EventObservers._dispatch
File "C:\BOTWHeightmap_Project\gen_map_gui.py", line 138, in generate
self.hmap.generate()
File "C:\BOTWHeightmap_Project\gen_map_gui.py", line 98, in generate
create_image(tl, br, self.lod, str(int(time.time())))
File "C:\BOTWHeightmap_Project\generate_map.py", line 76, in create_image
draw_map(grid_tl, grid_br, detail, img, mdb)
File "C:\BOTWHeightmap_Project\generate_map.py", line 62, in draw_map
draw_grid(grid_tl, (x, y), detail, image, mdb)
File "C:\BOTWHeightmap_Project\generate_map.py", line 40, in draw_grid
h = h.tostring()
^^^^^^^^^^
AttributeError: 'array.array' object has no attribute 'tostring'`

@DiabloFox
Copy link
Author

DiabloFox commented Jun 1, 2023

So it seems like the newer version of Python (since Python 3.9) array.array: tostring() and fromstring() methods have been removed. So I will try to install an older version 3.8.8 and see if it fix.

I found a similar issue here

@simonkhoury1
Copy link

simonkhoury1 commented Jun 17, 2023

I encountered this myself and asked chatgpt

The error message you encountered is related to the tostring() method, which is no longer available in the array.array module. The tostring() method has been deprecated since Python 3.9.

To fix the error, you can use the modified code snippet:

=============================
def draw_grid(grid_tl, grid_xy, detail, image, mdb):
name = '5' + str(detail)
grid_z = z_from_xy(grid_xy, mdb)

name += format(grid_z, '0>8X')
file = None
try:
    file = open('terrain/' + name + '.hght', 'rb')
except:
    return

h = array.array('H')
h.fromfile(file, 65536)
h = h.tobytes()  # Modified line
temp = Image.frombytes('I;16', (256, 256), h)

grid_rel_x = 256 * (grid_xy[0] - grid_tl[0])
grid_rel_y = 256 * (grid_xy[1] - grid_tl[1])
image.paste(temp, (grid_rel_x, grid_rel_y))

file.close()

========================
After making this change, the 'array.array' object has no attribute 'tostring' error should be resolved.

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