• 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.

Windows Draw event not drawing. [Solved]

Sam04

Member
Just like that the draw event of some instances seems not to be drawing anything.

I was working on a project when I noticed that an instance was not drawing what it was suposed to draw, which at first was weird because the changes I've made since the last time it worked should have no effect on the instance draw event.

So I did a bit more testing to find out the cause of the problem.
  • I've made sure the object is set to visible and that there is no code anywhere changing that.
  • I've made it the only object in the room and still no difference.
  • I've tried deleting the background layer to see if it had any problem but I saw no change. (Keep in mind that I was only using the default instance and background layers that appear when you create a new room).
  • I've created a new empty room with the sole purpose to test this single object and it was still not drawing anything.
  • In all of those previous cases I've replaced the entire draw event code for a single draw_rectangle();.
  • I've made sure that what I'drawing is within the boundaries of the room.
  • Just to make sure I also preceded it by a draw_set_alpha(1); and a draw_set_colour(c_black);.
  • This only happens with one specific object.
  • Said object has a valid depth, it uses the one in the layer it was placed (which has a depth of -3) and the code never changes this.1
  • The object has no sprite assigned and everything in the draw event pertain to drawing shapes and other sprites.1
  • Said object still runs the code in the draw event. Writing show_debug_message("something"); does indeed shows "something" in the debug window.
  • I have tried with both relative and absolute positions both yielding the same result. Said object does not use physics and the other varables phy_position_x and phy_position_y do not work on them.2
  • This also works even when it is inside logic conditioning, so it also works as expected when I write something like:
Code:
if (1>0) {
    show_debug_message("This is suposed to be shown");
}
if (0>1) {
    show_debug_message("And this is not suposed to be shown");
}
  • So it still runs the code inside the draw event but refuses to draw anything at all.

I am working with the current IDE version (2.2.0.343 runtime 2.2.0.258) on a Windows 7 machine. I am not really sure if this is a bug or if there is a hidden option that I accidentally activated without noticing. I am using the free version so I am unable to test on any platform that isn't Windows which I supose it might be important because I've searched in this forum and have found other kind of problems with Windows 7 but I am not completely sure since I couldn't find any other problem like mine.

Thanks in advance for all the help.

[Edit 1: Increased the bullet list with things mentioned in the answers on this thread.]
[Edit 2: Added more items gotten from this amazing guide made by FrostyCat. I am still too new to be allowed to post links to the guide and the user but you can check them lower in this post.]
 
Last edited:
One thing I notice you haven't checked for:
- ensure that the object has a depth between -16000 and +16000. If it is outside of that range, then it will not draw but it will still be created and all events will continue to run.
 

Sam04

Member
One thing I notice you haven't checked for:
- ensure that the object has a depth between -16000 and +16000. If it is outside of that range, then it will not draw but it will still be created and all events will continue to run.
You are right, I forgot to mention it. But it does have a valid depth. It uses the one set up for the layer (which is -3) and it never changes it.

If you have code in the draw event, ensure you use a draw_self() function.
The draw_self() function is meant to draw the sprite assigned to the object. This object in particular has no sprite assigned and the said function has no bearing on wether other drawing functions work or not.
 

Sam04

Member
Can you post the code of the draw event?
Sure, this is the thing that I ended up trying. I tried it both with and without the alpha and colour lines.
Code:
draw_set_alpha(1);
draw_set_colour(c_black);
draw_rectangle(x-16,y-16, x+16,y+16, 0);
That should be draw_set_colour(c_white), should it not? c_black will not draw anything usually.
It is the other way around. White is the default one that in some drawing functions is interpreted as transparent, or nothing. Black, on the other hand, does indeed work as the color black.

There are more possible causes for missing text than that. See my checklist for missing text bugs.
Wow, I'm impressed by such a complete and thorough guide on these matters. However, dicarding the ones that I already mentioned I stumbled on these ones:
  • Has the drawing target been redirected to a surface, and if so, did you forget drawing the surface back onto the screen where it can be seen?
    I don't really understand this one. Although I don't use functions related to any surface except for window_resize(); but that one does not affect the views as all other objects seem to not care about this.
  • Is there a control structure that may keep the text drawing call from executing?
    Again, I don't really understand this one. I don't know about control structures. Sorry :(
  • If drawn at a relative position, are you using inappropriate position variables, such as phy_position_x and phy_position_y for a non-physics instance, or x and y for a physics instance?
    The example I posted at the beggining of this message uses relative position, but I have also tried with absolute position and it doesn't work either. Just to be sure I tried using phy_position_x and phy_position_y but the game crashed because the object does not use physics.
Just in case I double checked everything else in your list but everything was still as I first saw it.

[Edit: Some grammar issues.]
 
Last edited:

FrostyCat

Member
I don't see a draw_set_font() anywhere in your code, and that is the first item in my checklist under "Fonts". Depending on the export or runtime version, this could make the text invisible.
 

Sam04

Member
I don't see a draw_set_font() anywhere in your code, and that is the first item in my checklist under "Fonts". Depending on the export or runtime version, this could make the text invisible.
You are correct, I've never used a draw_set_font(); function; but that's because I've never really used any text function. All the drawing functions that I've used are related to drawing sprites or simple shapes.

Regardless, even when drawing text GM uses a default Arial font when no other font is specified for use. And I haven't included any font asset on this project.
 
What other events and code do you have in this object?

If you comment out all other code does it still not draw?

Have you tried cleaning the project cache?

If you create another new object and test the draw code, does it show up.
 

Sam04

Member
What other events and code do you have in this object?

If you comment out all other code does it still not draw?

Have you tried cleaning the project cache?

If you create another new object and test the draw code, does it show up.
I have already tried commenting everything and I still had that problem. Tha same happens when I clear the cache.

The part about the new obect is funny. When I created a new object with the same draw event it did draw everything correctly. But more interestingly it seems like deleting the instance in the room and creating a new instance solved the problem. I believe it might be a bug in the IDE because the old instance never had any change to the instance in the room. I am aware that in the room editor you can double clic an instance to open the settings of that particular instance (not the object), but I am sure that I never changed anything in the original one so this is baffling.
 
Very puzzling. I presume you checked the Creation Code of the problematic instance? If not, do you still have a copy of the project when it was not working, you could check it and/or submit a bug report and include a link to the project.
 

gnysek

Member
1) Make a copy of project
2) Simplify it as much as possible, removing all sprites/scripts/objects/rooms which aren't needed - repeat this step as long as bug exists
3) if it's fixed, the last thing you removed were causing a problem
4) if it's still presenting or you don't know why just removed in step 3) thing is causing a problem, share this minimalist example here, and we take a look !
 
Top