Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (EternallyCurious, howardR), 646 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Error E1516: Invalid memory area #440040
04/16/14 13:03
04/16/14 13:03
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Hey all,

Lately I got this invalid memory area error popping up, never had it before. A bit frustrating cause I wanted to release a demo of my project soon on this site cry.

The error happens only when I create an item after an enemy dies. E.g. I can create tons of items when the enemy is alive and when there is no enemy etc and get no error. And the strange thing is that it is kindy random, but does seem to always happen when killing a large group of enemies.

I will try to keep the code as short as possible here.

First the code after the enemy dies:

Code:
//update monsters left
 if ((connection & CONNECT_SERVER) || connection == 0) {
 monsters_left -= 1; send_var(monsters_left); }
 //drop item
 if ((connection & CONNECT_SERVER) || connection == 0) enemy_createitem();	
 //decay	
 ...		
 you = ent_createlocal("MDL_BloodSplatGreen.mdl",vector(my.x,my.y,my.z-16),bloodsplat);
 wait(-15);
 var decay_time = 0;
 while (1) { my.z -= 0.1; decay_time += time_step;
 if (decay_time >= 100) break;
 wait(2); }	
 ent_remove(me);



The code that creates item (when I write 'NULL' for the actions of the items, I get no error):

Code:
function enemy_createitem()
{ 
   var i;
   for(i = 1; i < 9; i++) {
  	 if (pointer_player[i]) {
  	  if (random(100) >= 66) you = ent_create("MDL_BonusHealth.mdl",vector(my.x,my.y,my.z+40),item_healthbonus);
  	  else { if (random(100) >= 50) you = ent_create("MDL_BonusArmor.mdl",vector(my.x,my.y,my.z+40),item_armorbonus); 
  	         else { you = ent_create("MDL_BonusSpeed.mdl",vector(my.x,my.y,my.z+40),item_speedbonus); } 
  	       }
  	   you.STATE = i;
  	   send_skill_to(pointer_player[i],you.STATE,0);
  	 }
   }	
}



And the code of the item (I added the Sys_marker after the errors began, don't really no if it has any effect at the moment):

Code:
action item_speedbonus()
{
sys_marker("ITS");	
if (connection & CONNECT_SERVER) my.smask |= NOSEND_FRAME | NOSEND_ANGLES | NOSEND_ALPHA | NOSEND_AMBIENT | NOSEND_COLOR | NOSEND_FLAGS | NOSEND_SCALE | NOSEND_SKIN; 	
while(connection != 0 && my.client_id < 0) wait(1);	
ent_sendnow(my);
wait(1);	
my.smask |= NOSEND_Z;
set(my,INVISIBLE | PASSABLE);
my.group = 5; //world and items
while(my.STATE == 0) wait(1);
 
 //make item visible for only one player
 while(!player) wait(1);
 if (player == pointer_player[my.STATE]) reset(my,INVISIBLE);
	
vec_scale(my.scale_x,0.8); 	 	
if (!is(my,INVISIBLE)) my.material = mtl_specBump;	

while(1)
{	
 if (!is(my,INVISIBLE)) {	
  ...
 }

 if (my.STATE != 0) {
  if (pointer_player[my.STATE]) {	
	if (vec_dist(my.x, pointer_player[my.STATE].x) < 100) {
	 if (connection == 2) { ... }
	 if ((connection & CONNECT_SERVER) || connection == 0) { ...
	 break; }
	}
  }
 }		
wait(1);
}	
ent_remove(me);
}



I runned in diag, below is the acklog file:

Html:
Log of A8 Engine 8.40.3 run at Wed Apr 16 14:22:41 2014
SKYNET on Windows NT/2000/XP version 6.1 Build 7601
Options Test.c -diag -te
App: D:\Tools\GStudio8\acknex.exe in D:\Tools\GStudio8\SKYNET's games\TEST\

MM mixer opened
DSOUND device opened
DI interface opened
Start Window opened(c) Conitec - www.3dgamestudio.com
A8 Engine - Commercial Edition V8.40.3 - Sep  2 2012
Development version
Registered to: SKYNET, ALL YOUR CODE BELONG TO US

Mouse found
Speakers (Realtek High Definition Audio) opened
NVIDIA GeForce 310M  pure T&L device 1ff9 detected
D3D device NVIDIA GeForce 310M  1ff9 selected.
PATH data\
ackAR.dll opened
acknet.dll opened
ackoal.dll opened
ackphysx.dll opened
ackwii.dll opened
Compiling TEST.C - [Esc] to abort..
PATH D:\Tools\GStudio8\code\
PATH D:\Tools\GStudio8\templates\images\.........
PATH D:\Tools\GStudio8\data\
PATH D:\Tools\GStudio8\data\..
PATH D:\Tools\GStudio8\data\................................................... 3.622 sec
Running TEST.C.
38 objects
Main started at 4.866
D3D_Init Window: 720x480 -> Window: 1x720x480x32
Video memory found: 1734 MB
D3D_Resize Screen: 1366x768 -> Screen: 1x1366x768x32
LevelInit at 5.253
275 entities 0 cameras 3 lights 0 sounds 0 paths
 50 lmaps 12 textures 530 meshes 809 submeshes 28361 faces
Nexus overflow at 34592200...ok
LevelReady at 6.378
mtlfx_startup started
def_startup started
Pointers_startup started
Interface_startup started
globalvars_startup started
Main loop at 6.770....
1st frame with 1734 MB.. at 7.922
HEADRELATIVE sound: 1
Malfunction W1516: Invalid memory area def_debug
Program aborted



Thanks for taking the time! I more code or info is needed, I can add it (I tested alot already).

Re: Error E1516: Invalid memory area [Re: Reconnoiter] #440063
04/17/14 12:01
04/17/14 12:01
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
God this error message is so annoying, it does not give any me any helpfull info. I should probably use sys_marker some more than, could someone tell me how I could use sys_marker effectively? I have a feeling I am doing something wrong with it...

Re: Error E1516: Invalid memory area [Re: Reconnoiter] #440073
04/17/14 16:04
04/17/14 16:04
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline
Serious User
DLively  Offline
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
Hi laugh Really sorry to hear about this!!

Here goes a shot in the dark...

I organized the create function differently..
You mention that it doesn't happen when you apply NULL to the actions in the create function, maybe the error is in on of the items?

Code:
function enemy_createitem()
{ 
   var i;
   var random_num = 0;
   for(i = 1; i < 9; i++) {
         if(player_pointer[i]){
         random_num=random(100);
         randomize();
         if (random_num >= 66) {you = ent_create("MDL_BonusHealth.mdl",vector(my.x,my.y,my.z+40),item_healthbonus);}
         if (random_num < 66 && random_num >= 50) {you = ent_create("MDL_BonusArmor.mdl",vector(my.x,my.y,my.z+40),item_armorbonus); }
         if (random_num < 50) { you = ent_create("MDL_BonusSpeed.mdl",vector(my.x,my.y,my.z+40),item_speedbonus); } 

         you.STATE = i;
         send_skill_to(pointer_player[i],you.STATE,0);
      }
   }
}


Last edited by DLively; 04/17/14 16:04.

A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
Re: Error E1516: Invalid memory area [Re: DLively] #440119
04/18/14 11:22
04/18/14 11:22
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Well first thanks DLively for commenting, I really appreciate the help.

Ugh I just got the error even when I removed the drop item lines. I tested this alot earlier when I removed the drop item lines and than I did not get a error. This error is getting really random. Although I did get it a bit later.

So far the observations (and this is getting a bit weird crazy ):
- it is occures randomly after an enemy dies, but the more ent_creates I seem to place/call when the enemy is dying/decaying (so after the break of the main loop of the enemy) the faster I get ther error.

The manual tells this about the error:
Quote:

Error E1516: Invalid memory area

A function such as ptr_remove, ent_remove, or sys_free was called with an invalid or already-freed pointer; or an allocated memory area was overwritten by a damaged file or script bug. This error is only issued if the warn_level variable is set to 2 or above. You can use the sys_marker function to find out where the memory area was allocated.


Not always when the crash occures an ent_remove is called (and I have no ptr_remove and sys_free in my script), so I doubt that is the problem. Which leads to the sentence talking about allocated memory area was overwritten by a damaged file or script bug. I doubt it are damaged files, since I use them alot already, so probably it is a script bug. I don't really know what qualifies here as a script bug, it sounds to me as it could be everything lol.

To me it screams like to much happens after the enemy dies. Maybe something else starts creating the problem and the code like creating the item etc. is the last straw?

ps: randomize is obsolete by the way and is replaced by random_seed wink.

Re: Error E1516: Invalid memory area [Re: DLively] #440128
04/18/14 17:37
04/18/14 17:37
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Originally Posted By: DLively

Code:
random_num=random(100);
randomize();



Originally Posted By: Reconnoiter
ps: randomize is obsolete by the way and is replaced by random_seed wink.


Amongst other things. The code has a much bigger flaw, however: Reseeding the rng over and over again is bad.

The rng works by using the seed to seed its initial state, and on each "random()" invocation, the state is mutated. Lets assume for a second "random()" uses a good rng engine (Mersenne Twister), reseeding it over and over again takes entropy out of the result and also changes the quality of the produced random numbers, which will stop being uniformly distributed (if that was a quality of the rng to begin with). The long story is: You get very bad "random" numbers.

Even worse though: Usually the time is used as a seed, which is enough of an entropy source for most applications that don't require any cryptography. However, it's usually just the seconds that are taken, now, since random_seed() is a black box, it's a fair assumption that this is also the case here. What's bad about this, is that your function takes MUCH less than a second, which means: You seed the rng with the same seed over and over again.

This is a pseudo random number generator we are talking about here, there is no entropy system anywhere that feeds into it, it's absolutely deterministic if you know the seed. This means, seeding it the same seed over and over again means that it will generate the same numbers over and over again.

The bad thing about random numbers is that they stop being random once you look at them. Basically, you are robbing yourself of random numbers.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Error E1516: Invalid memory area [Re: WretchedSid] #440279
04/22/14 12:15
04/22/14 12:15
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
I can't get sys_marker to work. For testing purposes, I place sys_marker at the beginning of the script (naming it "AAA"). I run the script as 'test run', have 'diag' marked on in preferences in SED and have set dplay_diag = 1. But when I look at the acklog.txt, I can't find 'AAA' anywhere. ?? crazy

Re: Error E1516: Invalid memory area [Re: Reconnoiter] #440282
04/22/14 15:53
04/22/14 15:53
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
AFAIK you have to set warn_level to at least 4 in order to see those warnings in the log file.


Always learn from history, to be sure you make the same mistakes again...
Re: Error E1516: Invalid memory area [Re: Uhrwerk] #440292
04/22/14 19:30
04/22/14 19:30
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Thanks for commenting.

I have set it to 6, nothing in the log yet.

Code:
dplay_diag = 1;
sys_marker("AAA");
warn_level = 6;



Ps: does anyone ever had a memory problem like this? If so, could you share your experiences with it? I would be really gratefull.
I ask this cause I don't understand this error, I can't seem to find the cause (/broken code) of it. And I can't seem to reproduce the error now (probably due to the error's randomness).

Re: Error E1516: Invalid memory area [Re: Reconnoiter] #441469
05/24/14 10:44
05/24/14 10:44
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Sorry for necroing this thread, but I might have finally found the cause of the memory error and thought it could be usefull for others who have the same problem. I had 'effect_local' in my events. I overlooked the parts in the manual where it says:
Quote:
- it shouldn't perform instructions that can trigger events itself, displace entities, start particles
. Hopefully that is indeed the cause of the error.


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1