AGS Engine

Further development of AGS engine

Bug Issue: Passing "this" pointer to script function does not change reference counter

Pages: [1]

Crimson Wizard

  • AGSer
  • Posts: 7,508
« on: 20 Oct 2017, 19:54 »
This is a bug either in script compiler or script interpreter (I suspect latter, but further investigation is required).

It appears that whenever "this" pointer of a managed object is passed to struct's member OR extender function, managed object's reference counter is not getting increased (nor decreased when returning from function). If other remaining references to this object will be nullified during the course of that function, the "this" pointer will be referencing a non-existing object, or any new object created in the meantime.

Script to reproduce:
Code: Adventure Game Studio
  1. DynamicSprite *globalSprite;
  2.  
  3. void TestFunc(this DynamicSprite*) {
  4.   Display("Sprite w: %d, h: %d", this.Width, this.Height);
  5.   globalSprite = null;
  6.   DynamicSprite *localSprite = DynamicSprite.Create(20, 20);
  7.   Display("Sprite w: %d, h: %d", this.Width, this.Height);
  8. }
  9.  
  10. function on_key_press(eKeyCode keycode)
  11. {
  12.   if (keycode == eKey0) {
  13.     globalSprite = DynamicSprite.Create(10, 10);
  14.     globalSprite.TestFunc();
  15.   }
  16. }
  17.  

Expected Display result:
Sprite w: 10, h: 10
Sprite w: 10, h: 10

Actual Display result:
Sprite w: 10, h: 10
Sprite w: 20, h: 20
« Last Edit: 20 Oct 2017, 19:57 by Crimson Wizard »

Issue updated by Crimson Wizard
« Reply #1 on: 20 Oct 2017, 19:58 »
  • Priority changed from 2 to 3

Pages: [1]

Issue Details

  • Reported
    20 Oct 2017, 19:54
  • Updated
    20 Oct 2017, 19:58
  • View Status
    Public
  • Type
    Bug
  • Status
    New
  • Priority
    High
  • Version
    Adventure Game Studio 3.4
  • Fixed in
    (none)
  • Assigned to
    (none)
  • Category
    Scripts

Tags



Powered by: SMF Project Tools 0.5.4 © Niko Pahajoki 2007-2011