Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Ziburinis

Pages: [1]
1
General / Re: Help with memory leaks [Solved]
« on: February 14, 2018, 05:54:18 am »
I think I fixed it, I forgot to make my base class destructor virtual. Déjà vu!

Thanks to anyone who read.

Really wish the GCC folks would make the delete-non-virtual-dtor warning come up more often for the sake of my sanity.

2
General / Re: Help with memory leaks
« on: February 14, 2018, 05:23:26 am »
Sorry, looks like I gave up a little too fast. I think I don't understand something about unique pointers. When I start the application with this code:
auto ptr = make_unique<DialogState>(this, k_Intro);

// Game Loop
while (window.isOpen()){
  ptr->handleTick();
  ...
  ptr->draw();
}
 
There are no memory leaks! But when I do the same thing with a vector:

vector<unique_ptr<GameState>> states;
states.emplace_back(make_unique<DialogState>(this, k_Intro));

// Game loop
while (window.isOpen()){
  states.back()->handleTick();
  ...
  states.back()->draw();
}
 

I get the leaks shown in the previous post. Am I doing something wrong here? The states vector is actually a member variable, but it should still go out of scope when the program ends.

3
General / Help with memory leaks [Solved]
« on: February 14, 2018, 03:11:10 am »
UPDATE: My base class destructor wasn't virtual. If I had a dollar....

UPDATE: You may want to skip this post and look at the second one.

Hello, I've been working on a game, it's about 2000 lines long, and I just needed to use Valgrind for the first time to find a segfault. I was surprised to see significant memory leaks all over the place. The leaks are in all of my backups, so I can't figure out where it was introduced, and I haven't been able to replicate it in a toy program. I'm hoping someone here will have some insight before I go nuts stripping it down to a minimum example. I've posted most of a Valgrind output here:
https://paste.debian.net/1010180/

I'm not using any dynamic memory allocation other than STL containers (no new or malloc). I use unique pointers for ownership and raw pointers elsewhere, but I can't think of any way they could be causing this. I'm also not doing anything weird with function pointers, or objects deleting themselves in weird ways, or anything like that.

I know that this looks like a false positive, since there's a lot from the graphics driver in there, but when I monitor the process's memory usage it seems to go up as I play the game, when no additional memory should be allocated.

It's also strange because if I don't call reserve on my vector<Text> of menu items then this block:
Code: [Select]
==30033== 29,784 (3,520 direct, 26,264 indirect) bytes in 1 blocks are definitely lost in loss record 2,038 of 2,053
==30033==    at 0x4C2D1FF: operator new(unsigned long) (vg_replace_malloc.c:334)
==30033==    by 0x138365: __gnu_cxx::new_allocator<sf::Text>::allocate(unsigned long, void const*) (new_allocator.h:111)
==30033==    by 0x1382AF: std::allocator_traits<std::allocator<sf::Text> >::allocate(std::allocator<sf::Text>&, unsigned long) (alloc_traits.h:436)
==30033==    by 0x137F77: std::_Vector_base<sf::Text, std::allocator<sf::Text> >::_M_allocate(unsigned long) (stl_vector.h:172)
==30033==    by 0x137B6D: sf::Text* std::vector<sf::Text, std::allocator<sf::Text> >::_M_allocate_and_copy<sf::Text const*>(unsigned long, sf::Text const*, sf::Text const*) (stl_vector.h:1260)
==30033==    by 0x1378B0: std::vector<sf::Text, std::allocator<sf::Text> >::reserve(unsigned long) (vector.tcc:73)
==30033==    by 0x136FBB: GameCore::Menu::init(sf::RenderWindow&) (menu.cpp:20)
==30033==    by 0x112C45: GameCore::DialogMenu::init(sf::RenderWindow&, unsigned short) (dialog_menu.cpp:20)
==30033==    by 0x12DD5D: GameCore::DialogState::init() (dialog_state.cpp:8)
==30033==    by 0x12E3C3: GameCore::App::pushState(GameCore::GameStateEnum, unsigned short) (app.cpp:75)
==30033==    by 0x12DFDA: GameCore::App::App() (app.cpp:23)
==30033==    by 0x13901B: main (main.cpp:6)

is replaced with this block:

