• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

SOLVED Need help confirming a possible bug

Status
Not open for further replies.
J

Jaysin

Guest
Hi,

I'm Jaysin, I've been using GMS2 (IDE: 2.2.5.481 /// Runtime: 2.2.5.378) for the past few weeks after having initially tried it 2 years ago. I enjoy it a lot, but I've come across an issue that I'm concerned may be a bug. I'm getting a crash in the GMS2 Runner and when I build a Windows executable. The crash is 100% reproducible and seems to occur when my oPlayer object collides with the position of a pMonster object that has already been destroyed.

I'm trying to think how best to explain this since I'm relatively new and don't know the best way to share my code, so I apologize if this is a little messy. To start, I'm working on an RPG and I'm currently tackling the turn based battle system. I'm coding in GML.

As I mentioned, I have 2 main objects involved in the crash, oPlayer and pMonster (or in this case a child object of pMonster called oFire). pMonster has logic in it's Step event to move towards oPlayer if oPlayer is within a certain range. pMonster also has a Collision event for oPlayer that sets pMonster to persistent (oPlayer is already persistent), takes note of some variables for both objects as well as the current room, re-positions both objects for the battle room, and goes to a room called rBattle.

From here an object called oBattle takes over that controls the turn based battle system. Currently the battle system only allows running, for which I wanted to let pMonster return to the original room and be "dazed" or something so oPlayer can run away, but I also wanted to test defeating pMonster. pMonster has a Room Start event that destroys it if a boolean "defeated" is true. I setup the Run option in oBattle to set pMonster to defeated before returning to the original room, thus destroying pMonster when the room starts and because it was persistent it doesn't spawn a second pMonster where the first one originally was.

Now here's the problem. After doing this, if you move oPlayer to the position pMonster would be in the room, the Runner and Executable crash. Output in the IDE states "FAILED: Run Program Complete" and says to review the log, but there's nothing there short of a warning about the "Collision" layer not being present in some rooms (my oGame object disables it on Room Start so I can be lazy when making rooms). I thought somehow pMonster was still being created despite the persistence change so I checked with the debugger and there was no pMonster (oFire actually) present, its like I have something to collide with triggering the event but no actual instance, so it just crashes?

I tried searching for related issues or existing bugs, but couldn't find anything exactly related. I'm not sure if I can post my project or anything (again, still really new) and my code spans a couple scripts. I'm concerned that I may have done something in my code that is causing the crash, but I tried using breakpoints to pinpoint where and couldn't locate anything. Nonetheless, before I submit a bug report to YYG, I wanted to check with others in case I did do something stupid that is causing this.

Please let me know if I've done something wrong with this post, or if I should include any further information. Sorry in advanced if I did something wrong here, still learning.

Thank you,
Jaysin
 

flyinian

Member
If you try to reference something and it doesn't exist, it'll crash the game.

Your code could be referencing the layer you disabled and can't find it so, it freaks out and crashes.
 

Roldy

Member
Hi,

I'm Jaysin, I've been using GMS2 (IDE: 2.2.5.481 /// Runtime: 2.2.5.378) for the past few weeks after having initially tried it 2 years ago. I enjoy it a lot, but I've come across an issue that I'm concerned may be a bug. I'm getting a crash in the GMS2 Runner and when I build a Windows executable. The crash is 100% reproducible and seems to occur when my oPlayer object collides with the position of a pMonster object that has already been destroyed.

I'm trying to think how best to explain this since I'm relatively new and don't know the best way to share my code, so I apologize if this is a little messy. To start, I'm working on an RPG and I'm currently tackling the turn based battle system. I'm coding in GML.

As I mentioned, I have 2 main objects involved in the crash, oPlayer and pMonster (or in this case a child object of pMonster called oFire). pMonster has logic in it's Step event to move towards oPlayer if oPlayer is within a certain range. pMonster also has a Collision event for oPlayer that sets pMonster to persistent (oPlayer is already persistent), takes note of some variables for both objects as well as the current room, re-positions both objects for the battle room, and goes to a room called rBattle.

From here an object called oBattle takes over that controls the turn based battle system. Currently the battle system only allows running, for which I wanted to let pMonster return to the original room and be "dazed" or something so oPlayer can run away, but I also wanted to test defeating pMonster. pMonster has a Room Start event that destroys it if a boolean "defeated" is true. I setup the Run option in oBattle to set pMonster to defeated before returning to the original room, thus destroying pMonster when the room starts and because it was persistent it doesn't spawn a second pMonster where the first one originally was.

Now here's the problem. After doing this, if you move oPlayer to the position pMonster would be in the room, the Runner and Executable crash. Output in the IDE states "FAILED: Run Program Complete" and says to review the log, but there's nothing there short of a warning about the "Collision" layer not being present in some rooms (my oGame object disables it on Room Start so I can be lazy when making rooms). I thought somehow pMonster was still being created despite the persistence change so I checked with the debugger and there was no pMonster (oFire actually) present, its like I have something to collide with triggering the event but no actual instance, so it just crashes?

I tried searching for related issues or existing bugs, but couldn't find anything exactly related. I'm not sure if I can post my project or anything (again, still really new) and my code spans a couple scripts. I'm concerned that I may have done something in my code that is causing the crash, but I tried using breakpoints to pinpoint where and couldn't locate anything. Nonetheless, before I submit a bug report to YYG, I wanted to check with others in case I did do something stupid that is causing this.

Please let me know if I've done something wrong with this post, or if I should include any further information. Sorry in advanced if I did something wrong here, still learning.

Thank you,
Jaysin
Post the relevant code here in the forum to get help. Post it in the programming forum.

When posting use the code button on the toolbar. The button looks like this </>

It will format your code nicely like

GML:
var someVariable = 10;

for (var i = 0; i < someVariable; i++) {
    // do stuff
}
Think about what code is relevant. Probably the move or collision events for your objects.
 
I'm also just going to put this out there: very rarely are game crashes related to bugs in GMS itself. It isn't impossible, but 99% of the time when someone new to coding thinks that GMS has a bug, the real bug is the code that they have written and GMS is working exactly as intended in regards to the incorrect code.
 
J

Jaysin

Guest
Thank you kindly for the replies, I'll address each of them here and if it still sounds like I messed up the code, I'll request this be moved to Programming or create a new post there and request this one be closed.

Firstly the Collision Layer. Some rooms didn't have a Collision Layer (2 rooms, rInit and rBattle). As a test I added a Collision layer to both to eliminate the warnings and the crash still occurs, so it has nothing to do with the Layer not being present.

Now for the code, here's the pMonster Collides with oPlayer code:

GML:
/// @desc Enter Battle Room

// Make Enemy Persistent
persistent = true;

// Obtain Current Posititions
originX = x;
originY = y;

// Move to Battle Room Positions
x = RESOLUTION_W * 0.75;
y = RESOLUTION_H * 0.5;

with (oPlayer) {
    // Obtain Current Positions and Room
    originX = x;
    originY = y;
    originRoom = room;
    encounterMonster = other.object_index; // Probably not needed
    encounterLevel = other.level; // Probably not needed
    
    // Move to Battle Room Positions and Lock Player
    x = RESOLUTION_W * 0.25;
    y = RESOLUTION_H * 0.5;
    image_index = 0;
    state = PlayerStateLocked;
}

// Room Transition
room_goto(rBattle);
And pMonster Room Start:

Code:
/// @desc Destroy if Defeated
if (defeated) {
    persistent = false;
    instance_destroy();
}
So what happens is the oPlayer collides with pMonster and we go to the Battle Room after making pMonster persistent. I chose to make pMonster persistent so when we return to the originRoom after the battle we don't spawn a new pMonster. When we return to originRoom pMonster comes with us, but is then destroyed if "defeated" was true. This does happen as I checked with breakpoints and instance_destroy() was called and pMonster (oFire) was removed from the Instances list. But if I then move oPlayer to the position pMonster (oFire) spawns to, the game crashes, almost like I collided with a non-existent instance.

Here's a Gif of the crash. Note the crash only happens when you move to the position that pMonster would be if it was allowed to respawn.

Lastly, I know how its likely I've done something wrong, I cannot determine why this is happening as there's now nothing in the logs and debugging shows no objects in that position I move to that causes the crash. Which is why I was concerned it may be a bug and would like help identifying that. If its determined that it is indeed my code, I will seek help in the Programming forum.

Thank you,
Jaysin
 
J

Jaysin

Guest
I'm sorry for the double post, but I have an update.

I reproduced the issue with the most minimal code I could think of. 3 objects, 2 rooms, 5 events spread across the 3 objects, I could reduce the lines of code further, but there doesn't seem to be a need to. Here's what I have:

oPlayer, represented by a 64x64 blue square and placed in rStart. oPlayer is persistent by default.
oMonster, represented by a 64x64 red square and placed in rStart. oMonster is not persistent by default.
oBattle, which has no sprite and is placed in rBattle. oBattle is not persistent.

oPlayer Step Event:
GML:
/// @desc Move Player

// We don't want the player to move in the battle room
if (room != rBattle) {
    // Get inputs
    keyLeft = keyboard_check(vk_left);
    keyRight = keyboard_check(vk_right);
    keyUp = keyboard_check(vk_up);
    keyDown = keyboard_check(vk_down);
    
    // Apply movement
    x += keyRight - keyLeft;
    y += keyDown - keyUp;
}
oMonster Create Event
GML:
/// @desc Defeated Variable
defeated = false;
oMonster Collision with oPlayer Event
GML:
/// @desc Go to Battle Room

// Move player to prevent further collisions
oPlayer.y -= 64;

// Make persistent and go to Battle room
persistent = true;
room_goto(rBattle);
oMonster Room Start Event
GML:
/// @desc Destroy if defeated
if (defeated) instance_destroy();
oBattle Step Event
GML:
/// @desc Go back to Start Room

keySpace = keyboard_check_pressed(vk_space);

if (keySpace) {
    oMonster.defeated = true;   
    room_goto(rStart);
}
And that's it. When you move oPlayer into oMonster, oMonster becomes persistent and you go to rBattle (oPlayer is moved a bit to prevent more collisions). Pressing Space in rBattle will trigger oBattle to toggle oMonster.defeated to true and room_goto(rStart). When rStart starts, oMonster will destroy itself. There is then no oMonster instances in the room, but if you move oPlayer to where oMonster would be, it crashes. oPlayer is the only object in the room and it only crashes when it moves to the position oMonster would be if it wasn't destroyed.

Here's a Gif of it happening with this code. The only adjustments made in the Gif were to the draw events where each had: draw_self() and draw_text(x,y,"text") for easy identification (oBattle's text includes the message for pressing space).

I can't see anything wrong with the code that would cause a crash like this, so I hope someone more experienced can point out anything I'm missing. I can attach the project for this if it would help, I'm just not sure if I'm allowed to.

Thank you,
Jaysin
 
J

Jaysin

Guest
Last update. I did some more testing and identified that the problem was stemming from the Collision event, not the code, but rather the existence of a Collision event (with no code even) in the project. I submitted a bug report to YYG, providing them with my test project from my last post. I got a reply this morning confirming that it is a bug and that its been fixed in the 2.3.0 beta. I wasn't aware the beta was open now, so I didn't think to try it myself.

I want to thank Roldy and flyinian for at least trying to help me with this with their suggestions. But I wanted to bring up that it is indeed a bug, and its been fixed in 2.3.0 beta should anyone else run into this problem.

I'll report this thread to a mod to be closed.
 
Status
Not open for further replies.
Top