Debugging issue - cannot set breakpoint. Please help.

The Partridge Family were neither partridges nor a family. Discuss.
Triber
Posts: 4
Joined: May 22nd, 2020, 3:12 pm
Location: Czech Republic

Debugging issue - cannot set breakpoint. Please help.

Post by Triber » May 22nd, 2020, 3:21 pm

So now I am stuck for a couple days with this issue that really gets me frustrated.

I am learning from Chili's begginer game programming tutorial and trying to make my own simple 2D dungeon game. I am using Visual studio 2019.

Everything went fine so far, but recently I've added new array of objects into the game that the player interacts with, however the condition triggers only after hitting one of the objects, the rest is completely ignored. So the logical conclusion was to try to debug it and see what's going on with the variables.

The issue is that when I set a breakpoint inside the condition, that should be triggered, Visual studio shows this message when I run in debug mode:
msg.png
(30.13 KiB) Not downloaded yet
I've googled this message and went through several topics on stackoverflow, however I couldn't find any solution that would work for me.
I've already deleted all the *.pdb and *.exe files and completely rebuilded the solution like 3 times, it has no effect whatsoever.
I also set Project properthies -> Linker -> Debugging -> Debuggable assembly to "Yes (/ASSEMBLYDEBUG" (that was one of the other advices on the forums).

Does anyone have similar experience and how you managed to solve it?

P.S.: sorry but I'm not posting the code here, since it doesn't make much sense for you to go through hundreds of lines of code that you've never seen before and I guess you wouldn't conclude much from a small piece. That's why I'm asking for a more abstract, general advice.

Thank you.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Debugging issue - cannot set breakpoint. Please help.

Post by albinopapa » May 22nd, 2020, 7:00 pm

As the message states, it's possible that the compiler has determined that the particular line is unreachable. There could be a number of reasons I suppose. Small functions can be inlined and as such don't resolve to function calls. If the 'if( player.collides... )' function is inlined and the compiler doesn't see any other way for the result to be true ( always returns false ) then the compiler can just ignore the 'true path'. This usually doesn't happen in Debug builds unless you or someone else has made some changes to optimization properties.

I've mostly ever seen this in Release builds.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Debugging issue - cannot set breakpoint. Please help.

Post by albinopapa » May 22nd, 2020, 7:13 pm

On a side note, your reasoning about not wanting to post the code seems odd. First off, hundreds of lines of code isn't that much to skim through. Second, why would going through code I've never seen before not make sense? People do this all the time as part of a code review. The easiest way to help someone from my experience is to have the code in front of me. If I can't tell just by looking at it, being able to run it and debug it line by line if need be is way more valuable than just taking shots in the dark.

Seems to me that you are either just embarrassed about something or are wanting to keep your code private in case you wanted to take this commercial or are afraid of someone using your code for their own. If embarrassed, I get it. I rarely show incomplete code on here for the same reason and it's quite the hassle sometimes to zip a cleaned project, which is why GitHub is so great.

If it's for the other reason, I can understand your concern then as well. I can't make any guarantees about sharing your code here.

If it is because you think it's a waste of your time, then consider what I said about how much easier it is for someone to debug a project on their own computer than it is to go through this back and forth of guessing what the issue could be.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Debugging issue - cannot set breakpoint. Please help.

Post by albinopapa » May 22nd, 2020, 7:21 pm

Btw, the answer I gave should give you an idea on how to proceed, but I'll go ahead and spell it out.

If line 45 ( player.setSpeed( 1 ); ) won't trigger set the break point on line 43 ( if player.collides(...) ). Step Into the function call. If the compiler has inlined the function, then execution will just go back to the for loop from the looks of it. If that is the case, then there is a trick you can use.

Code: Select all

#if defined( DEBUG ) || defined( _DEBUG )
#define NOINLINE __declspec(noinline) 
#else
#define NOINLINE
#endif

class Player{
public:
    NOINLINE bool collides( ... );
private:
};
This way during debug builds, the function won't be inlined and will be considered for inlining if in release. This should at the very least allow you to step into the collides() member function.

EDIT: The __declspec(noinline) is Microsoft specific so probably won't be available in other compilers.
GCC has the __attribute__(( noinline )) specifier to accomplish the same thing.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Triber
Posts: 4
Joined: May 22nd, 2020, 3:12 pm
Location: Czech Republic

Re: Debugging issue - cannot set breakpoint. Please help.

Post by Triber » May 23rd, 2020, 7:23 am

albinopapa: First of all, thank you for your reaction.

