• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=Two-Bit;39556613]Hey guys, an account of mine was recently hacked and to combat this I thought i'd make a random password generator in C++. It works somewhat but whenever I run it the string of characters is always the same. [CODE]while(true) { char chL = 'a' + rand() % (('z'-'a') + 1); char chU = 'A' + rand() % (('Z'-'A') + 1); char ch = '!' + rand() % ((')'-'!') + 1); int num = 1 + rand() % ((9-1) + 1); cout<<chL<<chU<<num<<ch<<endl; system("pause"); };[/CODE] [URL="http://gyazo.com/ae5398e0f22a15c7c78e5580e4c668da"]First run[/URL] [URL="http://gyazo.com/a53e5aa758c8581e4dd88061f26fde9d"]Seccond run[/URL] Is there any reason for this? how do I fix it. Thanks[/QUOTE] srand()?
Works great! Thanks so much [img]http://www.facepunch.com/fp/ratings/heart.png[/img]!
[QUOTE=Larikang;39556661]srand()?[/QUOTE] Works, thanks man
[QUOTE=Mega1mpact;39522213]Chrome tells me that their certificate is fine. [url]https://planning-scores.nl/serverlogout.html[/url] (the website I'm trying to do a request to)[/QUOTE] Just doing a repost of this question because I'm still stuck :/
I am having serious trouble with stencil buffers. It's the first time I've ever attempted anything with them and, to be honest, I have no clue how they work. I'm programming with C# and OpenTK, and sadly there aren't that many examples. Right now I've pretty much brought it down to trying to understand how to clip a rectangle using another rectangle and even that I cannot do.. The code I've got right now, which is a combination of multiple examples with all of which I hoped to get a result, is as follows: [code] GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.StencilBufferBit); GL.Enable(EnableCap.StencilTest); GL.ColorMask( false, false, false, false ); GL.StencilFunc( StencilFunction.Always, 1, 1 ); GL.StencilOp( StencilOp.Replace, StencilOp.Replace, StencilOp.Replace ); GL.Begin(BeginMode.Quads); GL.Vertex2(0, 0); GL.Vertex2(80, 0); GL.Vertex2(80, 80); GL.Vertex2(0, 80); GL.End(); GL.ColorMask( true, true, true, true ); GL.StencilFunc( StencilFunction.Equal, 1, 1 ); GL.StencilOp( StencilOp.Keep, StencilOp.Keep, StencilOp.Keep ); GL.Color3( 0, 0.5, 0 ); GL.Begin(BeginMode.Quads); GL.Vertex2(0, 0); GL.Vertex2(80, 0); GL.Vertex2(80, 80); GL.Vertex2(0, 80); GL.End(); GL.Disable( EnableCap.StencilTest ); [/code] The result: an unclipped green rectangle. If anyone has any knowledge of stencil buffers and is willing to reveil their secrets to me, I would very much appreciate it.
I have a question regarding C++, pointers and std::vector. Considering the following snippet, What should I do to avoid memory leaks ? [url]http://pastebin.com/5gC3Bq9B[/url] Obviously Persons::name isn't free'd, since it works like that, but I'd like to avoid such traps.
How do you do java profiling on Android? I've google'd around quite a bit. What are the absolute basics?
[QUOTE=OrYgin;39564081]I have a question regarding C++, pointers and std::vector. Considering the following snippet, What should I do to avoid memory leaks ? [url]http://pastebin.com/5gC3Bq9B[/url] Obviously Persons::name isn't free'd, since it works like that, but I'd like to avoid such traps.[/QUOTE] You need to free the char* in Person when the Person is destroyed, so either implement a a destructor for Person, or just switch to std::string if your environment allows it. Sometimes it's necessary to resort to the most basic types like char*, but in this case it should be avoided if at all possible. [editline]12th February 2013[/editline] std::string will take care of allocation and deallocation for you.
It's for a Source mod and all the strings are char*, so I try to avoid using something else. If I use a destructor on Person, when I pop it, I suppose bar() won't work. If I delete myself the char* before bar(), the strings are bugged. I suppose I'll just traverse the Vector, do my stuff (bar()), then empty the Vector after.
[QUOTE=OrYgin;39564289]It's for a Source mod and all the strings are char*, so I try to avoid using something else. If I use a destructor on Person, when I pop it, I suppose bar() won't work. If I delete myself the char* before bar(), the strings are bugged. I suppose I'll just traverse the Vector, do my stuff (bar()), then empty the Vector after.[/QUOTE] That would probably be the easiest and most reasonable course of action yeah, just traverse it and clear it afterwards.
Seems like pop() frees the char in the struct because when I try to free it (be it destructor or myself) it crashes the program randomly. Of course it's not the case, but it's getting way too weird for me.
[QUOTE=OrYgin;39564965]Seems like pop() frees the char in the struct because when I try to free it (be it destructor or myself) it crashes the program randomly. Of course it's not the case, but it's getting way too weird for me.[/QUOTE] Are you sure that the char* has even been allocated at that point? If it's pointing to random memory and you try freeing it, it's gonna fuck you up. Where are you creating the Person?
Well if the Vector is empty, it won't try to free anything, and when there is data in it, the char* is allocated. It goes along the lines of [code] Person p; p.name = new char[strlen(foo)]; strcpy(p.name, foo); Persons.push_back(p); [/code]
You know, if I were you, I'd just go all in and wrap the whole thing with constructos and destructors, marking the char* name member as private and const since it doesn't seem like anyone's gonna be modifying it. Something like this? It uses std::string internally, but acts like a char* outwards: [cpp] struct Person { public: Person(char *name, int age) : name(name), age(age) { } const char *getName() const { return name.c_str(); } int getAge() const { return age; } private: const std::string name; const int age; }; [/cpp]
It doesn't crash, but the string is bugged : "\u0000at" and the like. In the debugger I can see the value for the string is correct, but when displayed it bugs out. I suppose c_str() is bugged or something ?
[QUOTE=OrYgin;39566677]It doesn't crash, but the string is bugged : "\u0000at" and the like. In the debugger I can see the value for the string is correct, but when displayed it bugs out. I suppose c_str() is bugged or something ?[/QUOTE] Can't be, how/where are you using the result from c_str? Also /u0000at refers to a unicode character (I think, don't hurt me Jookia!), so it's probably an issue with the input not using the same encoding as your Person's name field.
Guess I'll just dump all of the code I'm using. The struct is to store a kill information, with a (source) Vector (position) and the name of the weapon. [url]http://pastebin.com/3weWbRAN[/url] And well after I'm done with the json, I empty m_vKills. [editline]13th February 2013[/editline] And if I change the std::string to a char*, it works no problem.
[QUOTE=OrYgin;39566934]Guess I'll just dump all of the code I'm using. The struct is to store a kill information, with a (source) Vector (position) and the name of the weapon. [URL]http://pastebin.com/3weWbRAN[/URL] And well after I'm done with the json, I empty m_vKills. [editline]13th February 2013[/editline] And if I change the std::string to a char*, it works no problem.[/QUOTE] All I can think of in this case is that the string returned from pEvent->GetString("weapon") is malformed, or perhaps just contains that \u000at value. Also, using that KillInfo struct, you can just pass the result from GetString() straight into the constructor, it will copy the string for itself so there's no need to allocate a new char array for it. Anyway, I'm about to head to bed. Hopefully someone who's a little more familiar with the Source engine than I am will show up and take you the rest of the way :)
That's what I tried to do, but it kept telling me that the list of arguments didn't match. (Edit : seems like it works now …) Anyway, the string appears to be well formed when I output it in the console, but it still is bugged inside the json. I guess it's the library's fault then :( Thanks to you anyway ! EDIT: of course copying the c_str into another char* fixes it, but it beats of the benefits of std string.
Do any of you guys have a good resources for project structuring? I spent a good month on working on a project and someone pointed out how difficult it was to debug because of the structure, so I pretty much wasted all of that time. I want to fucking finish ONE GOD DAMN USEFUL THING/GAME already, this is fucking stupid, I have NOTHING to show for my 2 years of experience.
[QUOTE=Meatpuppet;39567604]Do any of you guys have a good resources for project structuring? I spent a good month on working on a project and someone pointed out how difficult it was to debug because of the structure, so I pretty much wasted all of that time. I want to fucking finish ONE GOD DAMN USEFUL THING/GAME already, this is fucking stupid, I have NOTHING to show for my 2 years of experience.[/QUOTE] What do you mean? Like UML or something?
Ok I figured it out. Since I wasn't using a pointer to KillInfo, once it went out of scope it called the destructor and deleted the string. Now with pointers it's all free'd properly :) However I had a strange bug where the destructor was called when I was attacking. I suppose it was a name problem since it works perfectly since I changed the name.
[QUOTE=mobrockers2;39568161]What do you mean? Like UML or something?[/QUOTE] Like a guide on making a simple game engine structure.
[QUOTE=xThaWolfx;39564040]I am having serious trouble with stencil buffers. It's the first time I've ever attempted anything with them and, to be honest, I have no clue how they work. I'm programming with C# and OpenTK, and sadly there aren't that many examples. Right now I've pretty much brought it down to trying to understand how to clip a rectangle using another rectangle and even that I cannot do.. The code I've got right now, which is a combination of multiple examples with all of which I hoped to get a result, is as follows: [code] GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.StencilBufferBit); GL.Enable(EnableCap.StencilTest); GL.ColorMask( false, false, false, false ); GL.StencilFunc( StencilFunction.Always, 1, 1 ); GL.StencilOp( StencilOp.Replace, StencilOp.Replace, StencilOp.Replace ); GL.Begin(BeginMode.Quads); GL.Vertex2(0, 0); GL.Vertex2(80, 0); GL.Vertex2(80, 80); GL.Vertex2(0, 80); GL.End(); GL.ColorMask( true, true, true, true ); GL.StencilFunc( StencilFunction.Equal, 1, 1 ); GL.StencilOp( StencilOp.Keep, StencilOp.Keep, StencilOp.Keep ); GL.Color3( 0, 0.5, 0 ); GL.Begin(BeginMode.Quads); GL.Vertex2(0, 0); GL.Vertex2(80, 0); GL.Vertex2(80, 80); GL.Vertex2(0, 80); GL.End(); GL.Disable( EnableCap.StencilTest ); [/code] The result: an unclipped green rectangle. If anyone has any knowledge of stencil buffers and is willing to reveil their secrets to me, I would very much appreciate it.[/QUOTE] OpenTK is just a wrapper around OpenGL, look up OpenGL tutorials and convert "glFoo" calls to "GL.Foo" calls. You'll get a lot of examples that way.
[QUOTE=Meatpuppet;39568628]Like a guide on making a simple game engine structure.[/QUOTE] From my experience, the best way is through refactoring. In other words, don't start by trying to make an abstract general-purpose game engine from the get-go. Instead, start by making a game. Don't worry about sloppy code, don't worry about imperfect solutions and hacky workarounds. Just make a simple game and make it work. By doing that, you will automatically realize which bits of logic can be reused, which components can be modularized and abstracted, etc. Through the steady refinement of code and the pursuit of new projects, you will eventually develop a decent game engine.
[QUOTE=Larikang;39570947]From my experience, the best way is through refactoring. In other words, don't start by trying to make an abstract general-purpose game engine from the get-go. Instead, start by making a game. Don't worry about sloppy code, don't worry about imperfect solutions and hacky workarounds. Just make a simple game and make it work. By doing that, you will automatically realize which bits of logic can be reused, which components can be modularized and abstracted, etc. Through the steady refinement of code and the pursuit of new projects, you will eventually develop a decent game engine.[/QUOTE] I tried that, but I couldn't even get past a working main menu. =\ and my program was so hard to debug that I couldn't fix it
Maybe C++ wasn't the right language for you then.
[QUOTE=WeltEnSTurm;39573942]Maybe C++ wasn't the right language for you then.[/QUOTE] Generally speaking C++ isn't the right language for you. Unless there's a specific reason to use C++ I'd use something else. Chances are it's going to be faster to write, easier to debug and have better/standard support for things like graphics, file handling etc.
If you're wanting to go into game development, I would say learning and using C++ would be high up on the priority list. Nothing is coming close to replacing the language (or C) in that regard. Unless you just stick to the mobile app platform.
C++ is the perfect language to throw at someone to see if they actually have an interest in programming or if they're there for the "i want to make vidya gamez when i grow up". As for Meatpuppet, a good way to structure your code is through finite state machines or game states in general. It's not "the" answer, but it's one of them. As for debugging. Use asserts, rather crash the program than returning NULL or -1 in cases where stuff SHOULD happen. Use exceptions for stuff that should be handled properly. Check and return immediately at the top of your functions instead of shit like this, makes it easier to debug. [code] if( !error ) { if( !error2 ) { main code } } [/code] [B]USE BREAKPOINTS INSTEAD OF COUT/PRINTF (in most cases)[/B]
Sorry, you need to Log In to post a reply to this thread.