Using debugger for a fatal error -- do I need to crash and rebuild every time?

I'm trying to fix a stubborn error in my game. When encountered, it generates a fatal error (it says it's trying to access an instance that doesn't exist, even though the debugger clearly shows an instance with that index). Here's my current workflow:
  • Run in Debugger
  • Wait 25 seconds for the game to build
  • Step through code in the debugger and try to learn something. Eventually get a fatal error.
  • Watch the game crash
  • Manually kill the debugger
  • Run in debugger again
  • Step through code, trying a slightly different sequence of actions
  • Crash again
  • Repeat...

After 10 or 20 rounds this becomes very time consuming. Am I missing some feature of the debugger that would make this easier, e.g., by letting me restart the game, or step backwards, or get an interactive prompt? Or do I just need to crash and rebuild every time?

(I see there's a "restart game" button in the debugger, but when I press it, the game tries to complete the current function call and crashes anyway).

[update: upon request I'm adding the error message I'm getting, though if anyone has advice on how to use the debugger more effectively I'm very interested in that as well.]

Code:
ERROR!!! :: ############################################################################################
FATAL ERROR in
action number 1
of Mouse Event for Left Pressed
for object OTableSlot:


Unable to find any instance for object index '100147'
 at gml_Script_generateItemOnTable (line 7) -     contents = itemObj;
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_generateItemOnTable (line 7)
called from - gml_Script_tableItem (line 17) - generateItemOnTable(itemObj, id);
called from - gml_Object_OTableSlot_Mouse_4 (line 4) - tableItem();
I'm looking at the debugger and under "all instances" there is an instance with ID 100147.
 
Last edited:

TheouAegis

Member
They are should be telling you at what point the instance doesn't exist but is looking for one. You find that line. Then you put a break point on the line before it.

Post the full, complete error message. more than likely what you have going on, without a scene with the error message actually is, is you are trying to pass an object ID or you destroyed an instance before code finished running. Since you said there is an instance in the room that you can see, that suggests that you destroyed an instance before the code which needs to read from it has finished running.
 

samspade

Member
Thanks; I've added the error message to the post. If you have any thoughts on this specific problem, they would be welcome!
It says that on line 7 of (I think) generateItemOnTable which is being called from tableItem from line 4 of your left pressed mouse event in object OTableSlot you're trying to access an object that doesn't exist anymore. I would look at the instance id and figure out what it is supposed to be and then look for any code that could destroy that item.

You could also post the code in the script that is causing the problem, but there might not be anything wrong with it beyond there being a bad reference to an instance.
 
Thanks! I've stepped through the code while watching the instances tab of the debugger, and both before and immediately after the error I can see that there's an instance with ID 100147. Should that generally indicate that the instance does exist and other objects should be able to reference it? Or do you know of any way it could be showing up in the debugger but not exist in memory at the time it's being referenced?

One strange thing I've noticed is that just before the line where the error occurs, the cleanup code for some other objects is executing, including the object that's calling the function referenced in the error message. However, that object also still appears in the debugger at the moment the error occurs.

If I don't find a solution soon, I'll try to create a minimal reproducible example and post code for that.
 
Put some code just before the line that give you the crash:

Code:
if ( instance_exists(itemObj) )
{
    show_debug_message("Item Exists");
}
If you don't get the debug message, then that instance has been destroyed already, regardless of what the debugger is showing - it could be that it was destroyed in the same event as the code that is causing the error.

Note the following from the manual for instance_destroy()

It is worth noting that when you destroy an instance, its destroy event is called immediately after the code or action that calls the destroy. Second, although the destroy event is performed, the instance is not immediately removed from the game, and it will continue to perform the code contained in the current event. Only when the current event is over will it be removed from the game.
So an instance can be destroyed but still *possibly* be in memory until the end of the event.
 
Yep, looks like that's it. The object is (for unrelated reasons) destroying itself just before the line in question, but the debugger wasn't updating so it looked like it was still there.

Ironic that in this case the debugger was making things much harder to debug, and all I really needed was a good old-fashioned print statement. Thanks for helping me figure it out!
 
Top