Opened 8 years ago

Closed 8 years ago

#6250 closed defect (worksforme)

AccessViolation every time Ogr.Open

Reported by: kellyelton Owned by: tamas
Priority: normal Milestone:
Component: CSharpBindings Version: 1.11.3
Severity: normal Keywords:
Cc:

Description (last modified by Mateusz Łoskot)

Ok, so I have some C# code here

string codeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
var thisDir = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(codeBase).Path)) + Path.DirectorySeparatorChar;
Directory.SetCurrentDirectory(thisDir);
//start up map engine
Environment.SetEnvironmentVariable("PATH",
	string.Join(Path.PathSeparator.ToString(), new string[] {
		thisDir + @"gdal\bin",
		thisDir + @"gdal\bin\gdal\csharp",
		thisDir + @"gdal\bin\ms\csharp",
	}) + Path.PathSeparator +
	Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Process), EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("OGR_SQLITE_CACHE", "256MB", EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("CPL_DEBUG", "ON", EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("CPL_LOG", "c:\\Temp\\log.txt", EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("CPL_LOG_ERRORS", "ON", EnvironmentVariableTarget.Process);

OSGeo.GDAL.Gdal.UseExceptions();
Ogr.RegisterAll();

var directdb = Ogr.Open(thisDir + "poly_spatialite4.sqlite", update: 0); //open for read only
directdb.Dispose();

Every time I run this I get an AccessViolation exception on Ogr.Open

I'm using gdal 1.11.3 and the csharp wrappers

I don't get this exception IF I turn off CPL_DEBUG or comment out Gdal.UseExceptions()

I'm also including the project I'm using to replicate this and all the files.

Change History (11)

comment:1 by kellyelton, 8 years ago

The code is here https://drive.google.com/file/d/0B2MHR61KzSMeanZ5cjBIaWtnclU/view?usp=sharing

I couldn't upload it because it was too big.

comment:2 by Mateusz Łoskot, 8 years ago

Component: defaultCSharpBindings
Description: modified (diff)
Owner: changed from warmerdam to tamas

comment:3 by kellyelton, 8 years ago

C# bindings aside...If I have CPL_DEBUG == OFF and exception throwing enabled...I won't get any exceptions....if I turn CPL_DEBUG == ON and I get an exception every time on OgrOpen...I'm first trying to figure out is that just noise in the library or is that actually something to worry about?

comment:4 by kellyelton, 8 years ago

After a little more testing, it seems this only happens when I'm debugging the program in my Visual Studio, going to try and track down what specifically causes this in VS.

comment:5 by Mateusz Łoskot, 8 years ago

I suspect, this problem might be related to mismatched Visual C++ run-time libraries between GDAL DLL, C# bindings, your app. Have a look at #3346 (also at #4291).

To confirm that's the problem, you will need to build GDAL (and C# bindings) from sources.

comment:6 by kellyelton, 8 years ago

Well it only happens when I'm debugging...If I don't attach the debugger, then it runs fine.

comment:7 by Mateusz Łoskot, 8 years ago

Well, it does not prove anything in case of this kind of 'undefined' behaviours. Surely, I may be lacking experience of C/C++ <-> .NET interactions.

comment:8 by kellyelton, 8 years ago

Running VS in /SafeMode didn't help.

comment:9 by kellyelton, 8 years ago

Wait sorry, I'm adding comments in here that are unrelated to the problem I have in the exact ticket here.

There was a secondary error due to visual studio. This bug I reported is happening with or without visual studio debugging, and with or without visual studio running itself.

This happens reproducibly every single time on every machine I've tested.

comment:10 by kellyelton, 8 years ago

Alright well I built 2.0.1 from source and it doesn't have this problem.

comment:11 by tamas, 8 years ago

Resolution: worksforme
Status: newclosed

Looks like this issue can be closed. To get rid of the mixed CRT problems, I'd suggest to test with the packages provided by http://www.gisinternals.com/

Note: See TracTickets for help on using tickets.