SFML community forums
Bindings - other languages => DotNet => Topic started by: Kwang1imsa on July 15, 2011, 01:45:58 am
-
private Sprite drawSpr = new Sprite();
In this line I am experiencing this error:
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]
-
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.
-
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?
-
Can't you initialize it in the constructor?
-
That's exactly what I do:
private Sprite drawSpr;
In the constructor:
drawSpr = new Sprite();
This is very odd. Am I doing something wrong?
-
That's exactly what I do
That's not what you showed in your first post... ;)
This is very odd. Am I doing something wrong?
Can you show a complete and minimal source code that reproduces this problem?
-
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:
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.
-
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 ;)
-
Alright, sorry. This is as much as I think is related to the issue. I hope this supplement will cover it:
Main:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.DoEvents();
Application.Run((Form)new MainGui());
MainGui Constructor:
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:
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]
-
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 ;)
-
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.
-
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:
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]
-
I have been using SFML 1.6 and I just realized that my new computer runs an ATI graphics card.
Oh... that explains everything :)
Is there a version of 2.0 I can get for .NET
https://github.com/SFML/SFML.Net
-
Awesome. I have been looking for that for ages!
-
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?
-
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.