Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C# sample attempted to read or write protected memory.
#12
I somewhat reproduced the issue:

  1. Using SharpDevelop 5.1 (I had this already installed).
  2. Created a simple console application targeting .NET 2.0 and C# 2.0
  3. Added "Tilengine.cs" and "Platformer.cs"
  4. Copied 32-bit versions of "Tilengine.dll" and "SDL2.dll" to the project root folder
  5. Build without problems
  6. Run from the debugger, hitting F5
I can se that a full frame is generated, but then it crashes with the following message:

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

   at Tilengine.Window.TLN_DrawFrame(Int32 time)
   at Tilengine.Window.DrawFrame(Int32 time) in d:\Tilengine\samples\csharp2\Tilengine.cs:line 808
   at Platformer.Main(String[] args) in d:\Tilengine\samples\csharp2\Platformer.cs:line 116

Commented out line 76 in Platformer.cs (// engine.SetRasterCallback(callback);):
It doesn't crash at all, the frame is partially drawn because it lacks the raster effects but it runs as expected.

Restored line 76 and inserted a return in line 130, just at the beggining of the MyRasterEffects() function:
It crashes again. So it's definitely something with the delegate manager in C#

Copied the generated .exe file from /bin/Debug to the root folder and executed it outside the debugger, double clicking it:
It crashes.

Changed project properties: Set to C# 5.0 and .NET 4.0:
It crashes when running from the debugger, but if I copy the resulting .exe from bin/Debug to the root folder and execute it directly, it DOES NOT crash.

So it seems to be a combination of the environment, the .NET target and the debugger...
Reply


Messages In This Thread
RE: C# sample attempted to read or write protected memory. - by megamarc - 09-01-2018, 05:55 PM

Forum Jump:


Users browsing this thread: 4 Guest(s)