• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

3D game keeps crashing oddly

Recently i've imported an old GM8.0 first-person shooter game of mine into Studio 1.4. I got the project working fine after removing some obsolete functions and changing some scripts for textures, but the game still crashes oddly sometimes when a room changes, like when you just move to a next room. It doesnt give an error message, it's just the Windows's '<program> has stopped working.' I'm thinking it's got something to do with some old code, that's now gone obsolete, or maybe some string of code that is vital in Studio is missing from my old GM8-era-scripts. I just wanted to check a couple of codes, i think these might just be causing some issues, is there anything wrong with them for Studio 1.4.? Can it be when the game switches to a room with one of these, it crashes?

Draw event of a still object (an NPC):

{
var tex;
tex = sprite_get_texture(sprite_index,image_index);
d3d_draw_wall(x-6*global.camsin,y-6*global.camcos,z1,
x+6*global.camsin,y+6*global.camcos,z2,tex,1,1);
}

Said NPC-object's Collision event with obj_wall:

{
x = xprevious;
y = yprevious;
if (abs(hspeed) >= abs(vspeed) && not place_meeting(x+hspeed,y,obj_wall_basic))
{ x += hspeed; exit;}
if not place_meeting(x,y+vspeed,obj_wall_basic)
{ y += vspeed; exit;}
if not place_meeting(x+hspeed,y,obj_wall_basic)
{ x += hspeed; exit;}
}

I suspect these might just be causing the game to crash, if not, i've gotta see if it's something with the player object. Thanks beforehand (and sorry for long babble)

Edit: Just added one code from player object, i didn't use this back when i did the game in 8.0 and 8.1. I found use for it in Studio since there's some texture clipping errors, so this code i've put in obj_player's Draw event:
{
draw_set_alpha_test(true);
draw_set_alpha_test_ref_value(128);
}
 
Last edited:

Fishman1175

Member
Yeah these kinds of crashes are always so annoying to figure out :squirrel:
Personally I’m not seeing any problem with what you posted...

Did your old project use any extensions? Or DLLs?

If it’s crashing when moving to a new room, check the creation code, room start code, and room end code for any instances in those rooms.

Another thing I would do is set a breakpoint when switching rooms in the debugger and step through line by line until you hit the line that crashes.
 
Last edited:
Yeah these kinds of crashes are always so annoying to figure out :squirrel:
Personally I’m not seeing any problem with what you posted...

Did your old project use any extensions? Or DLLs?

If it’s crashing when moving to a new room, check the creation code, room start code, and room end code for any instances in those rooms.

Another thing I would do is set a breakpoint when switching rooms in the debugger and step through line by line until you hit the line that crashes.
No extensions or DLLs in the project. Now when i tested in debug mode, it even crashes on an earlier room which never crashed earlier. In the debugger it says in the bottom on a red bar 'Target connection lost'. Where it normally says Target running. Its most likely smth to do with the 3D, no idea what yet tho, it seems to happen so randomly and always when it's a 3D room or when a 3D room starts. Might be some performance issue. I didnt know anything about Breakpoints before, but thanks for suggesting, i'll try to test using those now for first time.
 

icuurd12b42

TMC Founder
GMC Elder
I suspect you placed d3d_start in the darn create or room start event...

d3d_start belongs in the draw event... in the first first thing drawn, a dedicated cam object at depth 100000 for example. and d3d_end also, in the last thing drawn, in a cameEnd object at depth -1000000 for example
 
I suspect you placed d3d_start in the darn create or room start event...

d3d_start belongs in the draw event... in the first first thing drawn, a dedicated cam object at depth 100000 for example. and d3d_end also, in the last thing drawn, in a cameEnd object at depth -1000000 for example
Source for that? The manual (gms1 docs) contradicts what you say here. Also, I don't think it could explain a crash.

@Makkeonmies When you run in debug mode, with the source window open, does it show which script was executing when the crash happened?
 

