# Good multiplayer game design?

**URL:** <https://discourse.libsdl.org/t/good-multiplayer-game-design/13181>\
**Category:** SDL Development\
**Created:** [March 26, 2006, 5:59pm UTC](https://discourse.libsdl.org/t/good-multiplayer-game-design/13181 "2006-03-26T17:59:57Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![Patrick\_Boenzli](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/p/8dc957/32.png) [@Patrick\_Boenzli](https://discourse.libsdl.org/u/Patrick_Boenzli)\
**Post date:** [March 29, 2006, 10:19am UTC](https://discourse.libsdl.org/t/good-multiplayer-game-design/13181/21 "2006-03-29T10:19:23Z")

</div>

> Hmm… Weird, the error seems to be on the size() method of  
> std::vector… But how can it cause errors? :-/

There is nothing wrong in your code snippet. I guess that you have a  
problem with the vector itself: does this-\>players realy exist @ this  
specific moment? Because if not, you will definitly get this segfault.  
This would be the simpler case. Another possibility is, that you write in  
the address region of your reference and point it to another (protected)  
memory region.

In both cases, try using valgrind to check your memory management.

> **[Valgrind Home](https://valgrind.org/)**
>
> Official Home Page for valgrind, a suite of tools for debugging and profiling. Automatically detect memory management and threading bugs, and perform detailed profiling. The current stable version is valgrind-3.23.0.

good luck,  
patrick\> ===============

> # … _Find_ if (this-\>players.size() \>= MAXPLAYERS) … _Find again_ for (int p = 0; p \< this-\>players.size(); p++) … _Find again_ for (int p = 0; p \< this-\>players.size(); p++) … _No more_
> 
> What the heck is wrong? ☹ I’m sure this is one of those errors you  
> can’t figure out but then when you do, you say “Heck! I’m so stupid!”.  
> Can anyone see what’s wrong? Thanks! 😉
> 
> * * *
> 
> SDL mailing list  
> SDL at [libsdl.org](http://libsdl.org)  
> [http://www.libsdl.org/mailman/listinfo/sdl](http://www.libsdl.org/mailman/listinfo/sdl)

---

<div class="post-metadata">

**Author:** ![Leo\_M\_Cabrera](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/l/bcef8e/32.png) [@Leo\_M\_Cabrera](https://discourse.libsdl.org/u/Leo_M_Cabrera)\
**Post date:** [March 29, 2006, 10:05pm UTC](https://discourse.libsdl.org/t/good-multiplayer-game-design/13181/22 "2006-03-29T22:05:11Z")

</div>

Hmm… :-/ Alright, the network variable (SockHnd pointer) was a global  
variable, now I made a local in main() func, and I passed that to the  
threads. Now, the error is the same, only it occurs on the begin()  
function, not the size() function… ☹

I’m not messing with memory in this program, so it shouldn’t be a memory  
problem… What else could it be? Thanks! 😉

---

<div class="post-metadata">

**Author:** ![Jeff\_Jackowski](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/jeff_jackowski/32/340_2.png) [@Jeff\_Jackowski](https://discourse.libsdl.org/u/Jeff_Jackowski)\
**Post date:** [March 30, 2006, 12:06am UTC](https://discourse.libsdl.org/t/good-multiplayer-game-design/13181/23 "2006-03-30T00:06:15Z")

</div>

> Hmm… :-/ Alright, the network variable (SockHnd pointer) was a global  
> variable, now I made a local in main() func, and I passed that to the  
> threads. Now, the error is the same, only it occurs on the begin()  
> function, not the size() function… ☹
> 
> I’m not messing with memory in this program, so it shouldn’t be a memory  
> problem… What else could it be? Thanks! 😉

The problem does sound like a memory issue. You probably should check the  
value of the this pointer in a debugger before the fatal call to see if it  
is any good. As already mentioned, valgrind is an awesome tool to help  
track down these problems.

Don’t forget that just by running your program you are messing with  
memory. The question is one of messing up memory. It is very easy to do.On Wed, 29 Mar 2006, Leo M. Cabrera wrote:

–  
Jeff Jackowski  
[http://ro.com/~jeffj/](http://ro.com/~jeffj/)

---

<div class="post-metadata">

**Author:** ![Leo\_M\_Cabrera](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/l/bcef8e/32.png) [@Leo\_M\_Cabrera](https://discourse.libsdl.org/u/Leo_M_Cabrera)\
**Post date:** [March 30, 2006, 1:56am UTC](https://discourse.libsdl.org/t/good-multiplayer-game-design/13181/24 "2006-03-30T01:56:40Z")

</div>

HOOOOOOOOOLD up a minute! =-O  
Both threads are running at the same time… The TradePlayers thread  
runs before any player was found… Let me try fixing that… 😛  
Thanks! 😉

---

<div class="post-metadata">

**Author:** ![Leo\_M\_Cabrera](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/l/bcef8e/32.png) [@Leo\_M\_Cabrera](https://discourse.libsdl.org/u/Leo_M_Cabrera)\
**Post date:** [March 30, 2006, 3:29am UTC](https://discourse.libsdl.org/t/good-multiplayer-game-design/13181/25 "2006-03-30T03:29:39Z")

</div>

I came to this window twice to say I found the bug, but both times I  
realized that I hadn’t half way thru the message… ☹

I found one thing though: My send and receive functions both receive  
data! Is that the problem? 😛  
I also wanted to ask, does the char pointer for SDLNet\_TCP\_Recv need to  
be initialized? I just declared the variables with their lengths…  
Thanks! 😉

[Previous page](https://discourse.libsdl.org/t/good-multiplayer-game-design/13181.md?page=1)
