Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C# sample attempted to read or write protected memory.
#11
But the 64-bit version literally won't even run with the DLL that comes with it, and I have no clue how I could ever get the 32-bit version to work in a million years. What could possibly be wrong?
Reply
#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
#13
Been messing around with this some more because this annoying me now, I got 64bit to work without changing any code just creating new project and select c#5.0 and 4.5.1 and it works in debug but not release but 32bit wasnt working at all, my wife looked changed the file allignment to 2048 and put the tilengine.cs in it owns class library and now everything works ....... not sure if was just a fluke but it all works now in sharpdevelop, now i was install vs2017 this morning at the same time but shes a c# developer so i defer to her wisdom
Reply
#14
Thank for your experience man!

Nowadays, any end-user application sits at the top of a huge mountain of third-party software: libraries, frameworks, runtimes, OS services... In my daily work as a professional developer I've seen similar issues. You cannot expect to know why something strange suddenly happens, but just to find another combination in which the issue disappears.

Your wife seems like a C# guru, kudos for her Cool
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)