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

Author Topic: AccessViolationException on Draw  (Read 4664 times)

0 Members and 1 Guest are viewing this topic.

WilliamK2H

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
AccessViolationException on Draw
« on: September 30, 2019, 10:07:50 pm »
A person got this error, seems to be very rare and I cant really figure out why it appeared.

Quote
Application: K2HGame.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
   at SFML.Graphics.Text.sfRenderTexture_drawText(IntPtr, IntPtr, MarshalData ByRef)
   at SFML.Graphics.Text.Draw(SFML.Graphics.RenderTarget, SFML.Graphics.RenderStates)
   at SFML.Graphics.RenderTexture.Draw(SFML.Graphics.Drawable)
   at K2HGame.SFML_Utils+RenderSurface.Draw(SFML.Graphics.Drawable ByRef)
   at K2HGame.SFML_Utils.DrawText(RenderSurface, System.String, Int32, Int32, Int32 ByRef, UInt32)
   at K2HGame.modText.DrawText(Int32, System.Object, System.Object, System.String, Int32 ByRef, UInt32)
   at K2HGame.modPlayer.BltPlayerName(Int32)
   at K2HGame.GameLoop.Start()
   at K2HGame.DataHandlerPlayer+_Closure$28-0._Lambda$0()
   at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

Code that it occured in:
 
   Public Shared Sub DrawText(surface As RenderSurface, text As String, x As Integer, y As Integer, ByRef color As Integer, Optional fontSize As UInteger = 13)
        Try
            If surface.Font Is Nothing Then
                Return
            End If
            Dim output As New SFML.Graphics.Text(text, surface.Font, fontSize)
            'Dim red As Byte = color >> 16 And 255
            'Dim green As Byte = color >> 8 And 255
            'Dim blue As Byte = color And 255

            Dim convColor = ColorTranslator.FromOle(color)
            'Outline
            output.Color = New SFML.Graphics.Color(0, 0, 0)
            output.Position = New SFML.System.Vector2f(x + 1, y)
            surface.Draw(output)
            output.Position = New SFML.System.Vector2f(x, y + 1)
            surface.Draw(output)
            output.Position = New SFML.System.Vector2f(x - 1, y)
            surface.Draw(output)
            output.Position = New SFML.System.Vector2f(x, y - 1)
            surface.Draw(output)
            'Text
            output.Position = New SFML.System.Vector2f(x, y)
            output.Color = New SFML.Graphics.Color(convColor.R, convColor.G, convColor.B)
            surface.Draw(output)

            output.Dispose()
        Catch ex As Exception
            MainHandler.LogException("DrawText", ex)
        End Try
    End Sub

        Public Sub Clear()
            Try
                renderTexture.Clear(backGroundColor)
            Catch ex As Exception
                MainHandler.LogException("Clear", ex)
            End Try
        End Sub

        Public Sub Draw(ByRef drawable As Graphics.Drawable)
            Try
                If Not isRendering Then
                    Clear()
                    isRendering = True
                End If
                renderTexture.Draw(drawable)
            Catch ex As Exception
                MainHandler.LogException("Draw", ex)
            End Try
        End Sub
 

Any ideas are appreciated!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: AccessViolationException on Draw
« Reply #1 on: October 02, 2019, 11:41:36 pm »
Some pointer is getting scrambled i.e. points to a wrong location.
I'd suggest to attach the debugger and check all the values.

Also, don't forget to call Display() on your render texture.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything