Ran into the "Tried to read or write protected memory" error message

Started by midiman, Fri 22/07/2016 00:40:09

Previous topic - Next topic

midiman

Let me begin by stating that in no way, shape or form, this is an urgent message as I didn't even make it past coding the first room. However, after adding a line that would make cEgo (yes, the standard guy) walk to a set coordinate in a room, the entire game stopped working. I tried to save the project and I ran into this wall of text

rror: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Version: AGS 3.3.5.7

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. ---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at ccCompileText(SByte* , SByte* )
   at AGS.Native.NativeMethods.CompileScript(Script script, String[] preProcessedScripts, Game game, Boolean isRoomScript)
   at AGS.Editor.NativeProxy.CompileScript(Script script, String[] preProcessedData, Game game, Boolean isRoomScript)
   at AGS.Editor.AGSEditor.CompileScript(Script script, List`1 headers, CompileMessages errors, Boolean isRoomScript)
   at AGS.Editor.Components.RoomsComponent.SaveRoomOnThread(Object parameter)
   at AGS.Editor.BusyDialog.RunHandlerOnThread()
   --- End of inner exception stack trace ---
   at AGS.Editor.BusyDialog.Show(String message, ProcessingHandler handler, Object parameter)
   at AGS.Editor.Components.RoomsComponent.SaveRoomButDoNotShowAnyErrors(Room room, CompileMessages errors, String pleaseWaitText)
   at AGS.Editor.Components.RoomsComponent.RecompileAnyRoomsWhereTheScriptHasChanged(CompileMessages errors, Boolean rebuildAll)
   at AGS.Editor.Components.RoomsComponent.AGSEditor_PreCompileGame(PreCompileGameEventArgs evArgs)
   at AGS.Editor.AGSEditor.PreCompileGameHandler.Invoke(PreCompileGameEventArgs evArgs)
   at AGS.Editor.AGSEditor.CompileGame(Boolean forceRebuild, Boolean createMiniExeForDebug)
   at AGS.Editor.Components.BuildCommandsComponent.TestGame(Boolean withDebugger)
   at AGS.Editor.Components.BuildCommandsComponent.CommandClick(String controlID)
   at AGS.Editor.ToolBarManager.ToolbarEventHandler(Object sender, EventArgs e)
   at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
   at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at AGS.Editor.ToolStripExtended.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Yes, that's an impressive amount of text, especially if you have no idea what most of it means.

I've looked on the forums for more about this question, but it seems like the problem is always something different and I've tried the following "Solutions" so to speak

A) Made a backup, deleted the original files, restored the backup, this did nothing
B) Restarted the computer and attempted to rebuild the files. As soon as I click Rebuild, I get the same error as above
C) looked in the control panel to see if the game is somehow running somewhere, I could not find this
D) Tried to put cEgo in different rooms to start, this did nothing either
E) Remove the new lines that I put in, this didn't work either

It seems that it's only this one game though, I tried making a new game and that seems to work fine.
So I have the following 2 questions

A) Can this be fixed somehow ?
B) How can I prevent this from happening in the future ?

I would appreciate all the help and suggestions you could offer.


Thanks in Advance

Midiman
-remember, there's no game that can't be beat-

Crimson Wizard

Hello Midiman.
The only part of error that may have any importance for you is first couple of lines, the rest is just for developers.

This error actually indicates that there is some very bad bug in the Editor, but it is uncertain what it is exactly. That could be something that happened hours before, but triggered only after.

I want to clarify: do you get this all the time with your project? If yes, could you upload it somewhere so that we could take a closer look at it and possibly find the cause of this problem?
Without this, I am afraid, there is not much we can do, because we won't even know where to start looking.

midiman

yes, this happens all the time with this one project. Like I said though, It's not much besides 1 testing room. I've uploaded the project onto https://dl.dropboxusercontent.com/u/62028528/jackofhearts.zip
Thanks for your quick response :smiley:

Crimson Wizard

Good news, this error is happening to me too, which means I at least will be able to investigate it. :)
I will check this as I get spare time, maybe on nearest weekends.

midiman

Once again, thanks for the quick reply :smiley: I'll be working on some other stuff in the meantime

Sent from my SM-G900V using Tapatalk


Gurok

This is a bug in the AGS parser. It should report "unexpected end of file", which would give you some idea of what's wrong. As CW said, this part is getting looked into.

There is also a problem with your code here. You aren't supposed to end a script file with the word "function" on its own. The word function should be followed by the other parts of a function declaration.

If you want to fix your code in the meantime, remove the stray "function" from room 1 or complete the function definition:

Code: ags
// room script file


function // <-- Remove this or finish filling it out, e.g. function MyFunction() { }


Despite the apparent severity of the error message from AGS, you should be fine to continue with your project (provided you avoid the situation outlined above).
[img]http://7d4iqnx.gif;rWRLUuw.gi

midiman

Whoops, that "Function" is a leftover from a failed code attempt. thanks for the tip

midiman

I don't know how it is over there, but once I remove that "function" the error message is gone. As soon as I add the "function" again, the error shows back up. I think my problem is solved :cheesy: thank you for helping

Crimson Wizard

Actually, in modern AGS "function" is silently replaced with "int", so it is trailing "int" that causes this.*

I made a test, and found that actually any basic type ("int", "float", "bool") placed in the end of script causes this memory error.


* BTW, completely unrelated, but I just had funny thought. Becuase function->int replacement is unconditional, following actually works:
Code: ags

function A()
{
  function z;
  z = 10;
}

Gurok

Yep. I wonder if we can make it a bit smarter. A regular expression looking for a legal identifier and a bracket following, perhaps. As I recall, this is a pre-compilation step.
[img]http://7d4iqnx.gif;rWRLUuw.gi

SMF spam blocked by CleanTalk