5 registered members (AndrewAMD, ozgur, Ayumi, 2 invisible),
690
guests, and 10
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: C# wrapper - RELEASE
[Re: Timothy]
#402948
06/12/12 17:01
06/12/12 17:01
|
Joined: Apr 2007
Posts: 141 Germany
Timothy
Member
|
Member
Joined: Apr 2007
Posts: 141
Germany
|
Hi, when I use an OpenFileDialog to load a model with "ENTITY.ent_create(LoadModel.FileName, new Vector(100, 100, 0), *anyfunction*);" I often get an AccessViolationException error (...wurde nicht behandelt. Es wurde versucht, im geschützten Speicher zu lesen oder zu schreiben. Dies ist häufig ein Hinweis darauf, dass anderer Speicher beschädigt ist). The Debugger points to (EngFun.cs):
/// <summary>
/// engine_frame - see Gamestudio manual
/// - for more detailed and up to date documentation, visit http://manual.3dgamestudio.net/ </summary>
public static int engine_frame()
{
return NativeEngFun.engine_frame();
}
This mainly happens if I load an *.MDL-file with 3+ MB. Then the engine needs a little time to load the model (short freeze of the embedded engine window) and I get the error (depends on the complexity/texture space of the model). I suspect that maybe the Scheduler and this freeze cause this error but it could be my fault, too. Do you have an idea?
|
|
|
Re: C# wrapper - RELEASE
[Re: Timothy]
#402950
06/12/12 17:28
06/12/12 17:28
|
Joined: Dec 2006
Posts: 434 UK,Terra, SolarSystem, Milky W...
pararealist
Senior Member
|
Senior Member
Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
|
Where are you calling openfiledialog from? could be a threading issue maybe. LoadModel.FileName is this a string? or a class that returns a string? Maybe check that string is not empty before passing to ent_create().
A8.3x Commercial, AcknexWrapper and VS 2010 Express ○pararealist now.
|
|
|
Re: C# wrapper - RELEASE
[Re: pararealist]
#402951
06/12/12 18:10
06/12/12 18:10
|
Joined: Apr 2007
Posts: 141 Germany
Timothy
Member
|
Member
Joined: Apr 2007
Posts: 141
Germany
|
Thanks for your answer. I use this code:
private void button3_Click(object sender, EventArgs e)
{
OpenFileDialog LoadModel = new OpenFileDialog();
LoadModel.Title = "Import Model";
LoadModel.InitialDirectory = @"C:\";
LoadModel.Filter = "MDL (*.mdl)|*.mdl|Alle Dateien (*.*)|*.*";
LoadModel.FilterIndex = 1;
LoadModel.RestoreDirectory = true;
if(LoadModel.ShowDialog() == DialogResult.OK)
{
ENTITY.ent_create(LoadModel.FileName, new Vector(100, 100, 0), obj);
_items.Add(LoadModel.FileName);
listBox1.DataSource = null;
listBox1.DataSource = _items;
}
}
It is called by a button in my Form. I think that OpenFileDialog returns a string but I don't know how to control the string. The code does work sometimes, but bigger models cause it to crash and this is not because I am out of memory.
Last edited by Timothy; 06/12/12 19:03.
|
|
|
Re: C# wrapper - RELEASE
[Re: Timothy]
#402984
06/13/12 05:46
06/13/12 05:46
|
Joined: Dec 2006
Posts: 434 UK,Terra, SolarSystem, Milky W...
pararealist
Senior Member
|
Senior Member
Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
|
Yes i had the same problem too. To give you an idea what i did.
private void button_LoadLevel_Click(object sender, EventArgs e)
{
//you can still put opendialog here
//i use a global "levelloaded" string in a static
//class called Global accessed through properties.
...
Global.strLoadedLevel = opendialog.filename;
Scheduler.AddEventVoidThreadSafe(LoadLevel);
}
private IEnumerable<ScheduleMethod> LoadLevel()
{
//i use a Global.strLoadedLevel as string
if(Global.strLoadedLevel != string.empty}
{
EngFun.level_load(Global.strLoadedLevel);
//reinit camera
InitCamera();
}
yield break;
}
Calling some engine functions from a Form event will cause thread problems. Hope this makes sense.
A8.3x Commercial, AcknexWrapper and VS 2010 Express ○pararealist now.
|
|
|
Re: C# wrapper - RELEASE
[Re: pararealist]
#402998
06/13/12 10:51
06/13/12 10:51
|
Joined: Apr 2007
Posts: 141 Germany
Timothy
Member
|
Member
Joined: Apr 2007
Posts: 141
Germany
|
I defined the Global class like this:
public static class Global
{
public static string entity_import;
}
I used the string like you said and it seems to work now. Thank you very much!
|
|
|
Re: C# wrapper - RELEASE
[Re: Timothy]
#403023
06/13/12 16:47
06/13/12 16:47
|
Joined: Dec 2006
Posts: 434 UK,Terra, SolarSystem, Milky W...
pararealist
Senior Member
|
Senior Member
Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
|
Good. probably better to use properties in global
public static class Global
{
private static string entity_import;
public static string Import
{
get {return entity_import;}
}
}
Last edited by pararealist; 06/13/12 16:48.
A8.3x Commercial, AcknexWrapper and VS 2010 Express ○pararealist now.
|
|
|
Re: C# wrapper - RELEASE
[Re: pararealist]
#404993
07/20/12 17:36
07/20/12 17:36
|
Joined: Nov 2007
Posts: 2,568 Germany, BW, Stuttgart
MasterQ32
Expert
|
Expert
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
|
could you please do something like this:
public Vector xyz
{
get
{
return Vector.createFromPointer(xPointer);
}
set
{
Vector.createFromPointer(xPointer).vec_set(value);
}
}
this would enable us to write better and easier code, because assigning a vector would look like this:
skyStars.xyz = camera.xyz;
and not like this:
skyStars.xyz.vec_set(camera.xyz);
EDIT: And please do not wrap all functions! I know it was hard work, but wrapping clamp instead of rewriting it is really bad. This solution is much safer and faster:
public static double clamp(double x, double a, double b)
{
if (x < a) return a;
if (x > b) return b;
return x;
}
also you should use ref/out instead of DoubleSet and those strange variable-setting delegates another thing to mention is that using read-only properties for stuff like getting entity or bmap properties:
public int Width
{
get
{
return bmap_width();
}
}
Last edited by MasterQ32; 07/20/12 18:38. Reason: Additional things
|
|
|
|