Code: [Select]
==3732== 27,672 (1,408 direct, 26,264 indirect) bytes in 1 blocks are definitely lost in loss record 2,039 of 2,055
==3732==    at 0x4C2D1FF: operator new(unsigned long) (vg_replace_malloc.c:334)
==3732==    by 0x1380C5: __gnu_cxx::new_allocator<sf::Text>::allocate(unsigned long, void const*) (new_allocator.h:111)
==3732==    by 0x137FD9: std::allocator_traits<std::allocator<sf::Text> >::allocate(std::allocator<sf::Text>&, unsigned long) (alloc_traits.h:436)
==3732==    by 0x137E7D: std::_Vector_base<sf::Text, std::allocator<sf::Text> >::_M_allocate(unsigned long) (stl_vector.h:172)
==3732==    by 0x137A06: void std::vector<sf::Text, std::allocator<sf::Text> >::_M_realloc_insert<>(__gnu_cxx::__normal_iterator<sf::Text*, std::vector<sf::Text, std::allocator<sf::Text> > >) (vector.tcc:406)
==3732==    by 0x1378FE: sf::Text& std::vector<sf::Text, std::allocator<sf::Text> >::emplace_back<>() (vector.tcc:105)
==3732==    by 0x137636: GameCore::Menu::addItem(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (menu.cpp:96)
==3732==    by 0x11314A: GameCore::DialogMenu::generateItems(unsigned short) (dialog_menu.cpp:70)
==3732==    by 0x112E0D: GameCore::DialogMenu::init(sf::RenderWindow&, unsigned short) (dialog_menu.cpp:32)
==3732==    by 0x12DD5D: GameCore::DialogState::init() (dialog_state.cpp:8)
==3732==    by 0x12E3C3: GameCore::App::pushState(GameCore::GameStateEnum, unsigned short) (app.cpp:75)
==3732==    by 0x12DFDA: GameCore::App::App() (app.cpp:23)

Which originates from a fairly innocent looking function:

  void Menu::addItem(String &str) {
    sf::Text &text = m_items.emplace_back();
    text.setFont(SFML_assets::noto_mono);
    text.setString(str);
    text.setCharacterSize(SFML_assets::font_size);
    text.setFillColor( m_text_color );
    m_last_visible = min(m_items.size(), m_num_visible);
  }
 

And if I re-enable the rest of my code I also get leaks coming from Text::getGlobalBounds(), my vertex array, and elsewhere.

I wouldn't worry about it, but when all of the code is enabled it's leaking 260 kb of memory, and I plan to make it a larger idle game, which people might leave running for long periods of time. Can you think of anything dumb I could be doing, or could it be a false positive?

Sorry for being so long winded, any advice is appreciated!

4
General / Re: Will one SFML project run on different computers?
« on: August 22, 2016, 05:12:02 am »
The path is a system wide variable that tells the OS where to look for dll files. Google says you can see its value by running echo %PATH% in the command line.

^ serious brain fart on my part. I'm all foggy from allergy meds today, sorry.

PATH just specifies where it looks for executables. Here's the search path for DLLs:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx

5
General / Re: Will one SFML project run on different computers?
« on: August 22, 2016, 12:28:43 am »
If your error is still "libgcc_s_sjlj_1.dll missing", then as I said you have three options:

1. Statically link in the gcc library, as the earlier stack overflow answer suggested.
2. Include the necessary dll and put it in the proper directory during installation.
3. Remove the dependency (I'd guess this means compiling with visual studio).

I'm not a Windows guru, as you can probably guess. Hopefully another forum member will correct me if I'm wrong on any of this.

6
General / Re: Will one SFML project run on different computers?
« on: August 21, 2016, 11:04:16 pm »
Oh, it's because you installed MinGW/codeblocks/whatever it was, I assume. That would have put all of the gcc runtime libraries somewhere in your system path. If you installed MinGW on another computer, it would presumably run there, too.

The path is a system wide variable that tells the OS where to look for dll files. Google says you can see its value by running echo %PATH% in the command line.

The executable file lists the libraries it needs at the beginning, and when you start it the path variable is checked. On linux, you can print out where it's finding/not finding a library by running ldd executable. It looks like it's a bit more involved in Windows:
https://stackoverflow.com/questions/1993673/what-is-the-equivalent-of-linuxs-ldd-on-windows

7
General / Re: Will one SFML project run on different computers?
« on: August 21, 2016, 10:42:11 pm »
Regardless of what it does, the executable wants a library and it wont run until it finds it. You can either distribute your game with a dll file and put it somewhere the executable will find when it runs, or you can include it straight into your code, or you can try to remove the dependency.

I would recommend trying the link I posted, and if the resulting executable isn't too huge, and you don't get more errors, just go with that option.

8
General / Re: Will one SFML project run on different computers?
« on: August 21, 2016, 09:56:36 pm »
Did you try this?
https://stackoverflow.com/questions/35332463/in-codeblocks-with-compiler-gcc-libgcc-s-sjlj-1-dll-is-missing

Gotta love the way Microsoft handles shared objects :P

Basically, a .so or .dll file is an executable with entry points that other programs can find. So when you download a development library it comes with all of the header files, so that the compiler can say "there's a function called drawWindow() that I can find at this entry point in the run time library". The end user doesn't need the development library, but they still need the run time library.

A runtime library is usually dynamically linked, that is, a .dll (Windows) or a .so (Linux). This way, you can have multiple programs sharing the same library and reduce the size on your disk, the memory consumed, and the size of downloads.

I've never needed to statically link something, but it's more common in a Windows environment. My understanding is that all of the libraries are plopped into the executable, so you're assured it exists on your friends computer.

9
Window / Re: SOLVED X_SetInputFocus error
« on: August 15, 2016, 12:18:11 am »
It grabs all of the keys before ratpoison gets to them, so I have to run a pkill -9 a.out to close the window, but since I doubt many of my end users will be using ratpoison this is an acceptable work around.
...

I think I've got everything working now, it was all user error. Apologies to the dev if time was spent trying to track this down.

10
General / Re: Best way for organizing turn-based game
« on: August 14, 2016, 10:25:22 pm »
No problem  :)

Also the first for loop should have been "players.size" not "player.size", where players is the list of all players.

I should also add that if I wanted units to smoothly slide, I'd add int x_offset and y_offset, measured in pixels, to the Hero class, and if I was going to animate them, they'd have some enum members like "walk_right", "walk_left" which I'd use as indexes to my vector of animation vectors, that vector would then get copied into the animation list, and popped once the last frame was reached.

11
General / Re: Best way for organizing turn-based game
« on: August 14, 2016, 10:00:29 pm »
I would have something like this in Hero:
unsigned int xpos;
unsigned int ypos;

Then at some point:
for i < player.size
   for j < player.heros.size
      <whatever sets up the sprite to be drawn>

In my game I have a drawable vertex array holder class, much like the one in the tutorial. It has some quads set aside for sprites that move about, and a second array for un-textured vertexes. The class has a member function called update, which gets called when the player scrolls around or something has decided to move. This is the function where I would run the for loops above.

If I wanted to animate something, I would have a list of animation vectors, the vectors would hold indexes which would translate to rectangles in my texture. But I don't do much graphics intensive stuff in my games. SFML gives you a lot of flexibility, and there are probably other ways which are just as good, or better, than what I've suggested.

12
General / Re: Best way for organizing turn-based game
« on: August 11, 2016, 11:46:29 pm »
On inheritance you might read this:
https://gamedev.stackexchange.com/questions/14158/how-object-oriented-are-videogames

For your game states it may be perfectly fine, the worst problems tend to come from complex trees where it's simpler and easier to just have "bool can_swim" instead of "Class SwimmingMonster : public Monster".

As for storing data, the only certain way (that I know of) to keep someone from cheating is to have everything validated by a central server. If someone tries to hack the memory that the game is in to set their hero's attack to 5,000, the server has to catch it.

You can keep the casual player from editing their save files by using Cereal to save your classes in binary, then save a hash value of the file at the beginning. The game would check the hash when it loads the data. I play a lot of games on Kongregate, and almost any game that's remotely popular has a "save file hacker" online to get around this, so for this approach to work you'd have to get funky with moving bits around, as well as adding padding to the game binary itself, the way a virus does to resist disassembly.

So, if it's possible, stick with the server that validates data from clients.

13
General / Re: Best way for organizing turn-based game
« on: August 11, 2016, 10:06:26 pm »
That's a big question! I'm something of a newbie myself, but here's the approach I would take:

1. Find the right tools for the job. You know you'll be drawing 105 sprites, and probably a window with a combo box to choose attacks, a unit description, and hp bar. So make a quick prototype that draws some lorem ipsum content. I'm in the process of choosing a GUI library myself, and I'm currently leaning towards Crazy Eddie's, which is very popular and has tutorials. There are also SFML tutorials for drawing a grid of tiles.

2. Model your data as if there was no user interface at all. So you might have:
Code: [Select]
struct Tile {
  unsigned int sprite;
  bool is_passable;
};

struct Map {
  Tile tiles[size_x][size_y];
};

Class Player {
  vector<Hero> heroes;
  void doStatusEffects();
};
3. Tie the underlying data and the interface together. This will likely involve following examples for the GUI you pick. You may want to have a "Game" class, with a gamestate member that lets the flow of the game be altered to various menus, world maps, etc.

There is no substitute for just trying and getting frustrated when it comes to software architecture. You just have to try to think ahead, and refactor when something doesn't work. But here are some tips:
- Don't use inheritance just for the sake of it. Especially in C++, it creates more headaches than composition, especially if you aren't very experienced with the syntax.
- Code reuse is very important. Start with small functions and structures, use them to make bigger functions and structures.
- Have a good attitudes towards figuring out things you don't understand. It's better to be eager to learn, and be patient with getting your project done, than to rush and get angry at the computer for not understanding you.

14
Window / Re: X_SetInputFocus error
« on: August 11, 2016, 06:41:41 pm »
Hello, I'm trying to get a hello world program to work. It compiles, but when I run it I get

Code: [Select]
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  42 (X_SetInputFocus)
  Serial number of failed request:  80
  Current serial number in output stream:  89

I'm using ratpoison as my window manager, so I'm used to this sort of error. I saw that there was a closed issue for it on github, #991, so I compiled the latest code, and that didn't fix it. Normally I can grep setInputFocus and comment out the function that comes up and that fixes it, but I'm still getting the error after remaking and reinstalling. Can anyone think of a work around?

In case it matters, my uname -a:
Linux deb1 4.6.0-1-amd64 #1 SMP Debian 4.6.1-1 (2016-06-06) x86_64 GNU/Linux
And my graphics card is:
Radeon HD 6290

Thanks for reading, let me know if I should report it as a new issue, or if you think I should go pester the ratpoison people. The other library I saw it in, that I can remember, is nanogui, which may use some of the same boilerplate for OpenGL window stuff, so I don't have a good guess at whose bug it is, if it is indeed a bug.

I took another crack at this today. Opening a window in fullscreen doesn't give the error (derp on my part). It grabs all of the keys before ratpoison gets to them, so I have to run a pkill -9 a.out to close the window, but since I doubt many of my end users will be using ratpoison this is an acceptable work around.

15
Window / SOLVED X_SetInputFocus error
« on: August 07, 2016, 11:33:21 pm »
Hello, I'm trying to get a hello world program to work. It compiles, but when I run it I get

Code: [Select]
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  42 (X_SetInputFocus)
  Serial number of failed request:  80
  Current serial number in output stream:  89

I'm using ratpoison as my window manager, so I'm used to this sort of error. I saw that there was a closed issue for it on github, #991, so I compiled the latest code, and that didn't fix it. Normally I can grep setInputFocus and comment out the function that comes up and that fixes it, but I'm still getting the error after remaking and reinstalling. Can anyone think of a work around?

In case it matters, my uname -a:
Linux deb1 4.6.0-1-amd64 #1 SMP Debian 4.6.1-1 (2016-06-06) x86_64 GNU/Linux
And my graphics card is:
Radeon HD 6290

Thanks for reading, let me know if I should report it as a new issue, or if you think I should go pester the ratpoison people. The other library I saw it in, that I can remember, is nanogui, which may use some of the same boilerplate for OpenGL window stuff, so I don't have a good guess at whose bug it is, if it is indeed a bug.

Pages: [1]