icuurd12b42

TMC Founder
GMC Elder
Me! I'm the source...

the guy who wrote the "Example" in the docs has no experience in 3d matters comparatively and basically copied the mistake most made since gm6 using 3d and placed it in the docs. Why do you think I knew you put the d3d_start in the create without you even mentioning it!!!

Anyone who put graphics stuff, no matter what it is, in the create or room start has never had the experience of **** behaving oddly or worst crashing on them for no reason... I have.


This is not a contradiction. it is a common mistake and a sign of ignorance (in it's true meaning):
Example:
d3d_start();

This code has been placed in the create event of an instance to tell GameMaker: Studio that all further drawing should be done in 3D mode.
You should do the graphics stuff in the draw and nowhere else, if you need to do it elsewhere like drawing on a surface in the end step you must wait for the first draw to have happened so the graphics card is ready. WORST, some graphics features will cause issues if performed within the first 7 frame of the game start, such as buffer_set_surface. A boot room solves this....

Like basically very few will suffer from your misuse unless they are in a situation where their video card and driver exposes this either in a form of a crash or misbehaviour
 
Last edited:

icuurd12b42

TMC Founder
GMC Elder
@icuurd12b42 I'd like to know more about this, becuase your saying it here is the first I've ever heard of d3d_start having this problem.
It's an known issue which I have exposed and warned people about for 8-10 years!!! Yet nobody's listening. Everyone is basing their 3d examples, tutorials, engines off of the few popular originals, this bug has multiplied like a god damned virus.

There is no value calling d3d_start in the create event in the first place! It's not like the call is costly, it does not belong there in the first place.

In my edit, I state the issue is only for some people. The chance of said people also be a developer that experience the issue is slim, but I have and know how to fix it as explained.

Related Issues
Creating a sprite from a surface in a the create event, results in no sprite created
Getting a buffer from a surface or application surface in the create event results in nothing being copied
Setting the application surface size may fail

In gm6,7,8 calling d3d_start without calling d3d_end breaks room transitions

not doing those start and end calls in the draw to set things up and be done with it when your drawing is done can step on the engine's behavior later on, like affect the gui draw, though yoyo has fixed these issues, there is no garanties they have a proper "reset to required settings" before their core code runs.
 

icuurd12b42

TMC Founder
GMC Elder
@Nocturne, can you please correct this d3d_start in create event mention in the document. It is not proper usage.


Anyway. what I said may not be the OP's issue, but it certainly will cause trouble with a few people running the game.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
@Nocturne, can you please correct this d3d_start in create event mention in the document. It is not proper usage.
I'll look into it. Note that if this has been an error for the last 8-10 years, there has been NO bug filed for it. If there had been it would have been fixed... ;)
 
so @icuurd12b42 @flyingsaucerinvasion can the d3d_start() be in the player (camera) object's Draw, or should i create a separate object for d3d_start() entirely, that would be always present in a room where the player (cam object) is?
Also, i traced one crash to an odd issue, apparently the enemy parent object's collission event with obj_wall_parent causes a crash. This didnt happen back in 8.0, first time only now that i test in Studio. If there's any action in enemy parent's collision event with the wall_parent, the game crashes. It can be an action to stop the enemy object, (as intended) but apparently ANY action causes the crash if placed in the collision event (i tested show_message, etc.)
Wall parent's Draw event code, if any help:

{
d3d_draw_wall(x1,y1,z1,x2,y2,z2,tex,1,1);
}

Just throwing guesses here but a) is this function obsolete and somehow causing an error/crash, b) does it have something to with how the d3d is drawn?
 
Last edited:

icuurd12b42

TMC Founder
GMC Elder
I put my d3d_start in my camera draw since it's in charge of starting the whole 3d perspective...

I suggest you change the collision event in that parent to user event 0 or whatever is free. save the project, quit, reload and reset the user 0 event back to the collision event it was set to. it's possible some indices got mixes. this may fix it.
 

