• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Tim Lawton

_itoa_s, strcpy_s, strcat_s. What are these doing exactly

12 posts in this topic

EDIT:

Hey there,

I've just realized that the title may be kind of misleading. so I'm rewriting this part.

Basically I have added a new method which holds the following 'functions' in the title, and I believe its causing my program to break at a very strange point in my 'UpdateSentence' method.

Here is the method I have just recently added "setFPS" in my Text class.

[CODE]
bool Text::setFPS(int fps, ID3D11DeviceContext* deviceContext)
{
char tempS[16];
char fpsS[16];
float red = 1.0f;
float green = 1.0f;
float blue = 1.0f;
bool r;
if(fps > 9999) //Truncate the fps
{
fps = 9999;
}
_itoa_s(fps, tempS, 10);
strcpy_s(fpsS, "FPS: ");
strcat_s(fpsS, tempS);
/*
if(fps >= 60) //if FPS is above or equal to 60 set text colour to green
{
red = 0.0f;
green = 1.0f;
blue = 0.0f;
}
if(fps < 60) //if FPS is below 60 set text colour to yellow
{
red = 1.0f;
green = 1.0f;
blue = 0.0f;
}
if(fps < 30) //if FPS is below 30 set text colour to red
{
red = 1.0f;
green = 0.0f;
blue = 0.0f;
}
*/
r = UpdateSentence(sentence3, fpsS, 20, 20, red, green, blue, deviceContext);
if(!r)
{
return false;
}
return true;
}
[/CODE]

Now the application isn't breaking/crashing at this point, it's breaking at another method called "UpdateSentence" which you can see in the screenshot here:

http://img547.imageshack.us/img547/3619/accessviolation2.png

Here is the break I'm getting, it seems to be happening with adding colour to the function and I have no idea why its playing up now when it previously wasn't.

Also if someone needs to see more code just ask and I can show

If someone could shine some light on this I would be greatful Edited by Xuchilbara
0

Share this post


Link to post
Share on other sites
[code]strcpy_s(fpsS, "FPS: ");[/code]
I am not sure what strcpy_s does, but if it's anything like strcpy, you are using fpsS uninitialized.
1

Share this post


Link to post
Share on other sites
In your debugger in the screen shot you can see that the sentence pointer is 0xCDCDCDCD. This is the debug library's pattern for uninitialized values.

You need to point it to a valid object.
2

Share this post


Link to post
Share on other sites
[quote name='frob' timestamp='1354216647' post='5005408']
In your debugger in the screen shot you can see that the sentence pointer is 0xCDCDCDCD. This is the debug library's pattern for uninitialized values.

You need to point it to a valid object.
[/quote]

Thanks for the quick reply, although it is pointing to a valid object, I have a struct in my header file which holds the floats:

[CODE]
struct SentenceType
{
ID3D11Buffer* vertexBuffer;
ID3D11Buffer* indexBuffer;
int vertexCount, indexCount, maxLength;
float red, green, blue;
};
[/CODE]

and then it's equal to the float 'red' in the parameter of UpdateSentence
0

Share this post


Link to post
Share on other sites
[quote name='SiCrane' timestamp='1354218317' post='5005422']
On 32-bit Windows, the maximum user addressable memory is 3GB, with the top 1GB of the virtual address space reserved for the kernel. If your pointer value is 0xC0000000 or higher then it can't be a legal pointer value. More specifically OxCDCDCDCD is MSVC's debug fill pattern for uninitialized memory. If you see a pointer error involving that address it generally means that you are accessing uninitialized memory, which since the debugger is identifying sentence's value as 0xCDCDCDCD that probably means that you either don't initialize sentence correctly when creating your object or that you are calling a member function on an invalid object pointer. Either way the sentence pointer isn't valid.
[/quote]

I see, but it was working previously, before I added the "setFPS" function, but if thats the case, is there anyway of getting round it?
0

Share this post


Link to post
Share on other sites
[quote name='Xuchilbara' timestamp='1354213223' post='5005387']
Now the application isn't breaking/crashing at this point, it's breaking at another method called "UpdateSentence" which you can see in the screenshot here:
[/quote]
Then why don’t you show the code for UpdateSentence()?

Also, sentence3 is garbage when it is passed to UpdateSentence(). I assume it is a member of the Text class.
Naming conventions such as m_ would go a long way to help people realize from where variables are coming.
It needs to be initialized—this has nothing to do with the functions listed in the topic.


L. Spiro Edited by L. Spiro
0

Share this post


Link to post
Share on other sites
[quote name='Álvaro' timestamp='1354216379' post='5005407']
[code]strcpy_s(fpsS, "FPS: ");[/code]
I am not sure what strcpy_s does, but if it's anything like strcpy, you are using fpsS uninitialized.
[/quote]

strcpy_s(char* dest, const char* src); works like strcpy but it will fail (I think with an exception? maybe just a windows error) if it would cause an overrun.

As for the error, it looks like that address is actually 0xCDCDCDE1, which suggests that somewhere you're adding 20 to an uninitialized pointer rather than initializing it.

Just put a conditional breakpoint at the start of the function there that breaks if the pointer value is 0xCDCDCDE1 and then look at the stack to see where it's coming from. Edited by Khatharr
1

Share this post


Link to post
Share on other sites
[quote name='Álvaro' timestamp='1354221529' post='5005443']
Oh, please ignore my comment. I thought we were talking about strcat(). I need some rest. ;)
[/quote]

lol, I know that feeling. [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]

As a side note:

[source lang="cpp"]_itoa_s(fps, tempS, 10);
strcpy_s(fpsS, "FPS: ");
strcat_s(fpsS, tempS);
[/source]

Could be:
[source lang="cpp"]sprintf_s(fpsS, "FPS: %i", tempS);[/source]
If you want to use C style string handling. Edited by Khatharr
0

Share this post


Link to post
Share on other sites
[quote name='L. Spiro' timestamp='1354221160' post='5005439']
[quote name='Xuchilbara' timestamp='1354213223' post='5005387']
Now the application isn't breaking/crashing at this point, it's breaking at another method called "UpdateSentence" which you can see in the screenshot here:
[/quote]
Then why don’t you show the code for UpdateSentence()?

Also, sentence3 is garbage when it is passed to UpdateSentence(). I assume it is a member of the Text class.
Naming conventions such as m_ would go a long way to help people realize from where variables are coming.
It needs to be initialized—this has nothing to do with the functions listed in the topic.


L. Spiro
[/quote]

Ah thats done it, it wasn't initializing correctly and going straight to garbage, it is working now thanks alot everyone! :)

Also in essence, _itoa_s, strcpy_s, strcat_s, wasn't even the problem, sorry for being misleading :/ Edited by Xuchilbara
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0