About the code sharing - yes, I'm a bit embarassed, I think my code is quite a mess, but on the other hand I don't think it's a big deal since im beginner. Making it commercial? No, I am nowhere near that. I'm just toying around with stuff I've learned from Chili's videos and trying to make something on my own, just learning. When the game is somehow playable, I would only share with a couple friends, that's all. I am not afraid of someone here stealing it since it doesn't contain any unique ideas (and the graphics is downloaded, I googled something like "2D dungeon game free tileset". I just didn't believe someone would want to debug the whole project here on forums, that's all.

I am going to try to move the breaking point as you mentioned and then I will report my result. If I'm still not able to debug it on my own, I will post the whole solution in *.zip here.

I am going to reply again soon.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Debugging issue - cannot set breakpoint. Please help.

Post by albinopapa » May 23rd, 2020, 7:35 am

I just didn't believe someone would want to debug the whole project here on forums, that's all.
I'm guessing you haven't read the [Sticky] ---- RULES: READ THIS FIRST! thread.
If you're looking for help on the tuturials, or just on programming in general, make sure you post your code (zipped and cleaned solution)
Also, btw, your issue doesn't come up often on the forum so if you do find the cause it would be nice to know what it was.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Triber
Posts: 4
Joined: May 22nd, 2020, 3:12 pm
Location: Czech Republic

Re: Debugging issue - cannot set breakpoint. Please help.

Post by Triber » May 23rd, 2020, 3:16 pm

Ok I've tried to do few more tests, unfortunetely no results.

I am attaching the solution now. (it doesn't contain your "trick" in Player.h, I've tried that after I cleaned the solution and put it in *.zip).
I've checked that Wiki page in the forum thread that you mentioned and cleaned the solution a bit so it's not that big.

The condition doesn't seem to trigger, however strange thing is, that the player actually DOES speed down after hitting one specific field of water. Just one of them. You will see that when you will build the solution and try to move around a bit.
dungeon.zip
(2.5 MiB) Downloaded 147 times
Little inside info:
Spoiler:
We are interested in player - water collision, which should slow down the player's movement.
Files that involve this: Water.h, Water.cpp, Player.h, Player.cpp, Game.cpp.

Water is an array, member object in the Game class (game.h). It is put into the map using file maps.h. That file contains 2D array which I used to make maps (couldn't think of anything better at the moment). Each number in the array represents a different object in the map; for water I use number 4. This array is processed in the function Game::draw_map, which is in the same file (maps.h).

The object itself is drawn in Game.cpp inside ComposeFrame function and the collision is tested inside UpdateModel function.
It might be something really trivial that I just can't see even though I am starring at this for hours.

Thank you in advance and I'm ready to explain anything in the solution if needed.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Debugging issue - cannot set breakpoint. Please help.

Post by albinopapa » May 25th, 2020, 5:48 pm

Okay, finally figured out what is going on with the player speed thing, but you'll have to figure out how to fix it.

The problem is with the if/else in the loop for checking if player is over a water tile. True that it sets player speed to 1 if overlapping a water tile, but then in the next loop it sets the player speed to default_speed if not overlapping. So for the majority of the tiles the player's speed is set to default, but if the player overlaps the last water tile then the speed is set to 1 and because there aren't any more loops that can change back to default_speed after that, it has the speed remain at 1.

There are a couple of ways to handle this:
  • set the player speed to default before the loop and only change the speed if there is a collision

    Code: Select all

    player.setSpeed( player.default_speed );
    for(...)
        if( player.collides( ... )
            player.setSpeed( 1 )
    
  • set a bool for collision and |= with the result

    Code: Select all

    bool isOverWater = false;
    for( ... )
        isOverWater |= player.collides( ... );
    
    player.setSpeed( isOverWater ? 1 : player.default_speed );
    
  • just break out of the loop after a collision and setting speed to 1

    Code: Select all

    for( ... )
        if( player.collides( ... ) ) {
            player.setSpeed( 1 );
            break;
        }
        else{
            player.setSpeed( player.default_speed );
        }
    
Either way, you won't be setting the speed to default_speed more than once, which I'm sure that's what you are expecting.

You could break out of the loop using either of the first two options as well since player is slowed no matter how many water tiles it's over.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Debugging issue - cannot set breakpoint. Please help.

Post by albinopapa » May 25th, 2020, 5:49 pm

As far as the unreachable break point, I did not have the issue in Debug build, but did have that issue in Release.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Triber
Posts: 4
Joined: May 22nd, 2020, 3:12 pm
Location: Czech Republic

Re: Debugging issue - cannot set breakpoint. Please help.

Post by Triber » May 26th, 2020, 4:29 pm

Thank you very much! You've been very helpful.

At some point I was convinced that I'm doing something wrong with the water directly, I didn't think my in-loop condition could be wrong in some way.

I've repaired it the first way you suggested; setting speed to default at the beginning of the loop and then changing the speed only if the collision is true. It works. 8-)

Post Reply