locked
DirectX LoaderLock RRS feed

  • Question

  • I found a C Sharp Pacman game, downloaded and converted to VB NET - It uses DirectX for audio and when the form starts I get this:

    LoaderLock was detected
    Message: DLL 'C:\WINDOWS\assembly\GAC\Microsoft.DirectX\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

    I have changed the target to .NET 2.0, 3.5, 4.0 and the Processor to x86 as was suggested elsewhere, Many places suggest ignoring the exception, which causes the game to hang at random. The original code does the same thing.

            Public Sub New(ByVal Owner As System.Windows.Forms.Control)
                _bufferDesc = New BufferDescription()
                _bufferDesc.GlobalFocus = True
                _bufferDesc.Control3D = True
                _soundDevice = New Device() ' **** Exception Line ****
                _soundDevice.SetCooperativeLevel(Owner, CooperativeLevel.Normal)
            End Sub
    

    from the Original code:

    _sndBackground = new GameSound(_picGameBoard); // **** Exception Line ****
    

    Workaround ? Or should I just rewrite the sound functions ?

    Saturday, December 31, 2016 11:42 PM

Answers

  •  Here is the link to my OneDrive where you can find the zip file called "Pacman converted from CSharp".  It contains the whole project folder including the text file i mentioned above.

     My OneDrive Link

     I also noticed a problem with the siren but,  i think i got that fixed (i think).  I also fixed one of the spots that needed some stuff disposed.  There are probably more though.  I left a few comments in those spots that i modified.  There was more that i did not comment though.

     I also see there was a tmrDie Timer that was not being used that i deleted from the project and i also see there is a blank sub called AnimateDie or something like that in one of the classes.  I am guessing that the author did not finish writing the full code or finish fixing all the bugs in it.


    If you say it can`t be done then i`ll try it

    • Marked as answer by Devon_Nullman Monday, January 2, 2017 5:19 PM
    Monday, January 2, 2017 1:30 AM

All replies

  • One must disable the managed debugging assistant for the DirectX 9c. Not sure the rest.

    This is a VS 2015 screen shot. See where loader lock is unchecked?

    Sunday, January 1, 2017 12:07 AM
  • "One must disable the managed debugging assistant"

    When I do that, the program hangs on load or shortly after.

    Sunday, January 1, 2017 5:09 AM
  • "One must disable the managed debugging assistant"
    When I do that, the program hangs on load or shortly after.

    There should be no need to instantiate that object in the constructor.  Move the code so it is executed after the constructor completes, but before the object is first accessed.
    Sunday, January 1, 2017 5:21 AM
  • "One must disable the managed debugging assistant"

    When I do that, the program hangs on load or shortly after.

    Well I think you have to do that or it will not work period. Then if you get another error I suspect that is something else.

    What OS is it? What version direct x?

    Here is a working example. In VS 2016 this give loader lock error in a new project. Then disable the loader lock as I showed and it runs.

    That is all I know about it. Other than there are issues with win 10 however it should work there too. And maybe vs 2010 will be slightly different.

    How did directx get on your system and what version is it the software wants?

    Also compile for x86 as you mentioned for direct 9c..

    'spinning cube directx 9c example
    Option Strict On
    Imports Microsoft.DirectX               'C:\Windows\assembly\GAC\Microsoft.DirectX\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.dll
    Imports Microsoft.DirectX.Direct3D      'C:\Windows\assembly\GAC\Microsoft.DirectX.Direct3D\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.Direct3D.dll
    
    Public Class Form1
        Private device As Device = Nothing
        Private vb As VertexBuffer = Nothing
        Private tex1 As Texture = Nothing
        Private angle As Single = 0.0F
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True)
            Me.ClientSize = New Size(400, 400)
    
            InitializeGraphics()
        End Sub
    
        Public Sub InitializeGraphics()
            'create the directx graphics device
            Dim presentParams As New PresentParameters()
            presentParams.Windowed = True
            presentParams.SwapEffect = SwapEffect.Discard
    
            device = New Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, presentParams)
    
            'create the object data
            vb = New VertexBuffer(GetType(CustomVertex.PositionTextured), 36, device, Usage.Dynamic Or Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default)
            AddHandler vb.Created, AddressOf Me.OnVertexBufferCreate
            OnVertexBufferCreate(vb, Nothing)
    
            'read the texture image - add the path to your own image
            tex1 = New Texture(device, New Bitmap("c:\bitmaps\rusty.bmp"), Usage.Dynamic, Pool.Default)
        End Sub
    
        Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
            device.Clear(ClearFlags.Target, Color.CornflowerBlue, 1.0F, 0)
    
            'Setup Camera
            device.Transform.Projection = Matrix.PerspectiveFovLH(Math.PI / 4, CSng(Me.Width / Me.Height), 1.0F, 100.0F)
            device.Transform.View = Matrix.LookAtLH(New Vector3(0, 0, 8.0F), New Vector3(), New Vector3(0, 1, 0))
            device.RenderState.Lighting = False
    
            'begin drawing
            device.BeginScene()
            device.VertexFormat = CustomVertex.PositionTextured.Format
            device.SetStreamSource(0, vb, 0)
    
            'draw the rotating cube
            angle += 0.01F
            Dim yaw As Single = CSng(angle / Math.PI)
            Dim pitch As Single = CSng(2 * angle / Math.PI)
            Dim roll As Single = CSng(4 * angle / Math.PI)
            Dim x, y, z As Single
    
            'set the local rotation and location
            device.Transform.World = Matrix.Multiply(Matrix.RotationYawPitchRoll(yaw, pitch, roll), Matrix.Translation(x, y, 3))
            'assign the image to the triangles
            device.SetTexture(0, tex1)
            'add the triangles that make the cube
            device.DrawPrimitives(PrimitiveType.TriangleList, 0, 12)
    
            device.EndScene()
            device.Present()
    
            'create infinate loop
            Me.Invalidate()
        End Sub
    
        Private Sub OnVertexBufferCreate(sender As Object, e As EventArgs)
            Dim buffer As VertexBuffer = CType(sender, VertexBuffer)
            Dim verts(35) As CustomVertex.PositionTextured
    
            ' Front face
            verts(0) = New CustomVertex.PositionTextured(-1.0F, 1.0F, 1.0F, 0.0F, 0.0F)
            verts(1) = New CustomVertex.PositionTextured(-1.0F, -1.0F, 1.0F, 0.0F, 1.0F)
            verts(2) = New CustomVertex.PositionTextured(1.0F, 1.0F, 1.0F, 1.0F, 0.0F)
            verts(3) = New CustomVertex.PositionTextured(-1.0F, -1.0F, 1.0F, 0.0F, 1.0F)
            verts(4) = New CustomVertex.PositionTextured(1.0F, -1.0F, 1.0F, 1.0F, 1.0F)
            verts(5) = New CustomVertex.PositionTextured(1.0F, 1.0F, 1.0F, 1.0F, 0.0F)
    
            ' Back face (remember this is facing *away* from the camera, so vertices should be clockwise order)
            verts(6) = New CustomVertex.PositionTextured(-1.0F, 1.0F, -1.0F, 0.0F, 0.0F)
            verts(7) = New CustomVertex.PositionTextured(1.0F, 1.0F, -1.0F, 1.0F, 0.0F)
            verts(8) = New CustomVertex.PositionTextured(-1.0F, -1.0F, -1.0F, 0.0F, 1.0F)
            verts(9) = New CustomVertex.PositionTextured(-1.0F, -1.0F, -1.0F, 0.0F, 1.0F)
            verts(10) = New CustomVertex.PositionTextured(1.0F, 1.0F, -1.0F, 1.0F, 0.0F)
            verts(11) = New CustomVertex.PositionTextured(1.0F, -1.0F, -1.0F, 1.0F, 1.0F)
    
            ' Top face
            verts(12) = New CustomVertex.PositionTextured(-1.0F, 1.0F, 1.0F, 0.0F, 0.0F)
            verts(13) = New CustomVertex.PositionTextured(1.0F, 1.0F, -1.0F, 1.0F, 1.0F)
            verts(14) = New CustomVertex.PositionTextured(-1.0F, 1.0F, -1.0F, 0.0F, 1.0F)
            verts(15) = New CustomVertex.PositionTextured(-1.0F, 1.0F, 1.0F, 0.0F, 0.0F)
            verts(16) = New CustomVertex.PositionTextured(1.0F, 1.0F, 1.0F, 1.0F, 0.0F)
            verts(17) = New CustomVertex.PositionTextured(1.0F, 1.0F, -1.0F, 1.0F, 1.0F)
    
            ' Bottom face (remember this is facing *away* from the camera, so vertices should be clockwise order)
            verts(18) = New CustomVertex.PositionTextured(-1.0F, -1.0F, 1.0F, 0.0F, 0.0F)
            verts(19) = New CustomVertex.PositionTextured(-1.0F, -1.0F, -1.0F, 0.0F, 1.0F)
            verts(20) = New CustomVertex.PositionTextured(1.0F, -1.0F, -1.0F, 1.0F, 1.0F)
            verts(21) = New CustomVertex.PositionTextured(-1.0F, -1.0F, 1.0F, 0.0F, 0.0F)
            verts(22) = New CustomVertex.PositionTextured(1.0F, -1.0F, -1.0F, 1.0F, 1.0F)
            verts(23) = New CustomVertex.PositionTextured(1.0F, -1.0F, 1.0F, 1.0F, 0.0F)
    
            ' Left face
            verts(24) = New CustomVertex.PositionTextured(-1.0F, 1.0F, 1.0F, 0.0F, 0.0F)
            verts(25) = New CustomVertex.PositionTextured(-1.0F, -1.0F, -1.0F, 1.0F, 1.0F)
            verts(26) = New CustomVertex.PositionTextured(-1.0F, -1.0F, 1.0F, 1.0F, 0.0F)
            verts(27) = New CustomVertex.PositionTextured(-1.0F, 1.0F, -1.0F, 0.0F, 1.0F)
            verts(28) = New CustomVertex.PositionTextured(-1.0F, -1.0F, -1.0F, 1.0F, 1.0F)
            verts(29) = New CustomVertex.PositionTextured(-1.0F, 1.0F, 1.0F, 0.0F, 0.0F)
    
            ' Right face (remember this is facing *away* from the camera, so vertices should be clockwise order)
            verts(30) = New CustomVertex.PositionTextured(1.0F, 1.0F, 1.0F, 0.0F, 0.0F)
            verts(31) = New CustomVertex.PositionTextured(1.0F, -1.0F, 1.0F, 1.0F, 0.0F)
            verts(32) = New CustomVertex.PositionTextured(1.0F, -1.0F, -1.0F, 1.0F, 1.0F)
            verts(33) = New CustomVertex.PositionTextured(1.0F, 1.0F, -1.0F, 0.0F, 1.0F)
            verts(34) = New CustomVertex.PositionTextured(1.0F, 1.0F, 1.0F, 0.0F, 0.0F)
            verts(35) = New CustomVertex.PositionTextured(1.0F, -1.0F, -1.0F, 1.0F, 1.0F)
    
            buffer.SetData(verts, 0, LockFlags.None)
        End Sub
    End Class
    

    Sunday, January 1, 2017 12:52 PM
  • PS there can be issues with your video setup too. Should be set to use hardware processing etc. Try to run this cube example in a new project and then we can all be using the same thing.

    Must be .net 2 or 3.5 also. Use 3.5.


    PS so the example requires directx 9c, x86, .net 3.5. Disable loader lock dba.
    Sunday, January 1, 2017 1:02 PM
  • Well I think you have to do that or it will not work period. Then if you get another error I suspect that is something else.

    As always, seriously impressive!


    "One who has no vices also has no virtues..."

    Sunday, January 1, 2017 1:23 PM
  • Tommy -
    I am using VS2010, 32 bit windows 10. Copied your example, changed bitmap of course.
    Importing the exact paths from example:
    C:\Windows\assembly\GAC\Microsoft.DirectX\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.dll
    C:\Windows\assembly\GAC\Microsoft.DirectX.Direct3D\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.Direct3D.dll
    Many errors
    'ClearFlags' is not declared.
    'CustomVertex' is not declared.
    'LockFlags' is not declared.
    'PrimitiveType' is not declared.
    'SwapEffect' is not declared.
    'CustomVertex.PositionTextured' is not defined. 36 times
    'Device' is not defined. 2 Times
    'PresentParameters' is not defined.
    'Texture' is not defined. 2 times
    'VertexBuffer' is not defined. 3 times

    Using the paths from the Pacman code, LoaderLock never gets thrown, works just fine with exception "allowed" or not
    C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\Microsoft.DirectX.dll
    C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\Microsoft.DirectX.Direct3D.dll

    I don't know if it matters, but the Pacman code is using DirectX only for audio.

    Sunday, January 1, 2017 4:24 PM
  • Tommy -
    I am using VS2010, 32 bit windows 10. Copied your example, changed bitmap of course.
    Importing the exact paths from example:
    C:\Windows\assembly\GAC\Microsoft.DirectX\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.dll
    C:\Windows\assembly\GAC\Microsoft.DirectX.Direct3D\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.Direct3D.dll
    Many errors
    'ClearFlags' is not declared.
    'CustomVertex' is not declared.
    'LockFlags' is not declared.
    'PrimitiveType' is not declared.
    'SwapEffect' is not declared.
    'CustomVertex.PositionTextured' is not defined. 36 times
    'Device' is not defined. 2 Times
    'PresentParameters' is not defined.
    'Texture' is not defined. 2 times
    'VertexBuffer' is not defined. 3 times

    Using the paths from the Pacman code, LoaderLock never gets thrown, works just fine with exception "allowed" or not
    C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\Microsoft.DirectX.dll
    C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\Microsoft.DirectX.Direct3D.dll

    I don't know if it matters, but the Pacman code is using DirectX only for audio.

    Well the paths change on each OS. That's for win 7. Not sure where it is in win 10.

    But I think your problem is windows 10. It does not run real dx9c it runs dx 11. Do a search you will see. My software works on win 10 as I showed. That is all I know.

    "I don't know if it matters, but the Pacman code is using DirectX only for audio."

    What version of DirectX?


    PS see if those dlls are on your system. if not you have to install directx 9c.
    Sunday, January 1, 2017 4:34 PM

  • Using the paths from the Pacman code, LoaderLock never gets thrown, works just fine with exception "allowed" or not
    C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\Microsoft.DirectX.dll
    C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\Microsoft.DirectX.Direct3D.dll

    What are you saying, pacman works or my cube example works with those paths?

    Sunday, January 1, 2017 4:45 PM
  •  Have you tried what Acamar suggested,  move the code out of the constructor to somewhere that it can be executed after the class has been created but,  before the audio device is accessed?  Maybe using something like If Device = Nothing Then create the new device so it is only created once?

     Without understanding how everything works and is set up in this class,  it is hard to say where it would be appropriate to try moving the code that instantiates the "Device" to,  if there is one.  Do you have a link to the code you downloaded before converting it?


    If you say it can`t be done then i`ll try it

    Sunday, January 1, 2017 5:20 PM
  • I was not sure how to do that, will try in a bit.

    Original PSC Source:

    Edit - on my system, the original code throws the same exception, and freezes if I disable the LoaderLock under Debugging.

    Sunday, January 1, 2017 6:13 PM
  •  Devon,

     I downloaded that project and tried opening it in VS just to check it out before trying to do anything.  I see that it is built targeting .Net Framework 2.0.

     So,  i then converted just the GameSound class to VB.Net and added it to a new form project that targeted .Net Framework 2.0 and x86 platform.  I then copied the .wav sound files out of the Chomp project folder and added them to the applications resources in my new project.  I also added a reference to (C:\WINDOWS\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\Microsoft.DirectX.DirectSound.dll) which is what they had referenced in the Chomp project.

     When i tried to play one of the sound files with the GameSound class,  it threw the LoaderLock exception as expected.  I tried re-arranging the code to do as Acamar and i where suggesting but,  no mater what i did it kept throwing the same exception.  I then did as Tom mentioned and turned off the LoaderLock exception and it worked fine after that.

     So,  i would try targeting .Net Framework 2.0 and the x86 platform.  Turn off the LoaderLock and then see what happens.  If there are more exceptions after that,  then as Tom said,  it is probably a separate issue that needs to be dealt with.

     Here is the code i used to test it with.  Perhaps try this in a new project set up as i said above.  See if it works.  If it does,  then there is other problems.

    Imports System.IO
    Imports Microsoft.DirectX.DirectSound
    
    Public Class Form1
        Private gs As GameSound
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            gs = New GameSound(Me)
            gs.PlaySound(My.Resources.Intro, False)
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            gs.PlaySound(My.Resources.PacmanEaten, False)
        End Sub
    End Class
    
    
    Public Class GameSound
        Private _buffer3D As Buffer3D
        Private _soundDevice As Device
        Private _bufferDesc As BufferDescription
        Private _soundBuffer As SecondaryBuffer
    
        Public Sub New(Owner As System.Windows.Forms.Control)
            _bufferDesc = New BufferDescription
            _bufferDesc.GlobalFocus = True
            _bufferDesc.Control3D = True
            _soundDevice = New Device
            _soundDevice.SetCooperativeLevel(Owner, CooperativeLevel.Normal)
        End Sub
    
        Public Sub PlaySound(EmbeddedSoundStream As Stream, [Loop] As Boolean)
            Try
                _soundBuffer = New SecondaryBuffer(EmbeddedSoundStream, _bufferDesc, _soundDevice)
                _buffer3D = New Buffer3D(_soundBuffer)
                If [Loop] Then
                    _soundBuffer.Play(0, BufferPlayFlags.Looping)
                Else
    
                    _soundBuffer.Play(0, BufferPlayFlags.[Default])
                End If
            Catch expPlay As Exception
                Debug.WriteLine(expPlay.Message)
            End Try
        End Sub
    
        Public Sub PlaySound(FullResourceName As String, [Loop] As Boolean)
            Try
                Dim strmTemp As Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(FullResourceName)
                _soundBuffer = New SecondaryBuffer(strmTemp, _bufferDesc, _soundDevice)
                _buffer3D = New Buffer3D(_soundBuffer)
                If [Loop] Then
                    _soundBuffer.Play(0, BufferPlayFlags.Looping)
                Else
    
                    _soundBuffer.Play(0, BufferPlayFlags.[Default])
                End If
            Catch expPlay As Exception
                Console.WriteLine(expPlay.Message)
            End Try
        End Sub
    
        Public Sub StopSound()
            If _soundBuffer IsNot Nothing Then
                _soundBuffer.[Stop]()
            End If
        End Sub
    
        Public Shared Function GetEmbeddedSoundStream(FullResourceName As String) As Stream
            Try
                Dim strmTemp As Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(FullResourceName)
                Return strmTemp
            Catch ex As Exception
                Throw New Exception("Could not retrieve embedded resource. " + ex.Message)
            End Try
        End Function
    End Class
    


    If you say it can`t be done then i`ll try it

    Sunday, January 1, 2017 8:27 PM
  • Razerz,

    Oh that's interesting. Well the article never did say what directx but I guess the file ref says it. I suspect you can use 3.5 too as I had no problem switching.

    Devon could you get my example to work or not?

    Razerz is on Win 7, right? Devon is Win 10. I have read that win 10 just emulates directx 9c with dx 11. Also some gamers claim to give the win 10 the right ref and then it works but I could not verify that on my system. My app runs on win 10 but the dx 3d view it is 10x slower than win 7.

    So I would not be surprised but it is simply a win 10 thing.

    Going from 10 or 15 years I recall that the loaderlock thing has nothing to do with loaderlock. Its the managed debug assistant checking for loaderlock throws the err. The reason is... it is 64 bit? Or something like that. And also something to do with one thing is managed and another is not. Now I ran for a long time and then one day I had to turn that loaderlock checker off before it would go. Was it moving from vb6 to .net? Or moving to vs 2010? I dont recall.

    PS When I say my app I mean a full app installed via msi installer where I have set dx 9c as required and it either goes off to the vendors site or it installs it from disc. As far as I know that part never happens on any win from 7 up. Dx 9 is suppose to be supported there and included. On xp the dx installer actually comes up and runs with my app setup but not in the rest.

    Sunday, January 1, 2017 9:05 PM
  • Razerz,

    Oh that's interesting. Well the article never did say what directx but I guess the file ref says it. I suspect you can use 3.5 too as I had no problem switching.

    Devon could you get my example to work or not?

    Razerz is on Win 7, right? Devon is Win 10. I have read that win 10 just emulates directx 9c with dx 11. Also some gamers claim to give the win 10 the right ref and then it works but I could not verify that on my system. My app runs on win 10 but the dx 3d view it is 10x slower than win 7.

    So I would not be surprised but it is simply a win 10 thing.

    Going from 10 or 15 years I recall that the loaderlock thing has nothing to do with loaderlock. Its the managed debug assistant checking for loaderlock throws the err. The reason is... it is 64 bit? Or something like that. And also something to do with one thing is managed and another is not. Now I ran for a long time and then one day I had to turn that loaderlock checker off before it would go. Was it moving from vb6 to .net? Or moving to vs 2010? I dont recall.

    Tommy, your example worked fine when I import using the paths to the DirectX dlls from the original C# project. 32 bit Win 10

    Will not compile using the paths from your example:
    C:\Windows\assembly\GAC\Microsoft.DirectX\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.dll
    C:\Windows\assembly\GAC\Microsoft.DirectX.Direct3D\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.Direct3D.dll

    Using the paths from the Pacman code, LoaderLock never gets thrown, works just fine with exception "allowed" or not
    C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\Microsoft.DirectX.dll
    C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\Microsoft.DirectX.Direct3D.dll

    Odd since the files are identical (MD5 Hash is the same)

    Sunday, January 1, 2017 9:26 PM
  • Razerz,
    Using the paths from the Pacman code, LoaderLock never gets thrown, works just fine with exception "allowed" or not
    C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\Microsoft.DirectX.dll
    C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0\Microsoft.DirectX.Direct3D.dll

    Odd since the files are identical (MD5 Hash is the same)

    Hmm. Well the paths are a distraction. I am not sure where that comment came from. It may have been in the original example from the dx sdk I copied from somewhere and modified. Its old.

    Well I just checked, my cube runs on win10 without the loader lock disabled in vs 2010. To run in vs 2015 I have to uncheck the loader lock checking. I bet vs 2010 is 32 bit and 2015 is 64. I started with it when I went to 2013 maybe. But its a distraction.

    So now you need to run Razerz example on your win 10 Devon. I was doing it until I saw all sound file refs.

    PS However the paths may somehow be the clue to the real directx 9c???? But try Razerz now.

    Finally, some gamers said installing the directx with the full sdk solved the problem  for them. However as I say it runs on my win 10 system without the dx sdk installed. Then I installed the dx sdk to see if it would speed up my app but no change.

    One more thing just to note the paths in the comment in my example are what I am using for ref to the dlls in project references on both win systems and all the VSes. I am running the same project all cases all work (other than the loader lock in 2015)..



    Hmm. That could be the path to the directx sdk version of the files??? Now that I think about it my win10 was an upgrade so the sdk could have been there all along. But my hunch is the problem is something else.
    Sunday, January 1, 2017 9:38 PM
  • IR's sample works just fine as long as I disable the exception for LoaderLock

    Sunday, January 1, 2017 10:38 PM
  • IR's sample works just fine as long as I disable the exception for LoaderLock


    LOL.
    Sunday, January 1, 2017 10:53 PM
  •  I have converted all the classes and added them to a new form project that i set up exactly as i said in my last post.  I did have to do quite a bit of work in the Form class to move things over to the Form Designer.  I also had to modify the code in the PlayBoardSound sub in the GameBoard class so it would play the sounds from my apps resources.  I also had to fix several type conversion errors that Option Strict would not allow.

     However,  i did get it working and have not had it crash or freeze up yet.  It does not look as smooth in my gif because of the delay between screen captures.....

     

     I can upload it to my OneDrive if you would like.  I see there is a text file saying that the author may have retained certain copyrights and to see that link but,  i see nothing about any copyrights at that link.  So,  i don`t think there would be a problem if i upload it.  I can add that text file in the project i guess.  However,  i did it in VS2015 so,  you would still need to basically rebuild the project in VS2010 if you don`t have VS2015.  That should not be to hard though.


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Monday, January 2, 2017 12:14 AM
    Monday, January 2, 2017 12:13 AM
  • PS - There are still a lot of things that need to be cleaned up in it though.  I know i saw a spot or two that there was new Brushes,  Graphics,  and other things that they created but did not dispose.  I might clean them up eventually but,  i just wanted to get it working first.  8)

    If you say it can`t be done then i`ll try it

    Monday, January 2, 2017 12:20 AM
  • I can upload it to my OneDrive if you would like.  I see there is a text file saying that the author may have retained certain copyrights and to see that link but,  i see nothing about any copyrights at that link.

    PS - There are still a lot of things that need to be cleaned up in it though.  I know i saw a spot or two that there was new Brushes,  Graphics,  and other things that they created but did not dispose.  I might clean them up eventually but,  i just wanted to get it working first.  8)


    If you say it can`t be done then i`ll try it

    Sounds good, I have VS2010 as well as VS2015 Community. I'll be curious as to any audio problems, I redid the sound also to use resources and it runs, but seems to have some audio problems when <I think> Invincibility Mode is activated, also the siren sound does not always stop when a level is completed. 
    Monday, January 2, 2017 12:41 AM
  •  Here is the link to my OneDrive where you can find the zip file called "Pacman converted from CSharp".  It contains the whole project folder including the text file i mentioned above.

     My OneDrive Link

     I also noticed a problem with the siren but,  i think i got that fixed (i think).  I also fixed one of the spots that needed some stuff disposed.  There are probably more though.  I left a few comments in those spots that i modified.  There was more that i did not comment though.

     I also see there was a tmrDie Timer that was not being used that i deleted from the project and i also see there is a blank sub called AnimateDie or something like that in one of the classes.  I am guessing that the author did not finish writing the full code or finish fixing all the bugs in it.


    If you say it can`t be done then i`ll try it

    • Marked as answer by Devon_Nullman Monday, January 2, 2017 5:19 PM
    Monday, January 2, 2017 1:30 AM
  •  Here is the link to my OneDrive where you can find the zip file called "Pacman converted from CSharp".  It contains the whole project folder including the text file i mentioned above.

     My OneDrive Link

     I also noticed a problem with the siren but,  i think i got that fixed (i think).  I also fixed one of the spots that needed some stuff disposed.  There are probably more though.  I left a few comments in those spots that i modified.  There was more that i did not comment though.

     I also see there was a tmrDie Timer that was not being used that i deleted from the project and i also see there is a blank sub called AnimateDie or something like that in one of the classes.  I am guessing that the author did not finish writing the full code or finish fixing all the bugs in it.


    If you say it can`t be done then i`ll try it


    Looks great Razerz. Good job. Love the fancy graphics. :)
    Monday, January 2, 2017 3:28 AM
  •  Here is the link to my OneDrive where you can find the zip file called "Pacman converted from CSharp".  It contains the whole project folder including the text file i mentioned above.

     My OneDrive Link

     I also noticed a problem with the siren but,  i think i got that fixed (i think).  I also fixed one of the spots that needed some stuff disposed.  There are probably more though.  I left a few comments in those spots that i modified.  There was more that i did not comment though.

     I also see there was a tmrDie Timer that was not being used that i deleted from the project and i also see there is a blank sub called AnimateDie or something like that in one of the classes.  I am guessing that the author did not finish writing the full code or finish fixing all the bugs in it.


    If you say it can`t be done then i`ll try it


    Looks great Razerz. Good job. Love the fancy graphics. :)

    I added a pause key and fixed the disposal of as many as I could find. Only thing left is to try to understand just what loaderlock is.

    Monday, January 2, 2017 5:19 PM
  • Looks great Razerz. Good job. Love the fancy graphics. :)

    I added a pause key and fixed the disposal of as many as I could find. Only thing left is to try to understand just what loaderlock is.

    Perhaps a new/updated version of the DirectX libraries would cause the LoaderLock issue to disappear. And with them or it perhaps build the app to greater than .Net 3.0 to see if the issue resolves.

    Also see Initialization of Mixed Assemblies.


    La vida loca

    Monday, January 2, 2017 5:50 PM
  •  I was just going through the classes and cleaning up a bunch of stuff myself.  I have removed quite a bit of BS such as all the pretty much useless Exit Select statements,  plus the 2 unused subs in the GameSound class,  and a few other odds-n-ends.

     I am looking it over and i see none of the classes implement IDisposable.  Some of them really need to have stuff disposed when the game is closed,  like the unmanaged DirectSound Device and its Buffers,  plus all the new Bitmaps that are created in the Packman class and Monster class.

     I would have gone about the whole design a little different.  I don`t like the use of all the Thread.Sleep calls on the same thread as the Forms,  and i definitely don`t like using Application.DoEvents.  All in all though,  it is kind of fun to play,  it has been many years since i played Pac-Man.  8)


    If you say it can`t be done then i`ll try it

    Monday, January 2, 2017 6:03 PM
  • PS - I forgot,  here are two SO links that have some short answers of what LoaderLock is.  8)

    what is a loader lock?

    How OS Loaderlock works

     

     EDIT:  Monkeyboy`s links have more info than these two though,  don`t know how i did not find those.


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Monday, January 2, 2017 6:12 PM
    Monday, January 2, 2017 6:09 PM
  • I added a pause key and fixed the disposal of as many as I could find. Only thing left is to try to understand just what loaderlock is.

    I think I explained what is happening although I may not have all the details correct.

    There is no loader lock.

    The mdba is using 64 bit and the directx dll is 32 bit (or whatever the problem is). So when the mdba to detect loaderlock runs it causes an error. It is not loader lock it is calling a 32 bit dll from a 64 bit. The mdba is the error.

    If there was loader lock going on and you disable the error message it was detected then what do you think will happen? Nothing. I think the app would lock. But it does not it runs fine. There is no loader lock. There is mixing of 64 and 32 bit inside Visual Studio. So when you turn that off the problem goes away.

    This was exaplained to me on this forum when I first hit the problem and was given the solution I gave in my first post. I dont recall it may have been Mick D that explained it to me then. Whomever it was I think they knew.

    It is not loader lock or the code would not run it would lock up. As I explained I used direct x 9c for yerars and then one day I had to start diabling the mdba for loader lock or it would not run. Disable it now it runs again. It think it was when first moving to 2013?


    PS Maybe direct x is using loader lock. But the error in not from crossing loader locks in separate threads. The problem is something the mdba does to detect it. Mixing managed 32 bit and unmanged 64 bit maybe.

    Just turn off the mdba and all is well. That is the answer to the question.


    Monday, January 2, 2017 7:52 PM
  • LoaderLock was detected
    Message: DLL 'C:\WINDOWS\assembly\GAC\Microsoft.DirectX\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

    PS Read the error carefully. It says loader lock detected. And something about mixing managed and unmanaged. But the real problem is using the debug assistant in this case.

    Is not vb managed code? Is there a lock loader statement in vb? Are we using two threads with locking? I think the answer is no. So we don't need to check for it. Its something for debugging code that can use it and has no purpose for normal vb which our code is.

    Also Look at the path in the original error message btw. Its the path to the dll I showed in my code example.

    That's my misunderstanding of it for what its worth. :)

    JPS

    In my example, this is the line of vb code where the loader locking is detected, in the directx.dll:

    Private device As Device = Nothing
    
    
           device = New Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, presentParams)
    

    The device is the directx drawing surface. But since we are the only ones using the device we have no loader lock problem.

    Monday, January 2, 2017 9:10 PM
  • Is not vb managed code?

    Yes, but not everything that's under the purview of dotNET is pure dotNET.

    An example that you're familiar with would be a bitmap.

    The whole reason that it's got a .Dispose method (implements IDisposable) is because the GC doesn't know how to handle finalization of the object.


    "One who has no vices also has no virtues..."


    Monday, January 2, 2017 9:18 PM
  • This is a link https://1drv.ms/u/s!Ag0nb6dfIqu4gh-MOVQVfNXvoBqP to a PacmanVB zip file on my onedrive.

    I didn't copy Razerz project. Yesterday I downloaded and compiled the C# project and used Telerik JustDecompile to decompile the executable to a new project. Two of the classes errored (only some subs in each) in the conversion but I used Teleriks online converter to convert those two classes then copied the subs out of those pasting them over the subs that were errored in the two classes.

    Anyhow it worked after that. Then I set Option Strict On in everything and went through correcting type conversions. And removed the Timer Razerz previously mentioned.

    Then I added all the .Wav files as resources and when the app loads it writes them all to the apps startup path. The methods for writing them seem kind of strange to me but the app was compiled to .Net 3.0 at the time however in .Net 4.0 app I have the code for writing the files to disk from resources for audio files seemed different method was used but it wouldn't work in .Net 3.0 code although I didn't pay too much attention to it.

    I then went through the GameSound class and basically commented out all the code leaving all the subs empty. And in the GameBoard class, after ref'ing C:\Windows\System32\WMP.Dll, I added imports statement for WMPLib. Instantiated 8 Windows Media Players and altered all the code that called GameSound so instead Windows Media Players play the sounds, two in looping mode. And in the sound stop sub, since all WMP's are in a List(Of WMP), loop through the list to stop them all.

    I believe some of the sounds may be delayed sometimes such as when Pacman eats one of the bad ones after eating a power pellet (or whatever they are called) or something. Or maybe other code is at issue cause sometimes when Pacman eats one the sound plays instantly. Perhaps the WMP playing that sound, when called to play it again, isn't done yet or something.

    I don't see a sound for when a bad guy hits Pacman though or notice where or what tells a sound to play when that occurs but I didn't look real close.

    After all that worked I compiled the app to .Net 4.0 and it works with no issue I noticed although I only ran it for a minute or so cause without a Joystick it's too difficult to turn corners and stuff.

    It may be that more WMP's need to be instantiated so multiples can play the same sound if necessary. There are methods to determine the state of a WMP I suppose or perhaps they should be stopped prior to providing them a URL in case they are not ready.

    Next up Joystick I suppose.

    Also didn't Pacman have little pellets it ate while moving around between power pellets? I forgot to check the C# version to see if it had them. Perhaps the C# to VB.Net conversion I did lost something.


    La vida loca

    Monday, January 2, 2017 9:33 PM
  • Is not vb managed code?

    Yes, but not everything that's under the purview of dotNET is pure dotNET.

    An example that you're familiar with would be a bitmap.

    The whole reason that it's got a .Dispose method (implements IDisposable) is because the GC doesn't know how to handle finalization of the object.


    "One who has no vices also has no virtues..."


    Well, who knows what the multiple sounds in Pac Man may be doing. Not me. I am just pointing out turning off checking for this error makes it work. That's what Razerz said in his first example.

    I was trying to find where I asked this question in my old threads but. I saw you in there. Joel engr, Penny, but it was when it was mixed with another unrelated problem. When I first joined the forum. But I cant find the thread where someone told me the answer and exaplained why. It could have been Reed.


    PS I keep saying error but its not really an error being detected it is use of loader lock. We don't need to check it. Even if we did there is some reason why the managed debug assistant does not work in this case.
    Monday, January 2, 2017 9:46 PM
  • ... It is not loader lock it is calling a 32 bit dll from a 64 bit. ....

     Maybe in some situations,  i don`t know,  but i don`t see that being the cause in this situation.  I have a 32bit system,  there is nothing being accessed that is 64bit on a 32bit system.  Perhaps that is not what you are trying to say though.

     I think the 2 links that Monkeyboy posted in his last post has helped me to partially understand what is going on.  It will take a few more times of reading through them and a little more looking things up,  and it might help me understand it more.  Then again,  it might just confuse me a little more too.  8)


    If you say it can`t be done then i`ll try it

    Monday, January 2, 2017 10:48 PM
  • Perhaps that is not what you are trying to say though.

    I am trying to say there is a reason but I dont know what it is exactly. I guess it is more manged vs unmanaged and what works in vb. My last summary is best of what I mean at the moment:

     I keep saying error but its not really an error being detected it is use of loader lock. We don't need to check it. Even if we did there is some reason why the managed debug assistant does not work in this case.

    The direct x is unmanaged code?? It is being used in vb managed code via ??. The direct x may be using loader lock. It is written in c++ or something that has it the ability to use it. We cant deal with it in vb. No reason to check for it. When we do we just get the message and have to stop. What we do using microsofts direct x does not need loader lock checking so turn that off.

    PS

    If vb gave us the ablity to use loader lock, then we would check to see if something else is has already locked the whatever and wait or whatever. But we dont have that in vb.

    Anyway, direct x 9c is made by microsoft to run in windows from vb this way whatever it is. We just need to turn off the dba in the visual studio that has it for whatever reason.

    Monday, January 2, 2017 11:05 PM
  • It may be that more WMP's need to be instantiated so multiples can play the same sound if necessary. There are methods to determine the state of a WMP I suppose or perhaps they should be stopped prior to providing them a URL in case they are not ready.

    Next up Joystick I suppose.

    Also didn't Pacman have little pellets it ate while moving around between power pellets? I forgot to check the C# version to see if it had them. Perhaps the C# to VB.Net conversion I did lost something.


    La vida loca

     LOL!!  I was thinking about adding use of a Joystick myself.  It would not be hard to throw in a Joystick class like i posted in THIS THREAD or maybe even strip it down a bit since you really only need the X and Y axes.

     I was also thinking that using the mciSendString function would work pretty good in place of DirectX for this.  I posted a short stripped down example from my larger GameSounds class that could be easily used in this at THIS LINK.  It would need the Stop and maybe Pause/Resume added back into it though.  That would get rid of all the LoaderLock BS.  8)

     Yes,  there is suppose to be pellets as seen in my animated gif a few posts back.  8)


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Monday, January 2, 2017 11:32 PM
    Monday, January 2, 2017 11:16 PM
  • It may be that more WMP's need to be instantiated so multiples can play the same sound if necessary. There are methods to determine the state of a WMP I suppose or perhaps they should be stopped prior to providing them a URL in case they are not ready.

    Next up Joystick I suppose.

    Also didn't Pacman have little pellets it ate while moving around between power pellets? I forgot to check the C# version to see if it had them. Perhaps the C# to VB.Net conversion I did lost something.


    La vida loca

     LOL!!  I was thinking about adding use of a Joystick myself.  It would not be hard to throw in a Joystick class like i posted in THIS THREAD or maybe even strip it down a bit since you really only need the X and Y axes.

     I was also thinking that using the mciSendString function would work pretty good in place of DirectX for this.  I posted a short stripped down example from my larger GameSounds class that could be easily used in this at THIS LINK.  It would need the Stop and maybe Pause/Resume added back into it though.  That would get rid of all the LoaderLock BS.  8)

     Yes,  there is suppose to be pellets as seen in my animated gif a few posts back.  8)


    If you say it can`t be done then i`ll try it

    Yeah. I added a class and used highres timer in BackgroundWorker getting joysticks hat positions (0, 90, 180 and 270) and used the hat. And if the hat position differs from previous hat position raise an event. And in the frmScreen class set the attempted direction.

    I'll probably alter it back to using the JoySticks stick x, y position but that was more difficult before probably because I was raising the event too much and now it is only raised if a difference in previous position occurs for the hat which I can do with the stick also after determining what the sticks actual differences between x and y are.

    I think with the audio I need to add some more WMP's so if any are busy when a tune needs to be played multiple times at the same time that can occur such as when Pacman eats a couple bad guys in a row.

            Private Sub JoyStick1_Update() Handles JoyStick1.JoyStickUpdate
                If JoyStick1.Running = True Then
                    If JoyStick1.Move = "Left" Then
                        Me._board.PacMan.AttemptedDirection = CharacterDirection.Left
                    ElseIf JoyStick1.Move = "Right" Then
                        Me._board.PacMan.AttemptedDirection = CharacterDirection.Right
                    ElseIf JoyStick1.Move = "Up" Then
                        Me._board.PacMan.AttemptedDirection = CharacterDirection.Up
                    ElseIf JoyStick1.Move = "Down" Then
                        Me._board.PacMan.AttemptedDirection = CharacterDirection.Down
                    End If
                End If
            End Sub


    La vida loca

    Tuesday, January 3, 2017 12:43 AM
  •  John,

     Instead of using a timer that continuously polls the joystick,  you can use the joySetCapture function to capture the joystick and have it send Joystick Messages to the WndProc of the frmScreen form only when an axis or button changes.   However,  you might need to use the joySetThreshold function to set the threshold so it does not send messages on every polling interval as mentioned in the fChanged parameter of the joySetCapture documents.  I am not sure what the Threshold is set to by default so,  i am not sure if it is needed or not without testing.

     However,  the HAT also known as the DPAD (Direction Pad with 4 buttons) would be just as good or maybe better than using the X and Y axes. 


    If you say it can`t be done then i`ll try it

    Tuesday, January 3, 2017 1:26 AM