Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | path9263 |
I am playing around with generating voxels in Godot. I’ve just been using GDScript so far to build a prototype. I was looking into ways to use less memory when dealing with lots and lots of voxels and came across PoolByteArray since GDScript does not seem to have a byte type. It looks promising but it’s not working for me.
The problem I’m having is that any array with more than 65536 indexes that contains PoolByteArrays crashes the game. If the array contains normal arrays it works just fine. Example of what I mean below… Also please see my edit at the bottom.
The following code works fine:
var tstArr = []
var randNumber
func _ready():
for i in 65536:
randNumber = randi() % 23
var NormalArr = [1, randNumber]
tstArr.push_back(NormalArr)
print(tstArr.size()) # prints "65536" as expected
This code however crashes, the debugger I don’t think even gets to start, it doesn’t report any errors anyway:
var tstArr = []
var randNumber
func _ready():
for i in 65536:
randNumber = randi() % 23
var bytPool = PoolByteArray()
bytPool.push_back(1)
bytPool.push_back(randNumber)
tstArr.push_back(bytPool)
print(tstArr.size())
However if in the above code I change for i in 65536:
to for i in 65535:
then it runs fine.
I’m not sure if this is a bug or if I am doing something wrong. I don’t have a great concept of how the PoolByteArray actually interacts with the computer’s memory but I suspect that could have something to do with this.
Any info or tips you can provide are greatly appreciated! Thanks!
EDIT: I’ve also discovered that there seems to be a limit to the number of PoolByteArrays even when they are contained in separate arrays.
var testArrOne = []
var testArrTwo = []
var randNumber
var maxNum = 65535
func _ready():
for i in maxNum:
randNumber = randi() % 23
var bytPool = PoolByteArray()
bytPool.push_back(1)
bytPool.push_back(randNumber)
testArrOne.push_back(bytPool)
for i in maxNum:
randNumber = randi() % 23
var bytPool = PoolByteArray()
bytPool.push_back(1)
bytPool.push_back(randNumber)
testArrTwo.push_back(bytPool)
The above does not work but if you change it to var maxNum = 32767
(half of the limit) or less, it does work. This is starting to seem more like a bug.
Again, thanks for any insight you can provide!