Please login or register.

Login with username, password and session length
Advanced search  

News:

Forum rules - please read before posting, it can save you a lot of time.

Author Topic: WME crashes with Array's and dynamic Object's  (Read 3721 times)

0 Members and 1 Guest are viewing this topic.

adonf

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
    • View Profile
WME crashes with Array's and dynamic Object's
« on: April 10, 2006, 05:04:26 PM »

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

Code: Text
  1. #include "scripts\base.inc"
  2.  
  3. // here comes the stuff which initializes the scene
  4. actor.SkipTo(400, 400);
  5. actor.Direction = DI_DOWN;
  6. actor.Active = true;
  7.  
  8. // minigame globals
  9. global TestGame;
  10.  
  11. ////////////////////////////////////////////////////////////////////////////////
  12. // scene state
  13. global Statetestcrash;
  14.  
  15. // default values
  16. if(Statetestcrash==null)
  17. {
  18.   Statetestcrash.Visited = false;
  19.  
  20.   TestGame = new Object("scenes\Room\scr\testcrash.script");
  21. }
  22.  
  23. ////////////////////////////////////////////////////////////////////////////////
  24. // run game
  25. while (TestGame.GameState != "end")
  26. {
  27.         TestGame.Update();
  28.         Sleep(50);
  29. }

Code: Text
  1. #include "scripts\base.inc"
  2.  
  3. Initialize();
  4.  
  5. method Initialize()
  6. {
  7.         this.DropObjects = new Array();
  8.         this. frames = 0;
  9. }
  10.  
  11.  
  12. method Update()
  13. {
  14.         this.frames = this.frames + 1;
  15.        
  16.         var drop_array = this.DropObjects;
  17.  
  18.         // create objects at frames 2 and 4
  19.         if (2 == this.frames)
  20.         {
  21.                 Game.LOG("creating toto1");
  22.                 var toto1 = new Object("scenes\Room\scr\bogus.script");
  23.                 drop_array.Push(toto1);
  24.         }
  25.         else if (4 == this.frames)
  26.         {
  27.                 Game.LOG("creating toto2");
  28.                 var toto2 = new Object("scenes\Room\scr\bogus.script");
  29.                 drop_array.Push(toto2);
  30.         }
  31.  
  32.         var j;
  33.         var cur_drop;
  34.         for  (j = 0 ; j < drop_array.Length ; j = j+1 )
  35.         {
  36.                 cur_drop = drop_array[j];
  37.                 // In real life we would do something with cur_drop
  38.                 // but to make the runtime crash we simply need to reference it.
  39.         }
  40.  
  41.         // print the content of drop_array
  42.         Game.LOG("frame num " + this.frames);
  43.         Game.LOG("Size and content of drop_array:");
  44.         Game.LOG(drop_array.Length);
  45.         var i;
  46.         for  (i = 0 ; i < drop_array.Length ; i = i+1 )
  47.                 Game.LOG(drop_array[i]);
  48. }


Code: Text
  1. #include "scripts\base.inc"
  2.  
  3. // object position
  4. this.PosX = 0;
  5. this.PosY = 0;
  6.  

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:
Code: [Select]
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
Code: [Select]
---------------------------------------------------------
---------- 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

Logged
I am the Milkman. My milk is good.

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: WME crashes with Array's and dynamic Object's
« Reply #1 on: April 10, 2006, 07:29:13 PM »

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 ?
WME does reference counting on the dynamically created script objects. And, yes, there was a bug, which was causing the objects to be released prematurely under certain conditions (you managed to meet...).

I (hopefully) fixed the bug now. Please check this fixed wme.exe (1.6beta2).
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

adonf

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
    • View Profile
Re: WME crashes with Array's and dynamic Object's
« Reply #2 on: April 11, 2006, 10:07:06 AM »

Thanks for the answer and the fix !

By the way, I managed to work around the bug by using a local variable inside the "for" block instead of a variable that is local to the whole function. Hmm, I guess this doesn't make any sense, so here's an example:

Code: Text
  1.         var j;
  2.         var cur_drop;
  3.         for  (j = 0 ; j < drop_array.Length ; j = j+1 )
  4.         {
  5.                 cur_drop = drop_array[j];
  6.                 // do something here
  7.         }
  8.  

Code: Text
  1.         var j;
  2.         for  (j = 0 ; j < drop_array.Length ; j = j+1 )
  3.         {
  4.                 var cur_drop = drop_array[j];
  5.                 // do something here
  6.         }
  7.  

... maybe this will be of some help...


« Last Edit: April 11, 2006, 11:53:48 AM by adonf »
Logged
I am the Milkman. My milk is good.

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: WME crashes with Array's and dynamic Object's
« Reply #3 on: April 11, 2006, 11:38:06 AM »

just from the sight of it, the double declaration of cur_drop looks like a bug to me though.
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

adonf

  • Regular poster
  • ***
  • Karma: 0
  • Offline Offline
  • Posts: 124
    • View Profile
Re: WME crashes with Array's and dynamic Object's
« Reply #4 on: April 11, 2006, 11:54:48 AM »

oops, bad cut and paste. i just edited the code
Logged
I am the Milkman. My milk is good.
 

Page created in 0.089 seconds with 99 queries.