Reloading dynamic layers and AccessViolation

Hi there,

I’m trying to get some code working to force the reload of a dynamic layer. Currently I added this:

// ***************************************************************
//		RestartBackgroundLoading()
// ***************************************************************
void CMapView::RestartBackgroundLoading(long OgrLayerHandle)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	// get the layer from the specified handle
	Layer* layer = GetLayer(OgrLayerHandle);
	// failure here will have already set ErrorMessage
	if (layer == nullptr) return;

	// reload layer in background thread
	if (layer->IsDynamicOgrLayer())
		layer->LoadAsync(this, _extents, OgrLayerHandle, true);
}

In addition to the required stuff to expose this on the COM/ActiveX object.

I can call it, and it seems to work - except after I added a shape to that dynamic layer.

At that point I get an access violation. I’m still trying to figure out where exactly as the stack traces aren’t much help. I’d just thought to verify here that the above could work or if I’m overlooking something? Would help to figure out if the violation is related to the reload or due to the addition.

cheers,
Mathijs

as it always goes, just after you post something you find something

I also have the access violation when zooming in/out so ignore this for now

I can confirm that this is unrelated to my code addition.

If I load a dynamically loaded layer and zoom out twice I get an access violation as well.

This is on the develop branch

Hello @Mathijs.Dumon

I just saw your post, and I have some questions.

  1. You have an additional parameter to LoadAsync (the boolean at the end). I don’t have that parameter; did you add that?
  2. By default (as I understand things) Dynamic layers don’t ‘reload’ except when extents change to an area that has not currently loaded. Did you modify LoadAsync in order to override that behavior? If so, can you provide your changes to that method?
  3. On what call, during the add shape process, do you get the access violation?
  4. I presume that you don’t get the access violation if you have not called your new method.

Thanks.
Jerry.

FOLLOW-UP:
I guess I’m still getting used to behavior of this discourse site. For some reason, I think I’m seeing the latest post, to which I reply, only then to discover there were more posts between the original post and my reply.

At any rate, now that I’ve seen your other posts, your crash would seem related be to the dynamic layer attempting to reload new extents as you zoom in and out. I will try to reproduce this. I wonder how much this feature is used by others, and whether it’s been fully ironed out.

Hi Jerry,

I needed the dynamic reload because we modify the data source outside of mapwingis. The change is triggered by user actions in a mapwindow plugin though, so we know when we have to reload the layer to get all features.

Since we need to do this several times during a user’s workflow, the performance hit of reloading the entire layer (and potentially other layers) starts adding up. Only reloading features within the current extent helps a lot.

The Boolean flag you saw is a bForce flag set to false by default. If set to true, the extents checks are skipped and the layer is always reloaded.

I have had access violations without adding features as well, but it’s hard to reproduce. This maybe indicates it’s related to a flaw in the locking of the loading thread/data. Sadly my C++ skills are somewhat lacking and I couldn’t pin-point the exact reason. I got get a usable trace a few times pointing to Layer.cpp line 381 and Ogr2rawdata at line 21 where callback (the async task object) was dereferenced (but not the options class).

I think this would be an awesome feature to get working correctly. I’d look into it, but I have more pressing needs for my client’s project at the moment, so it’s become a lower priority for me now. If you could spare a few moments that’d be real nice. I still need to update my fork of mapwingis, let me now if you want to check it out.