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

Non-integer randomheight value will result in crash #871

Open
jkctech opened this issue Mar 18, 2024 · 0 comments
Open

Non-integer randomheight value will result in crash #871

jkctech opened this issue Mar 18, 2024 · 0 comments
Labels

Comments

@jkctech
Copy link

jkctech commented Mar 18, 2024

Blender and OS versions

Windows 11
Blender 3.6.5

Describe the bug

Crash on calculating random building heights when using non-integer like number (0.5, 0.3, etc.) instead of (1, 5, 42, etc.)

How to Reproduce

Select a piece of map
Try to get OSM data with provided settings:

9e8684c72dd73d40c981228db4d3df9e

Error message

Because of the non-integer value of the random height, random.randint() fails because they get resulted into floats:

Python: Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\Blender 3.6\3.6\python\lib\random.py", line 303, in randrange
    istart = _index(start)
TypeError: 'float' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\JKCTech\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\BlenderGIS-master\operators\io_import_osm.py", line 681, in execute
    self.build(context, result, geoscn.crs)
  File "C:\Users\JKCTech\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\BlenderGIS-master\operators\io_import_osm.py", line 443, in build
    seed(way.id, way.tags, pts)
  File "C:\Users\JKCTech\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\BlenderGIS-master\operators\io_import_osm.py", line 287, in seed
    offset = random.randint(minH, maxH)
  File "C:\Program Files\Blender Foundation\Blender 3.6\3.6\python\lib\random.py", line 370, in randint
    return self.randrange(a, b+1)
  File "C:\Program Files\Blender Foundation\Blender 3.6\3.6\python\lib\random.py", line 309, in randrange
    raise ValueError("non-integer arg 1 for randrange()")
ValueError: non-integer arg 1 for randrange()

Managed to quickly fix it by manually casting the resulted values to an integer:

offset = random.randint(int(minH), int(maxH))

at line 287 of operators/io_import_osm.py

@domlysz domlysz added the easyfix label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants