C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 7th, 2003, 10:00 PM
Corry Corry is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Denton, TX or hell at any given time :)
Posts: 2 Corry User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Corry Send a message via AIM to Corry Send a message via Yahoo to Corry
Program only runs in the debugger?

I don't know about the experience of the forums here nor do I know if there is some simple reason people would know why a program only runs from the MSVC debugger.
Just to clarify, this program is a "Game Demo" that is for a college class, using DirectX 9 (Hoping to get into the HLSL soon) I havent gone quite to the point of putting in OutputDebugString("Got this far!\n"); all throughout the program yet. A little more background if you are still reading. The way it works is to initialize D3D, DSound, and DInput, then it initializes the "Game State" currently jumping right into the "Playing State" , which causes it to load all the graphics, etc, then it draws the world, and allows character interaction etc. After initializing that, it jumps right into the message pump, with the last step in the loop being to update the game state. The breakdown occurs after loading the graphics. I was hoping this would be a simple oh it runs in the debugger but not without it's probably xy or z setting. If not, I guess its on to OutputDebugString("blah\n"); and sysinternals debug string catcher...
Thanks in advance
Corry

Reply With Quote
  #2  
Old April 7th, 2003, 11:19 PM
Corry Corry is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Denton, TX or hell at any given time :)
Posts: 2 Corry User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Corry Send a message via AIM to Corry Send a message via Yahoo to Corry
Well, what can I say I am impatient. I went through and did lots and I mean LOTS of OutputDebugString("I am here!\n"); and char Debug[200]; sprintf(Debug, "Relevent pointers are %d and %d and %d\n", pointer1, pointer2, pointer 3); OutputDebugString(Debug);
EAventually it turned out to be an array bounds check by a really stupid piece of code on my part. I am using a simple rect algorithm to determine which "tiles" of the world are visible. If they are not visible I set their verticies all to 0,0, then not draw them. The algorithm function returns an integer array with visible tiles in an order that works in the program. If a particular tile is not visible its number is -1. Well, I was trying to set the -1 tile to a 0,0 rect.
So I take it that the msvc debugger has an array bounds check feature built in?

Also, now that I wrote tons of those statements mentioned above, I would like my own singular function like printf to output debug strings. I looked at the function definition to sprintf and it was and I quote sprintf(char*, const char*, ...) So whats with the ... they dont teach that in any C/C++ courses! Can I use that to make a say dprintf for debugprintf? How do I pull in the varibles/data in the ...?
Thanks
Corry

Reply With Quote
  #3  
Old April 8th, 2003, 10:08 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is online now
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,141 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 23 h 33 m 20 sec
Reputation Power: 1974
Quote:
Originally posted by Corry
...

Also, now that I wrote tons of those statements mentioned above, I would like my own singular function like printf to output debug strings. I looked at the function definition to sprintf and it was and I quote sprintf(char*, const char*, ...) So whats with the ... they dont teach that in any C/C++ courses!


I don't quite understand the question.

The printf() family of functions create a formatted string and then do something with it. printf writes the string to stdout. fprintf writes it to a file.

sprintf stores it in a char array. The first parameter (char*) points to the char array that is to receive the formatted string. The second parameter (const char*) is the format string which contains format variables to mark where the variable values go and what type they are to be. Then a variable-length/type list of variables follows.

For example:
sprintf(buffer,"The value of %s at line %d is %d\n",var_name,line_no,var);
%s marks a string, so var_name needs to be a char*.
%d marks a decimal value, so line_no and var need to be ints.
\n means "end of line"

Edit:
OK, I see now. The ellipses ("...") refer to a variable-length list of variable names that are to be used in the format string.

No data type is specified for those variables, BTW, because their data type is implicitly defined by their corresponding format variables. This leads to interesting bugs, since if you use the wrong type of format variable, then that variable will be interpreted as that data type. Debug hint: if the program seems to go through the motions alright but gives you really wacko output, then double-check the format variables.

This is an integral part of the printf family of functions, which are an integral part of C and is taught in every C class that I've ever heard of. In fact, the sprintf function was what really won me over from Pascal, where formatted output had to be done with multiple lines of code.

You probably haven't encountered it yet in C++, because they use iostreams to "protect" you from printf. Personally, I think we need protection from iostreams.


Quote:
Originally posted by Corry
Can I use that to make a say dprintf for debugprintf? How do I pull in the varibles/data in the ...?


There are ways in C to write functions with variable-length argument lists, but I was only exposed to that once in class about twelve years ago.

You could use sprintf everywhere you need it, or use C++'s function overloading feature to create a set of functions by the same name but with the different combinations of parameters that you need. Within each function, do an sprintf specific to that combination of parameters and then make the call to display it.

Not an elegant solution, but some of the functions should get used more than once.

Last edited by dwise1_aol : April 8th, 2003 at 10:20 AM.

Reply With Quote
  #4  
Old April 8th, 2003, 10:24 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is online now
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,141 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 23 h 33 m 20 sec
Reputation Power: 1974
Quote:
Originally posted by Corry
sprintf(Debug, "Relevent pointers are %d and %d and %d\n", pointer1, pointer2, pointer 3);


The format variable for pointers is %p, which will display the memory address assigned to the pointer.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Program only runs in the debugger?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap