Jump to content


Photo

Totally stumped by instance_exists bug


  • Please log in to reply
10 replies to this topic

#1 Erik Leppen

Erik Leppen

    GMC Member

  • GMC Member
  • 2028 posts
  • Version:GM:Studio

Posted 08 March 2012 - 03:54 PM

So I have the following code in my Step event.

///Check collision line - guy
var g;
if passenger = noone {
g = collision_line(x, y, ropebridgestation_left.x, ropebridgestation_left.y, guy, false, false)
show_debug_message(string(g) + " -- " + string(instance_exists(g)))
if g != noone {
if g.x > ropebridgestation_left.x and g.x < x {
passenger = g
g.onrope = true
}
}
}

(sorry for the missing indentation, blame the forum software)

The code is executed from ropebridgestation_right. There is an instance in the room of ropebridgestation_left and I want to check collision on the line between the two stations for characters (object name guy).

If you ask me, this is correct code.

I run my game in Windows C++ runner, and as soon as one of the characters crosses the bridge the game simply shuts down itself. The console form states this:

-4 -- 0
-4 -- 0
-4 -- 0
-4 -- 0
100954 -- 0
############################################################################################
VMError!! Occurred - Push :: Execution Error - Variable Get x
at Object.ropebridgestation_right.Step.0 (line -1) - <unknown source line>
############################################################################################
Local Variables :
100119( g ) = 100954.000000

You see a bunch of debug messages and then the error I don't understand. -4 is noone, the output of collision_line when there is no collision. The 0 tells me that indeed, instance_exists(noone) is false. That explains the -4 -- 0.
Then the collision occurs. The g in the above code becomes an instance id, here 100954. I have checked that this is indeed the id of the colliding guy (debugger says so). In fact it is an instance of another object that has guy as the parent object. This should not matter, because the id is correct, so collision_line works correctly on the parent object. However, instance_exists(100954) return false! That explains why "g.x" bugs out, But why!?!? is instance_exists(100954) false if 100954 is clearly the id of an existing instance?

In the original code of course I don't like the "g != noone". I prefer if instance_exists(g). But if I use that, simply nothing happens, because instance_exists keeps returning false.

Anyhow. My guess was that instance_exists is not working here. So I ran a little test to see if instance_exists works correctly. I set up a simple test sample containing two objects. One looks for collisions on the other. The code in the test controller:

var g;
if passenger = noone {
g = collision_line(x, y, mouse_x, mouse_y, object0, false, false)
show_debug_message(string(g) + " -- " + string(instance_exists(g)))
if g != noone {
if g.x > x {
passenger = g
}
}
}

Looks like pretty much the same code to me.

The compile form:

-4 -- 0
-4 -- 0
-4 -- 0
-4 -- 0
-4 -- 0
100002 -- 1

What? The bug is not in instance_exists? Why suddenly now it does work, and why doesn't it in my actual game?

I have only one question.

What is going on?!?
  • 0

#2 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14385 posts
  • Version:GM:Studio

Posted 08 March 2012 - 10:27 PM

I can only see this will crash if g is something but that something other than noone and does not exist. it makes no sense.

change the code to
passenger = noone;
g = collision_line(x, y, mouse_x, mouse_y, object0, false, false)
with(g)
{
if(x > other.x)
{
other.passenger = id;
}
}


Other things may be happening. are you deactivating stuff? if so where?
  • 0

#3 Erik Leppen

Erik Leppen

    GMC Member

  • GMC Member
  • 2028 posts
  • Version:GM:Studio

Posted 09 March 2012 - 09:09 AM

I can only see this will crash if g is something but that something other than noone and does not exist.

This never happens. g is either -4 (noone) or the id of an existing instance. The debug messages confirm this.

it makes no sense.

Exactly...

change the code to
passenger = noone;
g = collision_line(x, y, mouse_x, mouse_y, object0, false, false)
with(g)
{
if(x > other.x)
{
other.passenger = id;
}
}

This sounds like a smart move. So I did this. The whole with loop is simply not executed. Even if g is the correct id. I tested this with another series of debug messages.


Other things may be happening.

Sure, it's a game :P Lots of things are happening ;)

are you deactivating stuff? if so where?

Yes, in the room start event.

 
By the way. I suddenly realize I have a very similar object in another part of the game (another room) that does work. The code in that object is
var g;
if passenger = noone {
g = collision_line(x, y, glidecordstation_bottom.x, glidecordstation_bottom.y, guy, false, true)
if g > 0 {
passenger = g
g.onrope = true
}
}

Looks to me like the exact same code. And the exact same circumstances except it's another room. I tested with the same guy (it is a persistent object).



It's getting weirder each run :blink:

Edit: all of this is just in Windows C++ runner. I'm only going to test this in HTML5 if it works here first.

Edited by Erik Leppen, 09 March 2012 - 09:24 AM.

  • 0

#4 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14385 posts
  • Version:GM:Studio

Posted 09 March 2012 - 08:33 PM

At least the with command ensures it not blowing up.

The first thing I would do is remove any instance deactivation you have

You have persistent objects in the room right? are they deactivated by any chance? If you run out of the room, those would normally follow you, apparently when you deactivate those, weird things happen, and you cant get those instances back.

Same thing with persistent room you exit and come back, any object that were still deactivated when you exited will be gone when you come back.


There is a slim chance this is a problem you are experiencing.

The other misbehavior is about deactivating instances in the create and in the draw event.


