Xenonsmurf / FFxi-Navmesh-Builder

c# Application to help build navigation meshes for FFXI using collision data and Recast Detour.
GNU General Public License v3.0
12 stars 10 forks source link

[BUG] SystemAccessViolation upon calling LoadMesh #3

Closed Darkdoom22 closed 3 years ago

Darkdoom22 commented 3 years ago

Description:

After instantiating the FFXI Nav Class

            _CurrentMeshInstance = new Ffxinav();

I then attempt to load a mesh

        public bool LoadMesh(int zoneId)
        {

            if (zoneId == 0)
                return false;

            _MeshFilePath = _GetMeshFilePath();

            if (!File.Exists(_MeshFilePath))
                return false;

            _CurrentMeshInstance.LoadNavMesh(_MeshFilePath);

            bool meshEnabled = _CurrentMeshInstance.IsNavMeshEnabled();

            Debug.WriteLine($"NavMesh loaded for {DupesResources.Zones[zoneId]} {meshEnabled}");
            return meshEnabled;

        }

the file path - String curZoneMeshPath = $"{Directory.GetCurrentDirectory()}\\Dumped NavMeshes\\{DupesResources.Zones[Core.FFXI.World.ZoneID]}.nav";

This throws a SystemAccessViolation exception - Attempted to read or write protected memory 99% of the time it is called, very rarely the mesh loads properly. I've opened the meshes up in Recast and confirmed that they have dumped correctly.

To Reproduce Instantiate Instance, attempt to load a mesh.

Expected behaviour The NavMesh to load and then be usable for pathfinding.

Screenshots Call Stack: CallStack

Desktop (please complete the following information):

Additional context My application is built in c# using .net 5 I have tried using different directories occurs with Any CPU Release/Debug and x86 Release/Debug build options Single stepping through and looking at the disassembly the faulting instruction seems to be in your error handler so it appears the issue occurs somewhere before the faulting instruction the faulting instruction set is

MOV EAX, dword ptr [this + 0xce0] //this+0xce0 derefs to 00000000
CMP byte ptr [EAX + 0x03C], 0x0 //Access violation, EAX is 0x00000000 and 0x0000003C is not valid memory to deref

the function these instructions are in is at (FFXINAV.DLL+1F210), no symbols for this one so I can't give you a clearer idea of which function it is unfortunately but its called from Catch and Catch_All.

No additional information is provided in the log file - presumably because the crash occurs before the .dll is able to log anything.

This is with the most recent FFXINAV.Dll posted (1.0.1.4?) and imports.cs available on the git, hopefully I've just missed something silly and this is easy to solve.

Look forward to hearing back, thank you!

Xenonsmurf commented 3 years ago

Hi, sorry you are having trouble with this. I will look into it and get back to you asap.

In the meantime.

Please make sure you are running visual studios as admin.

Also you should be able to enable logging with the DLL under navmesh settings, that might be able to give you an idea where it's failing.

Xenonsmurf commented 3 years ago

Please download version 1.0.1.5 this issue should now be fixed, I have tested multiple times with different meshes and have been able to load the navmeshes.

https://github.com/xenonsmurf/Ffxi_Navmesh_Builder/raw/main/FFXINAV.dll

example

private readonly string _navFile = $@"{Application.StartupPath}\Dumped NavMeshes\100.nav";

private void loadMeshBtn_Click(object sender, EventArgs e) { if (File.Exists(_navFile)) AddDebugText(Nav.LoadNavMesh(_navFile) ? "FFXINAV.dll: NavMesh loaded." : "FFXINAV.dll: Unable to load NavMesh."); else AddDebugText("FFXINAV.dll: Unable to load NavMesh, File does not exist."); }

please let me know if this is now fixed.

Darkdoom22 commented 3 years ago

Successfully loaded some meshes and calculated some paths, looks like it's fixed.

Really appreciate the speedy response, thank you :). 👍

Xenonsmurf commented 3 years ago

np, glad it's working for you.