Adding property to ModifierDNA causes compile failure

I’m trying to modify the Array modifier by adding a rotation to the relative offset mode.

All I did so far is add a float array variable to line 262 at the end of ArrayModifierData struct in DNA_modifier_types.h as shown below:

typedef struct ArrayModifierData {
    ...
    float rotation[3];
} ArrayModifierData;

This causes hundreds of errors which seem unrelated to the actual file. There’s hundreds so here are the first few:

  • Error MSB6006 “cmd.exe” exited with code 1. bf_dna C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets 171
  • Error C2065 ‘SDNA_TYPE_MAX’: undeclared identifier bf_blenloader E:\blender-git\blender\source\blender\blenloader\intern\writefile.c 513
  • Error C4013 ‘SDNA_TYPE_FROM_STRUCT’ undefined; assuming extern returning int bf_blenloader E:\blender-git\blender\source\blender\blenloader\intern\writefile.c 665
  • Error C2275 ‘IDProperty’: illegal use of this type as an expression bf_blenloader E:\blender-git\blender\source\blender\blenloader\intern\writefile.c 665
  • Error C2275 ‘IDProperty’: illegal use of this type as an expression bf_blenloader E:\blender-git\blender\source\blender\blenloader\intern\writefile.c 709
  • Error C2275 ‘IDOverrideStatic’: illegal use of this type as an expression bf_blenloader E:\blender-git\blender\source\blender\blenloader\intern\writefile.c 721

What am I missing? Why can’t I add a variable?

it’s a bit hard to see with all the unrelated errors, but the true error is

2>Target ResolveProjectReferences:
2>Target InitializeBuildStatus:
2>    Creating "bf_dna.dir\Debug\bf_dna.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
2>Target CustomBuild:
2>    Generating dna.c, dna_type_offsets.h
2>    Sizeerror 8 in struct: ArrayModifierData (add 4 bytes)

you need to add 4 padding bytes

I don’t see that error. Where should I add the padding bytes?

The dna_type_offsets.h file is empty, and the dna.c file is an unsigned char array with hundreds of numbers in.

typedef struct ArrayModifierData {
    ...
    float rotation[3];
    char pad[4];
} ArrayModifierData;

ought to do it.

1 Like

Well, I was sceptical but it works. It seems like a huge hack though! Why is this needed? None of the other modifiers have padding.

I want to understand!

yes they do, look harder :slight_smile: search for pad[ in that file, i find 21 occurrences…

you can read more about what it is and why it is there over here

Aaah yes I wasn’t looking hard enough but I see the pad references now. Thanks a lot. That link clears everything up