|
-
January 4th, 2010, 01:27 PM
#1
Debugging
Hi, I'm having a couple problems debugging a VS2008 C++ app using this SFML graphics library.
The first one is that when I edit a breakpoint through the When Hit menu and I try to have a variable print out through the output window using something like {value} nothing appears when the breakpoint is reached.
The second more serious problem is that the debugger will only go through the first few breakpoints before exiting completely. The program will usually pop up a window where the graphics are and a plain text output window. When I use the debugger only the output window appears. I haven't detected any relevant problem with the program itself and the debugging works properly for a simple console program I tested.
Code:
int main()
{
//declare the characters and objects in window
object *ObjectArray[6];
//Wanderbot Basicbot(950.f,100.f,950.f,100.f);
hero firsthero(1000.f,300.f,1000.f,300.f);
Peacebot Patrolbot(100.f,1900.f,100.f,1900.f);
weapon cpistol;
collisionmachine collisionmachineinst;
gameui currentui;
float distancebetweenxmain, distancebetweenymain,unsignedbx,unsignedby;
sf::Clock Timer;
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
sf::Vector2f Center(400, 300);
sf::Vector2f HalfSize(400, 300);
sf::View View1(Center, HalfSize);
//variables needed to run things on main
collisionmachineinst.objectpopulation=5;
//setup background
<<BREAKPOINT>>//debugger exits out after this breakpoint
Code:
sf::Image Background;
if (!Background.LoadFromFile("PracticeDeck5test.png"))
{
std::cerr << "Error : cannot load image.\n";
return EXIT_FAILURE;
}
sf::Sprite BackgroundSprite(Background);
BackgroundSprite.SetPosition(0.f,0.f);
//register objects in collision loop
ObjectArray[0]=&firsthero;
//ObjectArray[1]=&Basicbot;
ObjectArray[1]=&cpistol.bullet[0];
ObjectArray[2]=&cpistol.bullet[1];
ObjectArray[3]=&cpistol.bullet[2];
ObjectArray[4]=&Patrolbot;
Last edited by Jarwulf; January 4th, 2010 at 01:29 PM.
-
January 5th, 2010, 01:59 PM
#2
Re: Debugging
Anybody have any idea? I'm using the continue button to move through if that helps...
-
January 5th, 2010, 04:39 PM
#3
Re: Debugging
 Originally Posted by Jarwulf
Anybody have any idea? I'm using the continue button to move through if that helps...
Could you use “Step Over” (F10) instead of “Continue” (F5)?
That way you can see if, possibly, your LoadFromFile() failed and you exited via
Code:
return EXIT_FAILURE;
Also, the code tags are used (mainly) to preserve your original code indentation; yours is not worth preserving 
Could you please indent your code properly in your future posts?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
January 5th, 2010, 05:41 PM
#4
Re: Debugging
 Originally Posted by VladimirF
Could you use “Step Over” (F10) instead of “Continue” (F5)?
That way you can see if, possibly, your LoadFromFile() failed and you exited via
Code:
return EXIT_FAILURE;
Also, the code tags are used (mainly) to preserve your original code indentation; yours is not worth preserving 
Could you please indent your code properly in your future posts?
It goes to the end of main but still exits out prematurely and doesn't hit the later breakpoints in main or the ones I set in other functions
EDIT: On further inspection it gives me a failed to load message for PracticeDeck. How would I solve this? I had moved all the media files to the debug folder in the project directory
Last edited by Jarwulf; January 5th, 2010 at 05:58 PM.
-
January 6th, 2010, 06:59 AM
#5
Re: Debugging
When you run your app in the VS IDE debugger, the default working directory is the same directory containing the .sln and .vcproj files. Since you try to open the file without a full path name
Code:
if (!Background.LoadFromFile("PracticeDeck5test.png"))
the system is looking in the folder with the vcproj for the PracticeDeck5test.png file.
The debug folder would be the default working directory if you double click on the exe from Windows Explorer.
I recommend you always use full path names to open your files. Another option is the set the properties for your project in Visual Studio to use the proper working directory.
Hope that helps.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
January 6th, 2010, 03:17 PM
#6
Re: Debugging
 Originally Posted by krmed
I recommend you always use full path names to open your files.
This is not practical in a real world, when you don’t know where your program will be installed.
The most convenient way is to use relative path (to your exe file), and GetModuleFilName() at run time to build full path.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
January 6th, 2010, 03:20 PM
#7
Re: Debugging
Yes, it is practical - and should be done.
I didn't say to hard code the full path - just to use the full path. Obviously the way is as you said, by using GetModuleFileName.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|