SFML community forums

Bindings - other languages => DotNet => Topic started by: Kwang1imsa on July 15, 2011, 01:45:58 am

Title: LoaderLock
Post by: Kwang1imsa on July 15, 2011, 01:45:58 am
Code: [Select]
private Sprite drawSpr = new Sprite();

In this line I am experiencing this error:

Quote
LoaderLock was detected:
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.
[/quote]
Title: LoaderLock
Post by: Laurent on July 15, 2011, 08:59:55 am
The message says it all, don't try to call a SFML function to initialize a class member, since it will be called at global initialization.
Title: LoaderLock
Post by: Kwang1imsa on July 16, 2011, 06:54:38 am
Thank you for the response.

How can I get around it? I am not familiar with MDAs.  How can I store a sprite without throwing it into a variable?
Title: LoaderLock
Post by: Laurent on July 16, 2011, 09:43:45 am
Can't you initialize it in the constructor?
Title: LoaderLock
Post by: Kwang1imsa on July 16, 2011, 06:55:50 pm
That's exactly what I do:

Code: [Select]
private Sprite drawSpr;

In the constructor:

Code: [Select]
drawSpr = new Sprite();

This is very odd. Am I doing something wrong?
Title: LoaderLock
Post by: Laurent on July 17, 2011, 10:48:23 am
Quote
That's exactly what I do

That's not what you showed in your first post... ;)

Quote
This is very odd. Am I doing something wrong?

Can you show a complete and minimal source code that reproduces this problem?
Title: LoaderLock
Post by: Kwang1imsa on July 17, 2011, 11:04:00 pm
Oh sorry. I meant to say "that's what I did after your first response"  :lol:

Anyways, that is essentially everything that is giving me problems.  I am also experiencing it with SFML.Graphics.Image();.

This is the entire constructor of my class:

Code: [Select]
public class GridEditGL : Panel
    {
        private Sprite drawSpr;
        private Sprite objSpr;
        public Dictionary<string,Sprite> drawSprList = new Dictionary<string,Sprite>();
        public List<tile> tilelist = new List<tile>();
        public List<obj> objlist = new List<obj>();
        public Sprite bgSpr;
        public SFML.Graphics.Image bg;
        private string defaultEmpty = @"resources\engine\editor\images\empty.png";
        public EnviroEditor parent;
        public RenderWindow mainWin;
        public GridEditGL(EnviroEditor par)
        {
            this.parent = par;
            this.Size = new Size(320, 320);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            drawSpr = new Sprite();
            bg = new SFML.Graphics.Image();
            objSpr = new Sprite();
            bgSpr = new Sprite();
            timer = new Timer();
            mainWin = new RenderWindow(this.Handle);
            mainWin.PreserveOpenGLStates(true);
            mainWin.UseVerticalSync(true);
 
            updateSize();
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, false);
            SetStyle(ControlStyles.Opaque, true);
            UpdateStyles();

        }


Edit: By the way, the class GridEditGL is created inside of the constructor of another class, which is created in the constructor of another class.
Title: LoaderLock
Post by: Laurent on July 18, 2011, 07:33:39 am
Quote
Edit: By the way, the class GridEditGL is created inside of the constructor of another class, which is created in the constructor of another class.

This is exactly why I'd prefer to see a complete and minimal code, not an incomplete piece of code from your big program ;)
Title: LoaderLock
Post by: Kwang1imsa on July 18, 2011, 08:29:17 am
Alright, sorry.  This is as much as I think is related to the issue.  I hope this supplement will cover it:

Main:
Code: [Select]
           Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.DoEvents();
            Application.Run((Form)new MainGui());


MainGui Constructor:
Code: [Select]

this.Hide();
                MainGui.root = this;
                this.splashScreen = new Splash();
                BackgroundWorker backgroundWorker = new BackgroundWorker();
                backgroundWorker.WorkerReportsProgress = true;
                backgroundWorker.DoWork += new DoWorkEventHandler(this.backgroundWorker1_DoWork);
                backgroundWorker.RunWorkerAsync();
                backgroundWorker.ReportProgress(this.loadState += 5);
               
                this.InitializeComponent();
                /*some irrelevant code here*/
                EnviroEditor enviroEditor = new EnviroEditor(par2); //<-- this contains GridEditGL
                this.loadState = 100;
                //System.Threading.Thread.Sleep(1000);
                ((Control)this).Show();


EnviroEdit Constructor:
Code: [Select]

public GridEditGL editor;
public EnviroEditor(EnviroBox par)
        {
            parent = par;
            InitializeComponent();
            editType.SelectedIndex = 0;
            teditor = new GridEdit(this);
            editor = new GridEditGL(this); //this is it <---
            Application.EnableVisualStyles();
            editor.tilelist = parent.tilelist;
            editor.objlist = parent.objlist;
            /*more irrelevant code*/
           
        }


I hope I didn't miss anything this time.  Thank you for keeping me company through this issue.[/code]
Title: LoaderLock
Post by: Laurent on July 18, 2011, 08:50:36 am
Sorry if it wasn't clear, but I don't want pieces of your original code. I'd like you to write a (new) complete code that reproduces the problem -- without the 99% of your initial code that is irrelevant. I need something that I can test quickly, something that focuses on the problem, and only the problem.

That's what "minimal and complete code" means ;)
Title: LoaderLock
Post by: Kwang1imsa on July 18, 2011, 06:43:05 pm
Ok. I understand.

A quick note to make, I tested this on 2 computers.  On one, the LoaderLock actually hangs the application, on the other, it is just thrown but can be ignored.

I will get something up shortly.
Title: LoaderLock
Post by: Kwang1imsa on July 18, 2011, 06:52:03 pm
Ok, so here is how to reproduce:

This did not throw a LoaderLock exception for me, but all the same it hangs the application:

1. Start a new Windows Forms Project
2. Go into Form1() and write this:

Code: [Select]

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            new SFML.Graphics.Sprite();
        }

    }
}



The application hangs on my new computer, and shouldn't on my old.  If I comment out SFML.Graphics.Sprite, it will run fine.

EDIT: I have been using SFML 1.6 and I just realized that my new computer runs an ATI graphics card.

Is there a version of 2.0 I can get for .NET?[/code]
Title: LoaderLock
Post by: Laurent on July 18, 2011, 10:51:39 pm
Quote
I have been using SFML 1.6 and I just realized that my new computer runs an ATI graphics card.

Oh... that explains everything :)

Quote
Is there a version of 2.0 I can get for .NET

https://github.com/SFML/SFML.Net
Title: LoaderLock
Post by: Kwang1imsa on July 19, 2011, 03:19:07 am
Awesome. I have been looking for that for ages!
Title: LoaderLock
Post by: Radnen on August 07, 2011, 11:08:41 pm
Quote from: "Laurent"
Quote
I have been using SFML 1.6 and I just realized that my new computer runs an ATI graphics card.

Oh... that explains everything :)


How does that explain everything? I have the same issue and use an Nvidia card.

Or is this loader lock present in version 1.6?
Title: LoaderLock
Post by: Laurent on August 08, 2011, 07:53:43 am
Quote
How does that explain everything? I have the same issue and use an Nvidia card.

It explains why the applications freezes on startup on Windows with an ATI graphics card -- that's a known bug in SFML 1.6.