icuurd12b42

TMC Founder
GMC Elder
I'll look into it. Note that if this has been an error for the last 8-10 years, there has been NO bug filed for it. If there had been it would have been fixed... ;)
this falls into the same realm as you need a boot room to wait a little before drawing. anyway, if the help shows best practices, this limits people having weirdism happen later
 
and d3d_end also, in the last thing drawn, in a cameEnd object at depth -1000000 for example
Just one more check tho, what do you mean by 'the last thing drawn?' I put d3d_start in player's (camera's) Draw event, but where do i place d3d_end? In what Event, Room End?
 
Well now it's gone really strange again. It crashes now in an even earlier room, with no changes done. The thing is that it actually crashes, (Windows has stopped working) doesnt give an Error. Since it seems so random (now the earlier fix regarding the enemy parent and wall parent doesn't work anymore for some reason) i'm guessing it's the Audio or something in graphics performance. Can the 3D just sometimes crash like this, randomly, if the computer performance drops or smth?

Compile window ends like this upon testing, is there anything indicating smth's wrong?

Attempting to set gamepadcount to 12
Unable to find output device "null" defaulting to "Speakers (Conexant SmartAudio HD) via DirectSound"
Total memory used = 49907916(0x02f988cc) bytes
Pause event has been registered for this frame
Pause event has been unregistered
Pause event has been registered for this frame
Pause event has been unregistered
Pause event has been registered for this frame
Pause event has been unregistered
Compile finished: 20:18:37

Sorry guys, i gotta rely on your help once again, this goes way over my head... it seemed like i found a solution but now the crashes seem pretty random. Like the game is too heavy (plays fine tho) or smth. Damn... i really like this game. Been making it for quite some time, maybe even since Gm7 (with some long ass pauses in between tho) Hopefully will be fixed in the end...!

Edit: still digging into the d3d_start / end, maybe the issue is with that since i've got a lot of switches from 2d to 3d in the game's beginning. also, i have a hunch it COULD be some audio-related issue.
 
Last edited:

Fishman1175

Member
If you were comfortable with sending a PM to me with the project I’d be happy to debug through it and help. I’m afraid I don’t have any other generic suggestions to offer.
 

Joe Ellis

Member
Have you tested other 3d stuff in gms 1.4? Like stuff from scratch, simple tests of the functions? It doesn't look like there's any problems with what you've shown, I'm wondering if there's a problem with your computer, is it old?
 
@Fishman1175 thanks for offer, but i was thinking the project is already quite big, as in lots of rooms and objects, so might prove bothersome. If it doesnt seem to get solved tho, i can mail it to you. @Joe Ellis I have yea, but mostly smaller projects that were also imported from GM8. Had some graphical issues too. This one is working fine otherwise, but this testing recently and trying to get to the root of the crash problems has made me think if it's because of my laptop. I have Windows 8.1. I have two guesses: it's the Audio somehow, since the crashes usually occur after a sound plays, or the 3D-2D switches, since they also occur when the room changes from a 2D to a 3D one.
Does this indicate smth bothersome, during Compile:

Unable to find output device "null" defaulting to "Speakers (Conexant SmartAudio HD) via DirectSound"

If not, it might just not be audio-related but smth to do with the 2d-3d switches.
 

Roa

Member
@icuurd12b42 I have no idea what you are talking about. d3d_start should never be in the draw event because it has nothing to do with how the image is seen in real time, and everything to do with setting up the default values that were once mostly hidden to make sure 3d renders properly. They literally set global values you have no control over.

This is the compatibility script right from GMS2's library. What you don't want to do is be constantly telling the variables that tell the hardware what to do, to constantly update something you are not even changing. You are literally throwing performance away.

