Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML 2.0: AccessViolationException in Text.DisplayedString  (Read 4395 times)

0 Members and 1 Guest are viewing this topic.

TobiasW

  • Newbie
  • *
  • Posts: 10
    • View Profile
SFML 2.0: AccessViolationException in Text.DisplayedString
« on: February 15, 2012, 05:36:08 pm »
Hello,

it seems that at random times DisplayedString cannot be read and prompts me with an AccessViolationException.

I've compiled a minimal example reproducing the problem - at least on my computer.

Code: [Select]
using System;
using SFML.Window;
using SFML.Graphics;

namespace Experiments.Executables {
    class TextTest {
        private RenderWindow app;

        public TextTest() {
            // Create the main window
            app = new RenderWindow(new VideoMode(800, 600), "SFML window");
            app.Closed += new EventHandler(OnClose);
        }

        public void Run() {
            // Start the game loop
            while (app.IsOpened()) {
                // Process events
                app.DispatchEvents();

                // Clear screen
                app.Clear();

                for (int i = 0; i < 100000; i++) {
                    new Text("Test").DisplayedString = "test";

                    /*
                     * System.AccessViolationException was unhandled
                          Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
                          Source=mscorlib
                          StackTrace:
                               at Microsoft.Win32.Win32Native.CoTaskMemFree(IntPtr ptr)
                               at SFML.Graphics.Text.sfText_GetString(IntPtr This)
                               at SFML.Graphics.Text.get_DisplayedString() in d:\dev\libs\C++\SFML-2.0\bindings\dotnet\src\Graphics\Text.cs:line 206
                               at Experiments.Executables.TextTest.Run() in D:\dev\Projekte\C#\Spiele\KinectTetris\Experiments\Executables\TextTest.cs:line 29
                               at Experiments.Executables.TextTest.Main(String[] args) in D:\dev\Projekte\C#\Spiele\KinectTetris\Experiments\Executables\TextTest.cs:line 44
                               at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
                               at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
                               at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
                               at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
                               at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
                               at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
                               at System.Threading.ThreadHelper.ThreadStart()
                          InnerException:
                     */
                    string str = new Text("Test").DisplayedString;
                }

                // Update the window
                app.Display();
            }
        }

        static void OnClose(object sender, EventArgs e) {
            // Close the window when OnClose event is received
            RenderWindow window = (RenderWindow)sender;
            window.Close();
        }

        static void Main(string[] args) {
            (new TextTest()).Run();
        }
    }
}


The high number for the for loop just accounts for the seemingly random nature of the error - I've had it with much lower amounts of calls in my code. In the above code, sometimes it crashes right at the start, sometimes I have to wait for up to a minute.

I am using the version of SFML 2.0 that was current a few days ago. Windows 7 x64, compiling for x86 in Debug Mode with .NET Framework 4.0 in Visual Studio 2010.

Cheers,
TobiasW