Hi,
First of all, I recently discovered WME and I'm really impressed by the amount of good work that was put into it. You did a truly amazing job, Mnemonic !
I'm working on a simple minigame to be included in an adventure game and I'm getting a crash in wme.exe when my scripts add dynamic game objects to an Array. I made a simple project that documents that, I'll post the code at the end of this message. Actually, adding the dynamic objets seems to work, but when I try to read the array's first element the executable crashes.
I tried it with v. 1.6b2 and 1.5.2, both crash. Is it something that I did wrong ?
I suppose it might have something to do with objects being freed when they're still referenced, which leads me to my next question:
How does object deallocation work in WME ? I couldn't find any documentation about it, is there some kind of garbage management that frees unreferenced objects and kills the scripts that run on them ? I know that nobody really cares about memory management on the PC
but still, it would be nice for me to stop the scripts once a minigame has stopped.
Thanks
Olivier
#include "scripts\base.inc"
// here comes the stuff which initializes the scene
actor.SkipTo(400, 400);
actor.Direction = DI_DOWN;
actor.Active = true;
// minigame globals
global TestGame;
////////////////////////////////////////////////////////////////////////////////
// scene state
global Statetestcrash;
// default values
if(Statetestcrash==null)
{
Statetestcrash.Visited = false;
TestGame = new Object("scenes\Room\scr\testcrash.script");
}
////////////////////////////////////////////////////////////////////////////////
// run game
while (TestGame.GameState != "end")
{
TestGame.Update();
Sleep(50);
}
#include "scripts\base.inc"
Initialize();
method Initialize()
{
this.DropObjects = new Array();
this. frames = 0;
}
method Update()
{
this.frames = this.frames + 1;
var drop_array = this.DropObjects;
// create objects at frames 2 and 4
if (2 == this.frames)
{
Game.LOG("creating toto1");
var toto1 = new Object("scenes\Room\scr\bogus.script");
drop_array.Push(toto1);
}
else if (4 == this.frames)
{
Game.LOG("creating toto2");
var toto2 = new Object("scenes\Room\scr\bogus.script");
drop_array.Push(toto2);
}
var j;
var cur_drop;
for (j = 0 ; j < drop_array.Length ; j = j+1 )
{
cur_drop = drop_array[j];
// In real life we would do something with cur_drop
// but to make the runtime crash we simply need to reference it.
}
// print the content of drop_array
Game.LOG("frame num " + this.frames);
Game.LOG("Size and content of drop_array:");
Game.LOG(drop_array.Length);
var i;
for (i = 0 ; i < drop_array.Length ; i = i+1 )
Game.LOG(drop_array[i]);
}
#include "scripts\base.inc"
// object position
this.PosX = 0;
this.PosY = 0;
Instructions: just create an default project with a scene called 'Room' and save the files into data\scenes\Room.
Oops, almost forgot the log file:
17:58: frame num 1
17:58: Size and content of drop_array:
17:58: 0
17:58: creating toto1
17:58: frame num 2
17:58: Size and content of drop_array:
17:58: 1
17:58: [object]
17:58: frame num 3
17:58: Size and content of drop_array:
17:58: 1
17:58: [object]
17:58: creating toto2
17:58: frame num 4
17:58: Size and content of drop_array:
17:58: 2
and the crash log file
---------------------------------------------------------
---------- WME crash report: 10-04-2006, 17:58 ----------
---------------------------------------------------------
wme.exe caused a EXCEPTION_ACCESS_VIOLATION in module wme.exe at 001B:00431CE2
EAX=00000000 EBX=00AE2BF8 ECX=00D6CFB8 EDX=FFFFFFFF ESI=00D6B5B8
EDI=00579BFC EBP=00D6CAB0 ESP=0012F598 EIP=00431CE2 FLG=00010246
CS=001B DS=0023 SS=0023 ES=0023 FS=003B GS=0000
Stack trace:
001B:00431CE2 (0x00020002 0x010E01F5 0x00D67FF8 0x00AE01B8) wme.exe