Unknown error!

I switch to mysql for my server recently, and it comes up with "Crystal online.exe has stopped working..."
Then i click debug and theres a green arrow pointing to this code:
1
2
3
4
5
6
7
8
9
10
11
			int denyammount=0;
			vector <int> denyreason;
			for(unsigned int i=0; i<players::list.size(); i++)
			{
				if(players::list[i]->username == plr->username && players::list[i]->loggedIn)
				{
					denyreason.push_back(2);
					denyammount++;
					server::print("this account is already logged in! ["+plr->username+"]", game::c_red);
				}
			}


Im not sure if the green arrow is actually, here is an image of this error:
http://oi40.tinypic.com/34gk8d3.jpg
And here is the whole code:
Here is the whole case (Not the whole file though)
http://pastebin.com/ipHn5H7y

What is wrong!?!

This error only happens if i wait for all the monsters to spawn, i can login before but not afterwards. there are only 3 monsters in total.

Even if i delete all the monsters after three have been spawned, then it still doesnt work. :S
Last edited on
A green arrow like that means it's the next line to be executed. A yellow arrow is the actual line being executed. To me, this suggests that it's crashing inside the push_back call.

I don't immediately see anything wrong with the code. The push_back looks harmless. Are you doing any multithreading?
Yepp, a couple of threads, why? :)
The thing is, this code worked when i was using the ini file saving method, and i diddnt add any threads when i changed to mysql :S
Last edited on
Well, if you happen to have multiple threads trying to push_back to the same vector you'll have problems. You'll need to synchronize it somehow.
If you have multiple threads accessing the vector at the same time, it could cause a memory error internally in the vector. You need to put some kind of lock on the vector, such as a mutex.
Could you give me an example? :)

Also, after the monster spawns, it doesnt change its own vector anymore, but it still screws up.

And also, if one monster is spawned, the game works >.<
Last edited on
It depends on what library your using for the threads, but it should provide some kind of locking mechanism.
Im just using Microsoft visual studios :)
Could i use concurrent_vector??
Last edited on
Uhhh, i give up :/ ill just merge the two threads :/

May i ask though, why did this only happen when i switched to mysql instead of ini reading..? i didnt change anything else >.<
Last edited on
Perhaps the different way of loading data created/removed some lag, causing both threads to access the vector at the same. You could try concurrent_vector, but I haven't seen it ever before, so I'm not sure how you would use it.
I tried it, it worked, BUT it doesnt allow you to remove stuff from the vector, which is the main function i need >.<
Topic archived. No new replies allowed.