Get rid of instance deactivation for now. My spider senses are telling me this is the best shot in the dark you have.

Or have a controller object that instance_activate_all on room end

[edit]
Could it be that html5 introduced a bug where collision check includes deactivated instances
  • 0

#5 Erik Leppen

Erik Leppen

    GMC Member

  • GMC Member
  • 2028 posts
  • Version:GM:Studio

Posted 09 March 2012 - 10:13 PM

The first thing I would do is remove any instance deactivation you have

yeah maybe that's the best idea to be sure it's not that.

The "weird things" you're talking about, are they already known or suspected for C++ runner specifically? Because in the original Delphi runner (the one in 8.1 and GM:html5) everything works. The C++ runner behaves differently. That's the reason I put the topic here, and not just in the Q&A section :)

You have persistent objects in the room right? are they deactivated by any chance? If you run out of the room, those would normally follow you, apparently when you deactivate those, weird things happen, and you cant get those instances back.

Same thing with persistent room you exit and come back, any object that were still deactivated when you exited will be gone when you come back.


There is a slim chance this is a problem you are experiencing.

The other misbehavior is about deactivating instances in the create and in the draw event.


Get rid of instance deactivation for now. My spider senses are telling me this is the best shot in the dark you have.

Or have a controller object that instance_activate_all on room end

Right now I only de-activate in Room Start and Game Start, and activate in Room End. The rooms are persistent, but I assume that by activating on Room End, I leave no de-activated instances behind. Also, I can switch rooms and the deactivated characters are just there when they should, and aren't when they shouldn't. The only problem in my whole game (right now) is that collision_line issue, and it occurs for one object and not for the other.

Could it be that Studio introduced a bug where collision check includes deactivated instances

Very improbable, because the output value of collision_line is either -4 or the id of an active instance and it does the latter at exactly the correct moment. However, something's wrong if with(100954) does nothing and (100954).x is an unknown variable, while at the same time my instance reports that id = 100954. I'd guess that this has little to do with activation or not.

But you're right that there's only one way to rule it out for sure..... man this is gonna cost time :confused:

Anyhow, I appreciate you thinking along, I know how hard it can be if you can't look at the code :)
  • 0

#6 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16791 posts
  • Version:GM:Studio

Posted 09 March 2012 - 10:19 PM

May I suggest that you file a bug report and include a *.gmz of the file? You can mark it is private so that only we at YoYo can see the file if you are worried about your game being seen by others... Itīs just that if this is ONLY in the c++ runner and it works in delphi (8.1 and html5) then it sure sounds like a problem under the hood.
  • 0

#7 alexandervrs

alexandervrs

    GMC Member

  • GMC Member
  • 417 posts
  • Version:GM:Studio

Posted 09 March 2012 - 10:26 PM

I get a VM error when I do:

instance_create(idonotexistyet.x,idonotexistyet.y,makeme);

when an instance of the object "idonotexistyet" is not present in the room.

If I do:

if (instance_exists(idonotexistyet)) {
    instance_create(idonotexistyet.x,idonotexistyet.y,makeme);
}

is all good.
But shouldn't GameMaker handle this check automatically?

Edited by alexandervrs, 09 March 2012 - 10:27 PM.

  • 0

#8 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14385 posts
  • Version:GM:Studio

Posted 09 March 2012 - 10:26 PM

If it ran fine in 8.1, it's definitely an engine bug
  • 0

#9 Erik Leppen

Erik Leppen

    GMC Member

  • GMC Member
  • 2028 posts
  • Version:GM:Studio

Posted 11 March 2012 - 09:22 AM

OK, so I got rid of all instance deactivation and reactivation stuff (it was unwieldy anyway, I now just juse a boolean variable to check if they're "there" or not).

...bug persists.

So it's NOT an issue about instance (de)activation! :no:

I'll look if I can create a simple example exhibiting the problem.

Edit: there's another inconsistency that I can't pinpoint, this time between HTML5 (faulty) and the other two (working correctly), that looks like the gravity is ten times stronger in HTML5.

Edited by Erik Leppen, 11 March 2012 - 09:32 AM.

  • 0

#10 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14385 posts
  • Version:GM:Studio

Posted 11 March 2012 - 07:52 PM

The second shot in the dark could be investigating your objects that are persistent

I hate these kinds of fluky bugs.
  • 0

#11 Erik Leppen

Erik Leppen

    GMC Member

  • GMC Member
  • 2028 posts
  • Version:GM:Studio

Posted 26 April 2012 - 10:00 AM

I totally forgot about this when I went doing other stuff, but I checked again and the bug is still there. I have now reported it so at least YYG knows about it. I have stripped the project to the smallest I could get it without changing the behavior of the bug itself, unfortunately it is still a pretty large project with a lot of things going on. But at least I stripped all unnecessary intellectual property: sprites, backgrounds, levels that don't contain the buggy objects, etc. etc. I also made the file public because I don't really care about "my code being stolen" - it's not like what's left of it is worth stealing anyway - after all it doesn't work :P so yeah. Go ahead and take it if you can :P

People who have GM:Studio installed are invited to check out the file and run it and see if they could find the problem. Maybe it is a user error that I'm simply overlooking. Or maybe you want to fiddle with the code to see if you could pinpoint the source of the problem further.

Note: I'm talking Windows C++ runner only. Don't care yet about HTML5 and other platforms - this is code that should work, and I want it to work on C++ runner first.

The bug report is here: http://bugs.yoyogame...iew.php?id=2986
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users