-
Hi,
thanks for your answer, the example functions above are indeed not good, but in my game the game is idle if no input has happened and it never garbage collects, however i now found out this issue only appears in the emulator in the browser on the pc, when i tested it on the device itself with my game it works fine but somehow in the espruino ide and emulator using same code from my game when calling bangle.buzz never gets freed and eventually when enough buzzes had past even with very long delays between input and code execution it never garbage collects it.
I should have tested on the device first but i was mainly developping in the ide with the emulator as it works a bit faster.
I still don't know why the emulator does not free the memory. but i have created a better example code:
each time you do a touch on the screen memory keeps increasing and never gets released in the emulator, i did touches with pauses in between until memory was exhausted and it did not garbage collect. On the device itself it actually behaves fine and memory remains stable but in the emulator in my chrome browser it does not and keeps increasing until enough buzzes have been done for the memory to be exhausted
if you comment bangle.buzz the issue never happens
var memStart; memStart = process.memory(true); function doBuzzer(e) { Bangle.buzz(1,1); var memTmp = process.memory(true); var used = memTmp.usage - memStart.usage; print(": Udiff:"+ used.toString() + " used:" + memTmp.usage.toString() + " free:" + memTmp.free.toString() + " total:" + memTmp.total.toString() ); } Bangle.on("touch", doBuzzer);
-
Hi,
in my game when i call Bangle.buzz free memory keeps decreasing until it runs out of memory. I noticed in the documentation it says it returns a promise but i'm not familiar with them and i don't know how i should use Bangle.buzz so it does not keep eating free memoy or how to free the memory from probably the returned promise.
for example when testing i tried this code and it runs out of memory when doing this resulting in an error:
var memStart; memStart = process.memory(true); for(i = 0; i < 1000; i++) { Bangle.buzz(1,1); var memTmp = process.memory(true); var used = memTmp.usage - memStart.usage; print(i.toString() + ": Udiff:"+ used.toString() + " used:" + memTmp.usage.toString() + " free:" + memTmp.free.toString() + " total:" + memTmp.total.toString() ); } for(i = 0; i < 1000; i++) { Bangle.buzz(1,1); var memTmp = process.memory(true); var used = memTmp.usage - memStart.usage; print(i.toString() + ": Udiff:"+ used.toString() + " used:" + memTmp.usage.toString() + " free:" + memTmp.free.toString() + " total:" + memTmp.total.toString() ); } for(i = 0; i < 1000; i++) { Bangle.buzz(1,1); var memTmp = process.memory(true); var used = memTmp.usage - memStart.usage; print(i.toString() + ": Udiff:"+ used.toString() + " used:" + memTmp.usage.toString() + " free:" + memTmp.free.toString() + " total:" + memTmp.total.toString() ); }
I'm not sure if i'm doing something wrong here but it shows something like this as a result
... ... 369: Udiff:11929 used:11972 free:28 total:12000 370: Udiff:11934 used:11977 free:23 total:12000 371: Udiff:11939 used:11982 free:18 total:12000 Execution Interrupted at line 4 col 33 var memTmp = process.memory(true); ^ New interpreter error: LOW_MEMORY,MEMORY > >
-
Hi,
I just received my bangle js2 today, i already got a game going but the original images are a bit small so i wanted to scale them.
initially I had an image consisting of 126 seperate images. this image was 8x1008 (so 1 tile = 8x8). I used the image converter to make a 1 bit image object out of it but i changed the width and and height both to 8 and then i could use the frame option to display a single tile from this bigger image and it displayed fine when drawing single frames or "tiles"
However i have now resized my image to 10x1260 so one tile is 10x10 but somehow this is now producing weird results when using drawBitmap with the frame: option, the images it draws seem distorted now
i could not find an example that used the frame option so i'm not sure if changing the height portion from 1008 or 1260 to 8 or 10 is the way to use this but i'm not sure how else i could produce frames of data
Basically i want to draw a smaller portion of a bigger image only and i thought frame could be used for that but it only seemed to work when i used a 8x8 tilesize not when using a 10x10 tilesize and i'm not sure where i went wrong or if i'm misusing the frame option.
Can someone show me an example on how to use the frame option from drawImage where width and height of a single "frame" is 10x10 in an image that is a multiple of that.
edit: is it possible this is a bug ?
I have included the image as attachment as well as the code i used so the original image was 10x1260 yet somehow imageMetrics is only returning 121 frames while it should report 126 frame if i change width and height to 10.
Or does frame only work for byte aligned sizes ? like 8, 16, 24, 32, etc for width & height ?{ var blockTiles = { width : 10, height : 10, bpp : 1, buffer : atob("MgyPP88AAA88yDIMgAAA///wAADzzIMgyDIMjyPIAgCPIMgyDIAAAP4/gCAI8gyDIMgyDI8/zwAAD/wAAAAAAAD///AAAP/AAAAAMgyPI8gCAI/gAAAAAAAA/j+AIAj+AAAAADIMgzzPMAwDPMgyDIAAAD/P8wDAM8yDIMgyDIMgyDIMgyDIMgyAAAA+D4MgyDIMgyDIMgyDPM8wDAP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ZBgPQBBkIQhEAuMFBkGA8AAAAAAAAAAAAAAAAD4f5znOc5zn+Pg+AADAMAwDAMAwDAMAwAB+H4BgGH4cB+H4fgAH4fgGAYfgGH4fh+AABgOD4Ph2H4BgGAYAB+H4cBwH4Bh+H4fgAHAcB+H4fh2H4fh+AAfh+AYBgMDgOA4DgAB+H4dh2H4dh+H4fgAH4fh2HYfgGH4fh+AAf5/nOc5/n+c5znOAB+H+c5znYc5/n4fgAH4fhwHAcBwH4fh+AAfB+HOc5znOfh8HwAB+H4cBwH4cB+H4fgAH4fhwHAfB8HAcBwAAP5/nAcB3nOf4+D4AB2HYfh+H4dh2HYdgAAwDAMAwDAMAwDAMAAP4/gYBgGHYfg8DwAB3nefh+H4fh3ned4AHAcBwHAcBwH4fh+AAQFx3ve9/3Xcdx3HABznuf5/nec5znOc4ADwfh2HYdh2H4PA8AAfB+HYdh+HwcBwHAAA+H+c5znOc5/j+P4AHwfh2HYdh8HYdh2AAPh+HgeA8AYfh8HwAB/n+DAMAwDAMAwDAAHYdh2HYdh2H4fh+AAdh2HYdh2HYfg8DwABx3Hcdx3Hdd/zuO4AHOc5/n+DB/nOc5zgAc5zn+f4+AwDAMAwAB+H4BgGAwOB+H4fgAAAOA4DgAA4DgAAAAAPhDk2TZDk2Q4+D4AAEAI+b5gBAH5gIAgED4c5Nk2QZNk2Pg+AAf7z8HweAfP8/z/Pf5/vv+f54BgH5/v+9/n+8/z/P8+AcH8/z3+f738fx+AYBx/3/ff4+HeR5Hned5Dj4PgAD4R57nud5PkOPg+AA") }; print(g.imageMetrics(blockTiles)); //reports: >{ "width": 10, "height": 10, "bpp": 1, "transparent": false, "frames": 121 }
edit 2: it seems if i use 8bpp it produces correct results
{ const blockTiles = { width : 10, height : 10, bpp : 8, buffer : require("heatshrink").decompress(atob("AAP//4DCBJgHBBIgAGB445TDpJFRBJY7VAB5j9Y7AJMKowJMDpbH2BJhj9Y7BgIMxiLRDqwAdHZJFdMdLHYBJgrGBJjE4HZhFPMe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HaZFNACCnLBKIndADqBJGpACDAYIJQDqZnHXpLHWCRQvKJAgJHFaQcEDpYaKBBzHJGArHbCaIJGY7qNFWYycJGyAvMGxQJYAgkPDBoFKGShjITppBPV5JJST85jLNZTHVMaYWIBKDHUE5LGQMZabJZhQWGBJjqLDpRqLaxKHHRxJjGJ5ZGEBJxZJGYxjm")) }; print(g.imageMetrics(blockTiles)); //reports: >>{ "width": 10, "height": 10, "bpp": 8, "transparent": false, "frames": 126 } >
ah good to know it does not happen with you in the emulator (on pc / browser)
this is what i get and it never decreases but on the bangle itself it works fine
I'll see if i can pinpoint something on my pc / browser that can affect this, just to be sure you ran the code in the emulator or on the bangle itself ? the emulator is where i seem to have the issue