HW Errors 021 Followed by 022?

I’m trying to isolate a memory issue with my latest extension, which creates random mazes.

The code I’m using is available in the following image:

arcade-Maze-Extension-Playground

(Load it in beta; the extension doesn’t work on 0.8.11.)

The version of the extension contained in custom.ts uses a common drawing canvas to limit the amount of memory needed. That’s the private static _img: Image property in the Grid class.

The game also removes the breadcrumb sprites in a further attempt to lessen the memory burden.

If I run this program on my BrainPad Arcade, I get a 021 error when I press A (which generates the maze). If, then, I reset the device twice to re-run the game, I get a 022 error instead when I press A. In the error codes page for MakeCode (below), I don’t see a description for the 022 error code. What causes that error code?

Hm, looks like 022 is ‘too big allocation’ https://github.com/microsoft/pxt-common-packages/blob/4a4a14aba87c33c128ae474c2ff1bd013cffc506/libs/base/pxtbase.h#L225. Haven’t actually seen that one, will try to debug to see what’s happening in a bit.

(I would imagine this might come up if you index into an array with an arbitrarily large digit (e.g. arr[1000000000]) as it will have to allocate index * size memory, but I haven’t looked at the code yet / actually tested that though)

1 Like

Ooh … good thought, @jwunderl . Hardware definitely doesn’t like my inefficient indexing in the Cell.getDistances method. I’ve trimmed that a bit. Running into a problem in Distances.getPath, but you have me on the right track.

More soon. Thanks, Joey!

1 Like

Got it working! :slight_smile:

arcade-Maze-HW-Test

Even works with all of the sprites on HW, so you can monitor your score to see if you’re on the right path, just like in the browser.

Now to actually deal with the memory inefficiencies, instead of just working around them… :smiley:

1 Like

I have the memory inefficiencies in the extension reduced well enough without completely changing the data structures. Hardware can now handle mazes up to roughly 16x16, which should be more than large enough for most applications.

I’ll clean up the code and release a sample game after the production version of Arcade gets bumped to a version that can handle this code. For now, though, this only runs in beta. Feel free to play around with it!

arcade-Maze-HW-Test