Access Violation when testing validity of pointer in linked static library

While constructing a plugin that utilizes a linked static library, I’ve run into a recurring access violation upon running the following test function. What confuses me is that the issue is rather specific to a handful of pointers within a struct defined in the static library. Testing the library externally with the same version of MSVC yields no issues:

From AnvilGen.cpp (my plugin):

#include "mcmap.h"

void UAnvilGen::TestMessage()
{
	if (IAnvilGenPlugin::isAvailable())
	{
		const char* AnvilPath = "..\\..\\..\\..\\..\\Anvil\\TestWorld\\";
		struct mcmap_region *Region = mcmap_region_read(0, 0, AnvilPath); // WORKS FINE
		struct mcmap_region_chunk *NewChunk = &Region->chunks[0][0]; // ALSO WORKS

		// ERROR ON THIS LINE
		struct mcmap_chunk *Chunk = mcmap_chunk_read(NewChunk, MCMAP_PARTIAL, 0);
	}
}

After calling TestMessage() on game start in a blueprint, the stack trace points to the line indicated above. More specifically, it directs me to the following pointer:

From mcmap.c (compiled in the static library):

struct mcmap_chunk *mcmap_chunk_read(struct mcmap_region_chunk *rc, mcmap_mode m, int rem)
{
	nbt_compression_type type;
	struct mcmap_chunk *c;
	struct nbt_tag *t, *p, *l;
	int8_t y_index;
	unsigned int x,y,z, i;

	//don't index into NULL struct
	if (rc == NULL || rc->header == NULL)  // <---- ERROR HERE @ rc->header
		return NULL;
    // ...continued

Before the above, rc->header was initialized like so:

//connect pointers
if (r->locations[z][x] >= 2)
	{
	//connect 5-byte chunk header
	r->chunks[z][x].header = (struct mcmap_region_chunk_header *)&(b[i]);
	//'r->chunks[z][x].data' will now point to a block of 'r->chunks[z][x].size' bytes
	r->chunks[z][x].data = &(b[i+5]);
	}
return;
}

What confuses me is that no other application throws an error with any of the functions in the static library, not even with the same version of MSVC used on UE4. This should be a fairly straightforward null check, but UE4 crashes each time an operation checks or uses said pointer.

From mcmap.h (in the include directory):

struct mcmap_region_chunk_header //5-byte metadata for each chunk
{
	uint8_t length[4]; 
	uint8_t compression;
}; // PACKED;   <--- Was originally packed, doesn't work in either case.

struct mcmap_region_chunk
{
	struct mcmap_region_chunk_header *header; 
	size_t size; 
	uint8_t *data;
};

Not sure if there is some convention of UE4 that I am missing, though I can’t see where this pointer could be going wrong; especially given that it is handled primarily outside the scope of the engine. I am using version 4.6.1 of the engine (binary).

If it helps at all here is the full call stack for the crash:

MachineId:47B46CF8496D1F25EACC6285281067E9
EpicAccountId:ed84c0429be34246916d939ef9f64b87

Access violation - code c0000005 (first/second chance not available)

UE4Editor_AnvilGen!mcmap_chunk_read() + 64 bytes [c:\users\jake\desktop\software\libmcmap_vs\libmcmap\mcmap.c:659]
UE4Editor_CoreUObject + 563956 bytes
UE4Editor_CoreUObject + 1348671 bytes
UE4Editor_CoreUObject + 1471421 bytes
UE4Editor_CoreUObject + 1477214 bytes
UE4Editor_CoreUObject + 1350042 bytes
UE4Editor_CoreUObject + 1621364 bytes
UE4Editor_CoreUObject + 1477214 bytes
UE4Editor_CoreUObject + 563956 bytes
UE4Editor_CoreUObject + 1475014 bytes
UE4Editor_Engine + 1640529 bytes
UE4Editor_Engine + 9918747 bytes
UE4Editor_Engine + 3683489 bytes
UE4Editor_Engine + 3792845 bytes
UE4Editor_Engine + 3803171 bytes
UE4Editor_Engine + 3805342 bytes
UE4Editor_UnrealEd + 4271756 bytes
UE4Editor_UnrealEd + 4561611 bytes
UE4Editor_UnrealEd + 4660963 bytes
UE4Editor_UnrealEd + 1801811 bytes
UE4Editor_UnrealEd + 6686342 bytes
UE4Editor!FEngineLoop::Tick() + 3876 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.6\engine\source\runtime\launch\private\launchengineloop.cpp:2214]
UE4Editor!GuardedMain() + 479 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.6\engine\source\runtime\launch\private\launch.cpp:131]
UE4Editor!GuardedMainWrapper() + 26 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.6\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() + 249 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.6\engine\source\runtime\launch\private\windows\launchwindows.cpp:202]
UE4Editor!__tmainCRTStartup() + 329 bytes [f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c:618]

I think the problem is with this line:

struct mcmap_region_chunk *NewChunk = &Region->chunks[0][0]; // ALSO WORKS

The issue isn’t rc->header, it’s just rc. rc can be both not equal to NULL and also be completely invalid. Calling rc->anything would be crashing you (if I’m right).

Thanks for the response. That would appear to be the case; even if I eliminate the check to rc->header, the program crashes later on when rc->data is passed in.

Still a little bit strange, as I’ve been using those lines to test the library without error in several different non-UE4 mediums. I have a slight suspicion that rc’s invalidity might be due to the library’s dependency on zlib to properly function; I noticed that the zlib DLL is included in the binaries for the engine, which I thought might extend to the runtime of the game (I’ve already linked the zlib object library), but maybe I’m wrong. Usually when zlib is missing, a window pops up to alert me of that fact, which hasn’t happened in this instance.

Found the source of my problem; the file I was attempting to access was on a different relative path to the source than it is to the binaries. Likewise, the struct was not valid when directed from the source, and UE4 crashed when attempting to access the pointers within it.