Witchie NL Posted August 20, 2007 Report Posted August 20, 2007 Ok i was making a bot and used linkedlists for the first time. Ive got an exeption error and an MSVC++ debug error while loading/closing the bot.(IMG below) Ive isolated the part where it couses the errors to this part of the code: BtyDat *t = new BtyDat(); memcpy(t->Owner, Owner, 20); t->Wins = getInteger(Wins, 10); t->Losses = getInteger(Losses, 10);'Owner', 'Wins' and 'Losses' are decleared and initialised before it. Who can tell me why this is coused and how to fix it. Thanks alot,Witchie http://members.lycos.nl/primoflip/errors.jpg
Samapico Posted August 21, 2007 Report Posted August 21, 2007 Not much details here... What's your BtyDat like?Also, do you delete t when unloading the plugin to free memory? At which line does it bring you if you hit debug?edit: It probably brings you into some !@#$%^&*embly crap... but check the call strack (CTRL+L) and find where the error comes from with that
Witchie NL Posted August 21, 2007 Author Report Posted August 21, 2007 void botInfo::LoadDat() { tell(makeEcho("Loading database entrees.")); BountyDat.clear(); for (int i=0; i<=1; i++) { if (GetSetting("Bounty.dat", "Account"+(String)i, "Owner")) { String Owner = GetSetting("Bounty.dat", "Account"+(String)i, "Owner"); String Wins = GetSetting("Bounty.dat", "Account"+(String)i, "Wins"); String Losses = GetSetting("Bounty.dat", "Account"+(String)i, "Losses"); BtyDat *t = new BtyDat(); memcpy(t->Owner, Owner, 20); t->Wins = getInteger(Wins, 10); t->Losses = getInteger(Losses, 10); tell(makeEcho("Account"+(String)i+" - Owner="+(String)t->Owner.msg+" Wins="+(String)t->Wins+" Losses"+(String)t->Losses)); BountyDat.append(t); } } tell(makeEcho((String)i+" Entrees loaded.")); } There isnt a debug button.Sorry my MSVC++ is dutch, its 'Close', 'Try again' and 'Ignore' the error window sais.
Witchie NL Posted August 21, 2007 Author Report Posted August 21, 2007 K i got this fixed.I had no idea what i was doing with some functions and that was the problem. I was using memcpy(t->Owner, Owner, 20); to a String type variable.
Samapico Posted August 21, 2007 Report Posted August 21, 2007 struct BtyDat { String Owner; int Wins; int Losses; BtyDat() { ZeroMemory(Owner, 20); Wins = 0; Losses = 0; } }; Actually, the ZeroMemory caused problems because you told it to set bytes from Owner to Owner+19 at 0... However, Owner is a String object... It actually is a 4bytes int that gives you the address where its data is (that's a pointer)So your program did not have access to the 16 following bytes. By changing Owner to a char[20], you allocate exactly 20 bytes for it, so the ZeroMemory will work. Either removing ZeroMemory or changing Owner to a char[20] would have fixed your problem. Simplest thing to do would be to keep the string, remove the ZeroMemory, and change the memcpy to: t->Owner = Owner;
Witchie NL Posted August 21, 2007 Author Report Posted August 21, 2007 k did that, thanks you.I aint a realy good coder yet, tho im improving quite fast. thanks alot.
Recommended Posts