Pages: 1
  Print  
Author Topic: Odd Var Leak  (Read 984 times)
Offline (Unknown gender) daz
Posted on: February 20, 2014, 01:30:03 AM
Contributor
Joined: Jul 2010
Posts: 167

View Profile
ENIGMA has a weird variable leak that had utterly confused me for a while. I narrowed it as best I could. Let me start by saying I honestly have no idea what is causing this problem. At all.

Reproduce steps:
Create a script with code:
Code: [Select]
w = 777;
show_message("Width: "+string(w));
h = display_get_height();
show_message("Width: "+string(w));
show_message("Height: "+string(h));

Create a room, and in the init code, call the script.
Create an object with an event that calls the script in the room (e.g. spacebar up event).

You'll notice when called from the room creation code, the output is something like "777, 1080, 1080"
But when called from the object, it's "777, 777, 1080"

Somehow in the room creation code the variable w is being overwritten by either h or display_get_height(). I thought this might be a case that somewhere in the room there's an internal variable named w that is fucking up my previously set value.

IDK PLZ FIX THIS IS WIGGIN ME OUT MAN

I tried to look at ENIGMA's code myself but I couldn't find anything immediately obvious in window_set_size or display_get_height so it's probably deeper in ENIGMA's internals than I care to go.

I was bored so I also uploaded a bare minimum example of this sorcery happening: https://dl.dropboxusercontent.com/u/1215621/whatthescope.egm


p.s. using the windows exe uploaded on 2/18 idk what revision that is
Logged
Offline (Male) DaSpirit
Reply #1 Posted on: February 20, 2014, 09:12:27 AM

Member
Location: New York City
Joined: Mar 2013
Posts: 124

View Profile
What application did you use to find the leak? Just wondering, because I didn't know that GCC on Windows had any memory leak detectors (or at least, none that are not commercial).
Logged
Offline (Unknown gender) daz
Reply #2 Posted on: February 20, 2014, 10:06:35 AM
Contributor
Joined: Jul 2010
Posts: 167

View Profile
Leak was probably not a good word sorry. It seems more like a scope issue, wherein somewhere in the room code a var "w" is public to EDL.
Logged
Offline (Male) Goombert
Reply #3 Posted on: February 21, 2014, 04:14:51 PM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3107

View Profile
daz, it wouldn't be in functions, everything is namespaced, I'll try to take a look.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Male) Josh @ Dreamland
Reply #4 Posted on: March 14, 2014, 09:52:39 AM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
Not sure how I missed this topic. The strange behavior in room creation code is because the room creation code is not associated with an object; w and h do not exist, so they end up referring to the same address (instead of referring to NULL and giving you a segmentation fault). This shouldn't be happening, though, as I declare missing variables in room creation codes. Probably some sort of regression.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Pages: 1
  Print