Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,069 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,605 people online right now. Registration is fast and FREE... Join Now!




AccessViolationException

 
Reply to this topicStart new topic

AccessViolationException

nbarten
7 Apr, 2008 - 01:16 PM
Post #1

D.I.C Head
**

Joined: 30 Apr, 2007
Posts: 112



Thanked: 2 times
My Contributions
Hi all.

A few month ago, i started creating my own private server for a certain game. I've never been good with encryption/decryption, so first i never could start creating one... but then somebody wrote a dll-file with the functions in it, so i began.

Anyway, i've written the code for letting monsters or 'mobs' walk around. This is the class for the monster:

CODE
public class Mob
    {
        public String id, x, cy, fh;
        public String mid;
        public Boolean spawned;
        public Timer mobTimer = new Timer(1000);
        private int timerSeconds;

        public Mob()
        {
            spawned = false;
            timerSeconds = 0;
        }

       public void StartMob()
        {
            mobTimer.Elapsed += new ElapsedEventHandler(mobTimer_Elapsed);
            mobTimer.Enabled = true;
            
        }
        
        private void mobTimer_Elapsed(object source, ElapsedEventArgs e)
        {
            timerSeconds++;
            String data = "";
            //Global.timerMonster++;
            data = "9A 00";
            data += Work.DecimalToHex(int.Parse(mid), 4);
            //data = "9A 00 6F 0C 00 00";
            data += Work.DecimalToHex(timerSeconds, 2);
            data += "00 00 00 00 00";
            Global.allChars[0] = Packets.SendPacket(Global.allChars[0], data);
            
        }
        
        
    }


So, lets say, in a map i spawn some 20 monsters, everyone is an object of the class Mob, and for each object i call the StartMob() function, so each mob gets a timer (every second sends a packet to the client)

Now here's the problem, when i've many monsters like 20, my server crashes after some 2 - 4 seconds, and visual studio 2008 tells me the following:

Unhandled Exception: System.AccessViolationException: Attempted to read or
write protected memory. This is often an indication that other memory is corrupt.

The less monsters walk around, the less chance my server crashes...

I really don't know what causes this error ohmy.gif

Before i added the monster movement i had it just one time i think (when i was jumping together with someone else around). Also, when it crashes, visual studio points with the error message to this function (in another class):

content = Decrypt(this.maplechar.getSendIV(), content.Substring(8, content.Length - 8));

The Decrypt function is from the dll i use... it decrypts an incoming packet from the client (content).

Well... this error is really bugging me :S i hope somebody here knows something of this error.
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: AccessViolationException
7 Apr, 2008 - 01:36 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,198



Thanked: 213 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Is this DLL written in C++ you know? Because this type of error is caused typically when someone attempts to write information to a bad pointer (which points to protected memory). This is almost impossible if the user is using all managed code (pure .NET code) because all pointers are either valid or null. This is going to be a bug in the DLL and my guess is the more monster you have more the likelihood that a monster is going to run into this bad pointer or attempt to write/read from a pointer that is pointing to bad data or being accessed by another monster and failing.

Not sure what you can do about it but to see if there is a recent copy of the DLL out there or plan for the access violation with error trapping or adjust your game design to compensate.

sad.gif
User is offlineProfile CardPM
+Quote Post

nbarten
RE: AccessViolationException
7 Apr, 2008 - 10:21 PM
Post #3

D.I.C Head
**

Joined: 30 Apr, 2007
Posts: 112



Thanked: 2 times
My Contributions
QUOTE(Martyr2 @ 7 Apr, 2008 - 02:36 PM) *

Is this DLL written in C++ you know? Because this type of error is caused typically when someone attempts to write information to a bad pointer (which points to protected memory). This is almost impossible if the user is using all managed code (pure .NET code) because all pointers are either valid or null. This is going to be a bug in the DLL and my guess is the more monster you have more the likelihood that a monster is going to run into this bad pointer or attempt to write/read from a pointer that is pointing to bad data or being accessed by another monster and failing.

Not sure what you can do about it but to see if there is a recent copy of the DLL out there or plan for the access violation with error trapping or adjust your game design to compensate.

sad.gif


Thank you for your reply.

The dll is written in Delphi.

Seems i have to write the encryption/decryption part myself tongue.gif

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 07:01PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month