Structs engine crash

Discussions about Coding and Scripting
Post Reply
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Structs engine crash

Post by Feralidragon »

Hi there,

I just want a confirmation if you know this one:
- is it normal the engine crash with structs like this:

Code: Select all

struct StructA
{
  var() name var1;
  var() vector var2;
  var() sound var3;
};

struct StructB extends StructA
{
  var() name var4;
  var() vector var5;
  var() sound var6;
}
Namely the StructB. When I make something like that, StructA can be accessed without a problem, while StructB crashes the game once I access it.
If I however make something like this:

Code: Select all

struct StructB
{
  var() name var1;
  var() vector var2;
  var() sound var3;
  var() name var4;
  var() vector var5;
  var() sound var6;
}
It doesn't crash.
Is the struct "extend" broken somewhat in UEngine1.x? Or does the "extend" only break when one (or both) of the structs have other structs inside them (like vectors) or references (like sounds, classes, etc)?
I didn't test it further, so if someone knows or can do a small set of tests to check this out, it would be great just to know what exactly is going on.

I wanted to use extend since it was the more correct thing in my case, but I will have to go with the ugly way and replicate the vars to the second struct instead.
iloveut99
Skilled
Posts: 231
Joined: Mon Aug 16, 2010 10:25 pm

Re: Structs engine crash

Post by iloveut99 »

Is it possible to extend a struct in first place? An alternative to the redundant code would be transform StructA and StructB in classes.

Edit\

Another alternative would be use a structA in B:

Code: Select all

struct StructA
{
  var() name var1;
  var() vector var2;
  var() sound var3;
};

struct StructB
{
  var() StructA var0;
  var() name var4;
  var() vector var5;
  var() sound var6;
}
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Structs engine crash

Post by Feralidragon »

Yes, you can extend structs in UScript, but it appears that it breaks in some cases like this one :\
If you look at the Object class, it has 2 structs that extends other structs (Plane extends Vector, and BoundingVolume extends BoundingBox), but those 2 structs are never used anyway (at least at UScript level from what I saw), nor I saw them used anywhere else, so I really don't know if they are actually broken or not.

Well, classes have the problem of having to be instantiated in order to be used (which is still a costly operation), while I just want to store some structured data for arrays.

As for adding the struct within another, that's a different concept, I would have to access it and store default properties in a different way (instead of accessing StructB.var6 I would need to access as StructB.var0.var6 instead), and I that's not what I want.

Thanks for the suggestions though :wink:
User avatar
Shadow
Masterful
Posts: 743
Joined: Tue Jan 29, 2008 12:00 am
Personal rank: Mad Carpenter
Location: Germany
Contact:

Re: Structs engine crash

Post by Shadow »

Interesting topic. How do you access the structs? As single variables or as elements of array list. Last one is important because dynamic arrays are totally fucked up on Unreal Script level when dealing with more complex structs (structs with different pointer data structures like class, sound etc.)

Plane and Bounding Box are used internally by the Engine on C++ Level, plane for example for draw/color functions

Well I'll test your both structs tomorrow if this is a general problem or just in your case... but I think it's a standard problem.
Image
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Structs engine crash

Post by Feralidragon »

These are my original structs:

Code: Select all

struct SingleSlicingData
{
	var() name AttackAnim;
	var() name RecoilAnim;
	var() float AttackRate;
	var() float RecoilRate;
	var() sound AttackSnd;
	var() vector AttackOffset;
	var() vector AttackDir;
	var() float AttackDelay;
};

struct DoubleSlicingData extends SingleSlicingData
{
	var() vector AttackOffset2;
	var() vector AttackDir2;
	var() float AttackDelay2;
};
I used them in arrays as here:

Code: Select all

var() SingleSlicingData SingleAttacks[4];
var() DoubleSlicingData DoubleAttacks[4];
I access them as SingleAttacks[someIndex].AttackAnim

Yeah, that's what I think the problem could be since I have a "sound" in the first one, but it was just a theory so far.
As different structs both work perfectly, as B extending A, only A works, B crashes on read.
Post Reply