You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following snippet leads to a memory corruption as evident by the output (which changes during each run. It works fine with --newruntime/--gc:arc|orc or --gc:markAndSweep|boehm|go|none|regions.
Example
import rationals
typeProbability=Rational[int]
Tile[n: staticint] =object
a: array[n, Probability]
collapsed: boolMap[w, h: staticint, n: staticint] =array[w, array[h, Tile[n]]]
TileId=intCoord=tuple[x, y: int]
Rule[n: staticint] =tuple[c: Coord, t: Tile[n]]
Discriminator[n: staticint] =seq[Rule[n]]
Tileset[n: staticint] =array[n, Discriminator[n]]
procwaveFunctionCollapse(result: varMap, tileset: Tileset) =echo tileset
echo"XXX: Mem corruption: Rollout!"for id in0..<tileset.len:
for (c, t) in tileset[id]:
echo tileset[id] #XXX: Already corrupt hereprocwaveFunctionCollapse[n: staticint](tileset: Tileset[n], w, h: staticint): Map[w, h, n] =for x in0..<w:
for y in0..<h:
for i in0..<n:
result[x][y].a[i] =1//n
result.waveFunctionCollapse(tileset)
funcprepareTileset(tileset: varTileset) =var additions: Tilesetfor id, tile in tileset:
for rule in tile:
for i, p in rule.t.a:
additions[i].add(block:
var newRule: Rule[tileset.len]
newRule.c = (-rule.c.x, -rule.c.y)
for j in0..<newRule.t.a.len: newRule.t.a[j] =1//1#Init to 1
newRule.t.a[id] = p / tileset.len
newRule)
for id, tile in additions:
for rule in tile:
tileset[id].add rule
#Add self discriminatorfor id, tile in tileset.mpairs:
var newRule: Rule[tileset.len]
newRule.c = (0, 0)
for j in0..<newRule.t.a.len: newRule.t.a[j] =0//1#Init to 0
newRule.t.a[id] =1//1
tile.add newRule
funcprepareTileset(tileset: Tileset): Tileset=result= tileset
prepareTileset(result)
whenisMainModule:
typeTiles=enumAir, Land, Water, Walllet unpreppedTileset: Tileset[4] = [
Air: @[],
Land: @[],
Water: @[],
Wall: @[
( (1, 1) , Tile[4](a: [Air: 0//1, Land: 0//1, Water: 0//1, Wall: 1//1]) ),
( (0, 1) , Tile[4](a: [Air: 0//1, Land: 0//1, Water: 0//1, Wall: 1//1]) ),
( (1, 0) , Tile[4](a: [Air: 0//1, Land: 0//1, Water: 0//1, Wall: 1//1]) ),
],
]
var preppedTileset =prepareTileset(unpreppedTileset)
echo"XXX: Not yet (visibly?) corrupt: ",preppedTileset
discardwaveFunctionCollapse(preppedTileset, 12, 12)
The following snippet leads to a memory corruption as evident by the output (which changes during each run. It works fine with
--newruntime
/--gc:arc|orc
or--gc:markAndSweep|boehm|go|none|regions
.Example
Current Output
Possible Solution
Compiling with
--newruntime
Additional Information
The text was updated successfully, but these errors were encountered: