bb.EntityName error

Archives Forums/Blitz3D SDK Programming/bb.EntityName error

Chaos(Posted 2008) [#1]
Can anyone help here? I've been creating a 3D map editor for a project im working on and hit a problem with the Blitz3DSDK, I'm using Visual C# (in VS2005 with a coupe of extra Lib's) - Ive tracked the problem down to the bb.EntityName command.

I'm trying to get the name of the entity under the cursor, I can get the Entity ID / Number but when I try and convert this to the name of the entity the app throws a AccessViolationException error claiming I was trying to read or write to protected memory!!

I would also point out that this ONLY happens if I run the app on windows VISTA! (32 or 64bit) and runs perfectly on XP (32 or 64bit)

I have modified the sample source code to show the exception im getting (move the cursor over the block on the screen and it should crash) - just overwrite the program.cs code with:-



using System;

using bb = Blitz3DSDK;

static class RotateCube
{
[STAThread]
static void Main()
{
bb.BeginBlitz3D();
bb.Graphics3D(960, 540, 0, 2);
int value = 0;
string ename = "";
int cube = bb.CreateCube(0);
int light = bb.CreateLight(1, 0);
int camera = bb.CreateCamera(0);
bb.EntityPickMode(cube, 3);
bb.NameEntity(cube, "The-Cube");
bb.PositionEntity(camera, 0, 0, -4, 1);

while (bb.KeyHit(bb.KEY_ESCAPE) == 0)
{
bb.UpdateWorld(1);
bb.RenderWorld(0);
bb.CameraPick(camera, bb.MouseX(), bb.MouseY());
value = bb.PickedEntity();
if (value != 0)
{
//ename = ToString(value);
bb.Text(20, bb.GraphicsHeight() - 40, "Entity Name ="+value, 0, 0);
ename = bb.EntityName(value);

}
bb.TurnEntity(cube, .1f, .2f, .3f, 1);
bb.Text(20, bb.GraphicsHeight() - 20, "Blitz3DSDK C# Example (C)2007 Blitz Research 2007", 0, 0);
bb.Flip(1);
}
bb.EndBlitz3D();
}
}


Any Help would be very much appreciated!!


monotonic(Posted 2008) [#2]
Hi,

I have recently posted a bug report about the very same thing, I don't have anything other than Vista 32bit to test.

So its a Vista thing eh!


Chaos(Posted 2008) [#3]
Monotonic,

Yes it would seem so, I have no problems on xp at all! - just Vista, its a real pain.


Kale Kold(Posted 2008) [#4]
I might be stating the obvious here so i understand if i get flamed, but have you made sure your platform target is set to 'x86' in the project properties?


Chaos(Posted 2008) [#5]
Kale Kold,

I'm not about to flame anyone - it was a good question - the project is set for x86, the application will run quite happily until it hits the EntityName command then it crashes with the error above.

-Chaos


monotonic(Posted 2008) [#6]
I find it quite funny (in the loosest sense of the word) that it’s a function like EntityName that has issues with Vista. You would have thought a function that actually does something with DirectX or some low-level stuff would have issues.

Its easily solved just by adding your own string Name, property, but it would be nice to be able to use the in-built one, but what ya gonna do.


Chaos(Posted 2008) [#7]
Monotonic,

Could you elaborate on your work around? - when you say adding a string name property do you mean assinging a type value or something else?

I need to be able to name entitys and read back their names so if you could post a workaround based say on the simple code snippet above that would be great

Cheers -

Chaos


monotonic(Posted 2008) [#8]
Sorry for the delay.

What I do is create a class for my 3D objects, for instance:


class WorldObject
{

// The Blitz 3D object
public int Object
{
get {return m_n_object;}
} private int m_n_object;

// The name property
public string Name
{
get {return m_s_name;}
set {m_s_name = value;}
} private string m_s_name;


// other methods properties here, construction etc....

}



Obviously if creating a class for each object is a little too much overhead for your purposes then you could create a structure which is created on the stack which is faster access than classes which are created on the heap.

Or you could even create a key-value array with the object pointer as the key and the name as the value.


Chaos(Posted 2008) [#9]
Monotonic,

Ahhhhh.... I see, thanks for that, Ill have a play and see what I can do - till the bugs fixed anyway!!

Cheers

Chaos