Page 1 of 1

[C++] Game crashes after I split the code

PostPosted: 13 Dec 2009, 09:47
by Andrew
Hi guys,

I need some help figuring out an issue I am having after I split my code base into two binaries. Client and Server.

Here's the command to get the code along with a guide on compiling it. (See the building on linux section)

{l Code}: {l Select All Code}
bzr pull lp:~andrewfenn/hardwar/binarysplit

It compiles fine for me, the problems happen when running the server. Code for interacting with sqlite which I haven't changed, just moved to a different object now crashes. If anyone could help me debug this it'd be great! :D

{l Code}: {l Select All Code}
andrew@andrew-laptop:~/programming/hardwar2/bin$ gdb ./server
This GDB was configured as "i486-linux-gnu"...
(gdb) run
Starting program: /home/andrew/programming/hardwar2/bin/server
[Thread debugging using libthread_db enabled]
Starting server
Port:26500
[New Thread 0xb62afa70 (LWP 8550)]
[New Thread 0xb61aeb90 (LWP 8553)]
[Thread 0xb61aeb90 (LWP 8553) exited]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb62afa70 (LWP 8550)]
0xb7b3620f in openDatabase (zFilename=0x8f6a7d4 "world/default.db", ppDb=0x4, flags=6, zVfs=0x0) at sqlite3.c:88945
88945   sqlite3.c: No such file or directory.
   in sqlite3.c
Current language:  auto; currently c

Re: Game crashes after I split the code

PostPosted: 14 Dec 2009, 12:40
by Zlodo
It seems that opendatabase crashes because ppDb is a bad pointer ( 0x4 ). Digging up a bit I think that the GameManager singleton isn't created properly because of this in GameManager.cpp:

GameManager* GameManager::mGameManager;

Is not initialized to null. Try with GameManager* GameManager::mGameManager = NULL;

(I might be completely wrong though as seen as I just gathered this from the source code, I'm at work and don't have what I need at hand to build it)

Re: Game crashes after I split the code

PostPosted: 14 Dec 2009, 16:47
by Andrew
At first I thought this too, however I removed the singleton and it still doesn't work. The class that calls LevelManager is GameManager if that makes things easier to understand.

I updated the branch with my attempts, so far however I still haven't been able to figure it out.

Re: Game crashes after I split the code

PostPosted: 14 Dec 2009, 17:17
by Zlodo
Ok, so reading through the code again (still not able to compile it myself):

in the constructor of ServerMain, you first call ServerMain::setup() and then store the GameManager's singleton address in mGameMgr.

However, at the end of ServerMain::setup() you seem to dereference mGameMgr before it's initialized:
return mGameMgr->setup();

Also I would suggest removing the default constructor in ServerMain, so that if you forget to pass ServerMain constructor's parameters it won't compile instead of crashing at runtime.

Re: Game crashes after I split the code

PostPosted: 19 Dec 2009, 09:17
by Andrew
Tried both suggestions. I got rid of the singleton and constructor however it's still borking on that specific sqlite line.

Re: Game crashes after I split the code

PostPosted: 19 Dec 2009, 12:49
by Andrew
I've been looking in my design and I have decided to completely restructure the code. I'll let you know how I progress. :)

Re: Game crashes after I split the code

PostPosted: 20 Dec 2009, 15:32
by Andrew
Just to give everyone an update. After moving everything around it's working. :D