• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Bug, Feature, or am I confused?

samspade

Member
The debugger is one of the few places that I still have unexpected results in 2.3. I have the following code with a breakpoint on the very first line. It stops just fine, however when it does, all of the functions are already declared. That isn't super confusing but what is confusing is that if I click go to next line, the next is the first line of the struct. I ran it several times with the exact same results every time. It skips past all the function calls, in fact, it runs the function calls before it pauses for the breakpoint (i.e. by the time the game stops at the breakpoint, the debugger has already printed the messages).

This doesn't seem right. Am I missing something?

Code:

GML:
//creating method variables BREAKPOINT
say_hello = function() {
    show_debug_message("Hello World");
}   

say_something = function(_msg) {
    show_debug_message(_msg);
}

say_goodbye = function() {
    show_debug_message("Goodbye");
}

say_hello();
say_something("How are you?");
say_goodbye();


//structs
struct_of_stuff = {
    num : 124,
    str : "Hello World",
    my_function : function() {
        show_debug_message("Wow!");
    }
}
 

FrostyCat

Redemption Seeker
This is normal behaviour. In your code, the expressions inside must be evaluated first, then set into keys in the struct literal, then the struct literal gets assigned to the variable. It's like how parameters to a function call are evaluated first, then the function call itself.
 

samspade

Member
That makes sense for the struct literal, but why are my function calls, many lines after my break point, running before my break point is reached? If for example I change my code to the code below, I get almost what I expect. The code stops on the first show debug, runs through the functions, then calls the functions, then for some strange reason jumps back to the show debug message where the break point was set even though it doesn't run it again, then jumps inside the struct. It seems odd that if I have code before I create my method variables and put a breakpoint on it, everything runs mostly fine, but if I don't have that code and put the breakpoint on my first method variable, all lot of the code after my breakpoint runs before the breakpoint is triggered and when I step through the code it skips dozens of lines.

GML:
/// @description Data Types

show_debug_message("test"); //BREAKPOINT

//creating method variables
say_hello = function() {
    show_debug_message("Hello World");
}   

say_something = function(_msg) {
    show_debug_message(_msg);
}

say_goodbye = function() {
    show_debug_message("Goodbye");
}

say_hello();
say_something("How are you?");
say_goodbye();


//structs
struct_of_stuff = {
    num : 124,
    str : "Hello World",
    my_function : function() {
        show_debug_message("Wow!");
    }
}
 

samspade

Member
Well, it definitely appears to be a bug as I can reproduce it in other projects. However, it appears to occur only in very specific instances. It only occurs in the following circumstances as far as I can tell:
  • Your project has one room and one object and the object only has a create event
  • The first code run is a method variable declaration
  • later on there is a struct literal declaration
The result is that you can put the breakpoint on the method variable, but while it will appear to stop there in the debugger, the method and all code prior to the struct will already have been run and you can't step through it. So for example, if you create a new project, create a single object, make only a create event and paste the following code in:

GML:
/// @description Debugger Issue Test


//BREAKPOINT HERE
test_func_a = function() {
    show_debug_message(current_time);
}


test_func_b = function() {
    show_debug_message(current_time);
}


test_func_c = function() {
    show_debug_message(current_time);
}

//run functions
test_func_a();
test_func_b();
test_func_c();

variable = "test";


my_struct = {
    a : 1,
    b: 2,
    c: 3
}
And run the debugger, the debugger will appear to stop on the break point, but the all the method variables will have already been initialized, all the function calls run and the output in the debugger window, and the variable will already have the value test. Click advance to the next line, and you jump from line 5 to line 28.

Put code in front of the method variable and this doesn't happen. There are other things as well that break it. Don't use a struct, it doesn't happen. Use a constructor instead of a struct literal it doesn't happen. And in those cases the expected result will occur (the debugger pauses on the first method variable and then allows you to go through the code line by line, initializing the method variables as you go, running the function calls as you go and then initializing the variable and the struct in order). In certain circumstances, you can change things and then undo the changes and the issue will go away and no longer be reproducible even with the same code.

Overall, very annoying, but also very minor.
 
Top