Dec 27, 2014 at 8:41pm UTC
So, I'm making a game using SFML and cppdb( http://cppcms.com/sql/cppdb/ - I use it in server code ). I have 2 C++ projects. One is for server, and one is for client. Client works perfectly... Client has only basic functions for now (login, register, reset pass)... When I use login in my client and try to login with this acc:
Email:test@test.com
Password:test
everything works perfectly.
But when I try to login with this account:
Email:starfighter898@gmail.com
Password:test
I get memory heap in server ...
Its... really weird...
Here is the code(server):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
#pragma region LOGIN
else if (m == "login" )
{
std::string password;
std::string email;
std::string ip;
packet >> email >> password >> ip;
if (priv::isValidEmailAddress(email.c_str()))
{
if (password.size() > 0 && password.size() < 51)
{
if (email.size() > 2 && email.size() < 255)
{
#pragma region EMAIL CHECK
int existsemail = 0;
cppdb::result r = sql << "SELECT * FROM users WHERE email=?" << email << cppdb::row;
if (!r.empty())
existsemail = 1;
#pragma endregion
if (existsemail == 1)
{
#pragma region PASSWORD CHECK
int existsUser = 0;
cppdb::result re = sql << "SELECT * FROM users WHERE email=? AND password=?" << email << password << cppdb::row;
if (!r.empty())
existsUser = 1;
#pragma endregion
if (existsUser == 1)
{
pl[i].Password = password;
pl[i].Email = email;
pl[i].Ip = ip;
#pragma region GET DATA
cppdb::result res = sql << "SELECT * FROM users WHERE email=?" << email << cppdb::row;
if (!res.empty()) {
pl[i].Username = r.get<std::string>("username" );
pl[i].HasChat = (r.get<int >("hasChat" ) == 1);
pl[i].IsAdmin = (r.get<int >("isAdmin" ) == 1);
pl[i].IsBanned = (r.get<int >("isBanned" ) == 1);
pl[i].IsMod = (r.get<int >("isModerator" ) == 1);
pl[i].PlId = r.get<std::string>("id" );
}
#pragma endregion
sql << "UPDATE users SET ip_login=? WHERE email=?" << ip << email << cppdb::exec;
sf::Packet successMsgData;
successMsgData << "login" << "success" /*WE LOG IN*/ << pl[i].Username << pl[i].HasChat <<
pl[i].IsAdmin << pl[i].IsBanned << pl[i].IsMod << pl[i].PlId << email << password;
pl[i].Send(successMsgData);
}
else
{
sf::Packet errEmailMsgData;
errEmailMsgData << "login" << "err" /*ERROR OCCURED*/ << 6/*ERROR ID*/ ;
pl[i].Send(errEmailMsgData);
}
}
else
{
sf::Packet errEmailMsgData;
errEmailMsgData << "login" << "err" /*ERROR OCCURED*/ << 5/*ERROR ID*/ ;
pl[i].Send(errEmailMsgData);
}
}
else
{
//Same as above(I did it to reduce code for you to read)
}
}
else
{
//Same as above(I did it to reduce code for you to read)
}
}
else
{
//Same as above(I did it to reduce code for you to read)
}
}
#pragma endregion
Last edited on Dec 27, 2014 at 8:45pm UTC
Dec 28, 2014 at 1:06am UTC
It's not clear what the pl
stuff is.
What line does it crash on?
Dec 28, 2014 at 11:30am UTC
Run it as a program in a debugger, the program will stop and break into the debugger when you hit the error.
Dec 28, 2014 at 12:12pm UTC
It doesnt crash/hit the error when I run it in debug mode... -.-
So, is the problem in my .dll files?
Last edited on Dec 28, 2014 at 12:15pm UTC
Dec 28, 2014 at 12:23pm UTC
No. Are you building it the same way when you run it as a service and in the debugger? i.e. are you running them both as release?
Dec 28, 2014 at 2:35pm UTC
Huh...
First I built it in Visual C++ in release mode:
Tried to log in with that 'problematic' user....
Server crashed...
Then I built it in Visual C++ in debug mode:
Again tried to log in with that 'problematic' user...
Everything worked perfectly...
Sorry I'm not familiar with debuggers...?
Argh... Sorry :(
Dec 29, 2014 at 1:18pm UTC
The debug heap has a different layout, it has space for diagnostic info.
I am asking you to run the release build in the debugger, not a debug build.
It looks like you've corrupted the heap somehow. Without understanding your code, all I do is work backward from the crash.
Last edited on Dec 29, 2014 at 1:18pm UTC
Dec 29, 2014 at 9:14pm UTC
Heh, I just fixed it!!! Thought, I didn't run it in debugger. I always wanted to replace cppdb with MySQL Connector C++ in my server code. And I just replaced it.
Also, I rewrote whole server code(to get rid of some other bugs too)... and it works perfectly now!!! :D
Thanks for help!
Last edited on Dec 29, 2014 at 9:14pm UTC