Jump to content


Photo

Mysterious Missing Global


  • Please log in to reply
5 replies to this topic

#1 Rexhunter99

Rexhunter99

    GMC Member

  • GMC Member
  • 922 posts

Posted 22 February 2012 - 10:35 PM

Okay so, if you got this far, thanks, really appreciate your time.

I was developing a DLL to extend Game Maker's 3D capabilities via OpenGL, dubbed it GM_OGL just so it had a name and it was going fine, I took a month or two break from it and have come back with a fresh perspective and some new ideas to optimize the DLL some (and finish the incomplete features) but all of a sudden I can't even run the GMK/GM81 file or EXE they produce with the DLL and I distinctly remember it working last time I opened the project.

I opened the game maker file (GMK at the time) and had a quick look at the code and sure enough, it was set up properly, my DLL initialization script was called well and truly before ogl_start (which is where the error is occurring, global._ogl_start doesn't exist according to the interpreter within ogl_start(), but I am 100% sure it DOES exist) I moved ogl_init() to the game start event, then back to the create event, both cases ogl_init() should be called before ogl_start() and it should have created global._ogl_start so I did some quick variable existence checking within GML, no errors there, global._ogl_start exists within ogl_init(), I ran it in debug mode, ignored the error and global._ogl_start exists in the global variable listing as well so ogl_start() is refusing to find the variable which is infuriating.

This is occurring in GM8.0 and GM8.1 regardless of what I do.

I even tried rebuilding the DLL, I double checked the definitions for the function names in the DLL, cross referenced them with my GameMaker strings and even the function names within the C++ source code.

I am at my wits end with this problem, having spent a good two hours this morning on my day off trying to sort it out with zero luck. I hope someone might catch the problem here with a sharp eye and point it out for me, and if it is something I have done someplace, make a fool of me please.

Here is a link to the GMK/GM81 and DLL files, you don't need the source to the DLL because I have tested the DLL with a C++ compiled EXE.

http://www.mediafire...2irsrc9bfm9vhn2
  • 0

#2 iam1me

iam1me

    GMC Member

  • GMC Member
  • 380 posts
  • Version:GM8

Posted 23 February 2012 - 01:33 AM

Insert this code at the top of your create event code for your control_GL object:

show_message("Creating control_GL...");
if(variable_global_exists("_ogl_start")) show_message("!");
else show_message("...");

This code displays "..." showing that _ogl_start hasn't been initialized prior to the create event of this instance. It then proceeds to try to call the ogl_start() script, causing your error.

Edited by iam1me, 23 February 2012 - 01:34 AM.

  • 0

#3 Medusar

Medusar

    GMC Member

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

Posted 25 February 2012 - 10:50 AM

This is what's causing your issue:

It is important to understand what exactly happens when you move to a particular room in the game.

  • First, in the current room (if any) all instances get a room-end event. Next the non-persistent instances are removed (no destroy event is generated!).
  • Next, for the new room the persistent instances from the previous room are added.
  • All new instances are created and their creation events are executed (if the room is not persistent or has not been visited before).
  • When this is the first room, for all instances the game-start event is generated.
  • Now the room creation code is executed.
  • Finally, all instances get a room-start event.


Point is that game start events are actually executed after the instances in the first room are created (in other words, after their create events are executed). I always found this really annoying because I wanted to use the game start event to initialise things I would need in the create events, just like you. But anyway, that's what's causing your problem.
  • 0

#4 Rexhunter99

Rexhunter99

    GMC Member

  • GMC Member
  • 922 posts

Posted 25 February 2012 - 09:22 PM

This is what's causing your issue:

It is important to understand what exactly happens when you move to a particular room in the game.

  • First, in the current room (if any) all instances get a room-end event. Next the non-persistent instances are removed (no destroy event is generated!).
  • Next, for the new room the persistent instances from the previous room are added.
  • All new instances are created and their creation events are executed (if the room is not persistent or has not been visited before).
  • When this is the first room, for all instances the game-start event is generated.
  • Now the room creation code is executed.
  • Finally, all instances get a room-start event.


Point is that game start events are actually executed after the instances in the first room are created (in other words, after their create events are executed). I always found this really annoying because I wanted to use the game start event to initialise things I would need in the create events, just like you. But anyway, that's what's causing your problem.


Wow, thanks for that, added a new line to check if ogl_init() was succesful and if not call it again in the create event. But that really is a misleading event name, you'd think game_start would occur before the main game loop within the runner source code wouldn't you? (that's where I'd execute it)
  • 0

#5 Medusar

Medusar

    GMC Member

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

Posted 26 February 2012 - 09:27 AM

My thoughts exactly, I always hated this behaviour but it can be elegantly circumvented with a loading screen at the start of the game.
  • 0

#6 paul23

paul23

    GMC Member

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

Posted 26 February 2012 - 04:28 PM

My thoughts exactly, I always hated this behaviour but it can be elegantly circumvented with a loading screen at the start of the game.

Actually I think it is most logical: the creation event should be seen as a "constructor". Before creation event is fired an instance isn't completely constructed (and accessing instance-variables shouldn't be done). So executing "events" before creating is finished has simply no meaning. The only things you should do are things that can be done globally (by a controller's create event?).
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users