d3d_start
Code:
var ret = global.__d3d;
global.__d3d = true;
//camera_apply(global.__d3dCamera);
gpu_set_ztestenable(true);
gpu_set_zwriteenable(true);
return ret;
__init_d3d is a sub of d3d_start
Code:
gml_pragma( "global", "__init_d3d();");
// setup the depth variable to a sensible default
global.__d3d=false;
global.__d3dDepth=0;
global.__d3dCamera=camera_create();
global.__d3dPrimKind = -1;
global.__d3dPrimTex = -1;
global.__d3dPrimBuffer=vertex_create_buffer();
vertex_format_begin();
   vertex_format_add_position_3d();
   vertex_format_add_normal();
   vertex_format_add_colour();
   vertex_format_add_textcoord();
global.__d3dPrimVF=vertex_format_end();
global.__d3dDeprecatedMessage = [ false ];

enum e__YYM
{
   PointB,
   LineB,
   TriB,
   PointUVB,
   LineUVB,
   TriUVB,
   PointVB,
   LineVB,
   TriVB,  
   Texture,
   Colour,
   NumVerts,
   PrimKind,
   NumPointCols,
   NumLineCols,
   NumTriCols,
   PointCols,
   LineCols,
   TriCols,
  
   // these are used when building model primitives
   V1X,
   V1Y,
   V1Z,
   V1NX,
   V1NY,
   V1NZ,
   V1C,
   V1U,
   V1V,
  
   V2X,
   V2Y,
   V2Z,
   V2NX,
   V2NY,
   V2NZ,
   V2C,
   V2U,
   V2V,
};

enum e__YYMKIND
{
   PRIMITIVE_BEGIN,
   PRIMITIVE_END,
   VERTEX,
   VERTEX_COLOR,
   VERTEX_TEX,
   VERTEX_TEX_COLOR,
   VERTEX_N,
   VERTEX_N_COLOR,
   VERTEX_N_TEX,
   VERTEX_N_TEX_COLOR,
   SHAPE_BLOCK,
   SHAPE_CYLINDER,
   SHAPE_CONE,
   SHAPE_ELLIPSOID,
   SHAPE_WALL,
   SHAPE_FLOOR,
};

Keep in mind, Ive been doing this for 8-10 years too, and it has never been a problem for me.
@Nocturne Don't change anything without a whole sale investigation.
 

Roa

Member
@Fishman1175 thanks for offer, but i was thinking the project is already quite big, as in lots of rooms and objects, so might prove bothersome. If it doesnt seem to get solved tho, i can mail it to you. @Joe Ellis I have yea, but mostly smaller projects that were also imported from GM8. Had some graphical issues too. This one is working fine otherwise, but this testing recently and trying to get to the root of the crash problems has made me think if it's because of my laptop. I have Windows 8.1. I have two guesses: it's the Audio somehow, since the crashes usually occur after a sound plays, or the 3D-2D switches, since they also occur when the room changes from a 2D to a 3D one.
Does this indicate smth bothersome, during Compile:

Unable to find output device "null" defaulting to "Speakers (Conexant SmartAudio HD) via DirectSound"

If not, it might just not be audio-related but smth to do with the 2d-3d switches.
That null audio is normal

Have you tried setting the vertex buffer type to most compatible?
 
Have you tried setting the vertex buffer type to most compatible?
Most likely not since got no idea what it means hahah... can you please clarify? Is it to do with vertex_create_buffer(); ? Happy to try tho, anything really at this point...
 

BorisE

Member
Hey I just found the advice about d3d_start and d3d_end, I hadn't seen that anywhere else... Seems to be working so far, my game had become unstable recently, either through Win10 or GM updates I don't know. Currently I have the d3d_start in draw_start and the d3d_end in draw end. I'm not using draw_gui and there is only one viewport so that covers everything.

Now maybe I'll have another go at creating sprites on demand...I didn't try it before as it needs a temporary surface and I read that surfaces were unavailable while 3D was enabled.
 
Last edited:
Top