Runtime Error stacksize 8mb

Hello
currently i am trying to build a Tower Defense Game but unfortunatly the game every time i start it gives shortly after a error "Runtime Error stacksize 8mb"
I tried solving that issue for many hours but nothing worked i always got that error (I thought maybe there were just too many things running at the same time so i also tried making timers a lot slower but that didnt worked)
I couldnt find a solution in the Internet or what causes it (I even deinstalled the game and restarted my phone as mentioned in an other forum post but that didnt worked either)
I am using a lot of -to procedure do- and -call procedure- i read somewhere else that there is a limit on how many times you can call a procedure but i dont know how trustworthy that is
if that is true is there a way to increase or remove that limit?

Welcome,

It seems you are running out of memory. Maybe because you switch your screens wrong of maybe you have large assets like images. So you have to tell more about your project.

1 Like

The entire game runs on one screen (but i have two empy screens) and i am only using two pictures at the moment (picture of blue and black) (i want to do the graphics when the code is finished) so i dont think that the pictures are the issue
I discovered that the error appears when enemys spawn so either there is something wrong with displaying a 20x20 pixel image, the enable feature of sprites, or procedures and calling them
I cant imaginge that something else causes that problem because when i made my first tower defense game everthing worked fine and now in version 2.0 i worked with those things and the error appears

Can you share your aia?

How do you do that?:sweat_smile:

You can upload your exported aia by using the above button when you make a post.

Ok and what is meant by aia? The game file?

Your project source file. You can grab it under the My Projects menu.

image

1 Like

You have an endless loop in your code.

2 Likes

I am using three timers that tick very fast (intervall of 10, 50 and 100) They are not the issue because i changed them and it still gave me the error
and i am pretty sure that i dont have any loop in my code but in a second i can look

TowerDefense.aia (60.3 KB)

(All the Variable names and texts are in german)

TowerDefense.aia (60.3 KB)

I notice 2 things about your blocks:

  • You have not used the if/then/elseif/elseif/elseif ... facility yet (the bluebutton in the if/then block) , giving you vary deep block structures:

    That can stack your run time memory deep.
  • You have very repetitious code. Your blocks look like a box of combs.

    You can reduce your block count by 90% by using the Any (generic) blocks, procedure parameters, and lists of component blocks.

sry i dont fully understand that i thought about removing some things but because each block is for a different enemy i have to use multiple scripts or i create a large block that checks which enemy called that block (i am not from england so i dont know how to explain that better hope you understand it) and i dont think that that would be smaller than the current setup or am i not aware of something that solves this issue?

right now i only know the basics of programming so thank you for helping me :slight_smile:

Here are some sample for you to study, to see the power of lists and procedures.

Bullet Cloud:

http://ai2.appinventor.mit.edu/?galleryId=5858910198693888 (the eight queens problem)

How to Shuffle Balls on a Canvas - Google Docs (to make multiple sprites move on their own power)

How to replace multiple Clocks with a single Clock:
https://groups.google.com/g/mitappinventortest/c/BOj2-ThEe3s/m/VlmXdcVOAgAJ?pli=1

Hello Teragorn

You have your Clock Timers set to "Timer always Fires". These are system timers, you really do not want them to fire all the time unless they have to even when the App is not on Screen. Note that Android system timers are low priority, so they are not overly accurate. Best to use as few as possible.

When I run the App under the Companion, it crashes after a short while and locks the Companion. The GUI does not fit well on my Phone, I can't get to all of the buttons. This is because you are using pixels rather than % to size the components in the 'top bar'.

I notice you have used a Table Component to hold everything in the top bar - this is a problem because unfortunately the Table Component has issues. My advice is to avoid using it, use Horizontal Arrangements instead. I have not heard of a Table causing a memory error but it would not surprise me if it did.

It is better in this case to setup your Timers (interval, enabled/disabled) in a procedure called at the end of the Screen Initialize Block (not via the attributes palette). There should not be any timers running before the Screen has finished initializing.

Anywhere you need to number a variable, e.g. GegnerMovement1, GegnerMovement2 etc, use a List instead (think of a List in this context as being an array). You have used Procedures (good) but they repeat the same code for different sprites (not so good).

For example, you currently have ten Procedures for "Gegner Deaths". This could be just one, thus:

GegnerDeath

And this Timer Block:

...... can be like this:

Reducing all the duplications will:

  1. Reduce memory used
  2. Make the code easier to follow/understand
  3. Enhance game efficiency

So, I have had a go at reducing the Block Count using "AnyComponent" and Lists.

Original Block Total: 1263
Edited Block Total: 717

However, I'm not 100% sure of what your buttons do because:
a) Their names are in German
b) I can't see the whole GUI on my phone (see my previous post)

I have increased the Blocks total by 24 to add an Error Catcher. It does catch an error where a Sprite ID is expected but an Integer is received. Maybe I have mixed the Gegner number with the Gegner ID somewhere, you will probably spot it. The memory size error does not show up.

This is as far as I have got:

TowerDefense_Edit.aia (42.6 KB)

It's very late here and I am away from my PC for most of tomorrow (Tuesday, UK time)

If anyone else is to help you, it would be good to fix the GUI......

Nearly forgot. This alone could cause memory issues.

The images used for the Sprites are far too big. Since the Canvas and Sprites must be measured in pixels, the images for the Sprites should be the exact finished size (e.g. 20 x 20px).

2 Likes

Btw, this is what the app looks like on one of my test devices (Galaxy Note8):

In addition, the app should only be able to be used in portrait mode.

What @ChrisWard last said is especially important to avoid memory issues.
Always create images in the size / resolution that is actually required in the app.