Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(eht): account for non-pointer fields when computing component offsets

esengine45440ad2ae3a
diff --git a/build-tools/tasks/eht.js b/build-tools/tasks/eht.js
index 9505122ab..48bc44973 100644
--- a/build-tools/tasks/eht.js
+++ b/build-tools/tasks/eht.js
@@ -2,7 +2,7 @@ import path from 'path';
import { glob } from 'fs/promises';
import config from '../build.config.js';
import * as logger from '../utils/logger.js';
-import { runCommand } from '../utils/emscripten.js';
+import { runCommand, resolvePython } from '../utils/emscripten.js';
import { hashFiles, HashCache } from '../utils/hash.js';
export async function runEht(options = {}) {
@@ -78,7 +78,8 @@ async function executeEht(rootDir, script) {
const outputDir = path.join(rootDir, config.eht.outputDir);
const tsOutputDir = path.join(rootDir, config.eht.tsOutputDir);
- await runCommand('python3', [
+ const python = await resolvePython() ?? 'python3';
+ await runCommand(python, [
script,
'--input', path.join(rootDir, config.eht.inputDir),
'--output', outputDir,
diff --git a/build-tools/utils/emscripten.js b/build-tools/utils/emscripten.js
index 97df92f75..a7644b4e0 100644
--- a/build-tools/utils/emscripten.js
+++ b/build-tools/utils/emscripten.js
@@ -39,13 +39,32 @@ export async function checkEmscripten() {
}
}
-export async function checkPython() {
- try {
- await runCommand('python3', ['--version'], { silent: true });
- return true;
- } catch {
- return false;
+let cachedPython = null;
+
+/**
+ * Resolve a Python 3 interpreter. Prefers `python3`, falls back to `python`
+ * (Windows ships Python as `python`, not `python3`). Verifies the candidate
+ * actually reports Python 3 so a Windows Store alias stub doesn't pass.
+ * Returns the command name, or null if none found. Cached after first call.
+ */
+export async function resolvePython() {
+ if (cachedPython) return cachedPython;
+ for (const candidate of ['python3', 'python']) {
+ try {
+ const r = await runCommand(candidate, ['--version'], { silent: true });
+ if (/Python 3\./.test(`${r.stdout}${r.stderr}`)) {
+ cachedPython = candidate;
+ return candidate;
+ }
+ } catch {
+ // try next candidate
+ }
}
+ return null;
+}
+
+export async function checkPython() {
+ return (await resolvePython()) !== null;
}
export async function checkEnvironment() {
diff --git a/sdk/src/component.generated.ts b/sdk/src/component.generated.ts
index eb43d39e1..38a52eb6c 100644
--- a/sdk/src/component.generated.ts
+++ b/sdk/src/component.generated.ts
@@ -12,7 +12,7 @@ import type { AssetFieldType } from './scene';
* getAbiLayoutHash(); BuiltinBridge.connect() compares them and refuses to
* run on mismatch, because mismatched offsets read the wrong heap bytes.
*/
-export const ABI_LAYOUT_HASH = 'f5d18743d00de675';
+export const ABI_LAYOUT_HASH = '579120e76e895e7c';
export interface AssetFieldMeta {
field: string;
diff --git a/sdk/src/ecs/ptrAccessors.generated.ts b/sdk/src/ecs/ptrAccessors.generated.ts
index 09c1654b3..ca089a115 100644
--- a/sdk/src/ecs/ptrAccessors.generated.ts
+++ b/sdk/src/ecs/ptrAccessors.generated.ts
@@ -23,26 +23,26 @@ export function fillBitmapText(
f32: Float32Array, u32: Uint32Array, u8: Uint8Array,
ptr: number, out: BitmapTextPtrData,
): void {
- const color_ = out.color; color_.r = f32[ptr >> 2]; color_.g = f32[(ptr >> 2) + 1]; color_.b = f32[(ptr >> 2) + 2]; color_.a = f32[(ptr >> 2) + 3];
- out.fontSize = f32[(ptr + 16) >> 2];
- out.align = u8[ptr + 20];
- out.spacing = f32[(ptr + 24) >> 2];
- out.layer = u32[(ptr + 28) >> 2] | 0;
- out.font = u32[(ptr + 32) >> 2];
- out.enabled = u8[ptr + 36] !== 0;
+ const color_ = out.color; color_.r = f32[(ptr + 12) >> 2]; color_.g = f32[((ptr + 12) >> 2) + 1]; color_.b = f32[((ptr + 12) >> 2) + 2]; color_.a = f32[((ptr + 12) >> 2) + 3];
+ out.fontSize = f32[(ptr + 28) >> 2];
+ out.align = u8[ptr + 32];
+ out.spacing = f32[(ptr + 36) >> 2];
+ out.layer = u32[(ptr + 40) >> 2] | 0;
+ out.font = u32[(ptr + 44) >> 2];
+ out.enabled = u8[ptr + 48] !== 0;
}
export function writeBitmapText(
f32: Float32Array, u32: Uint32Array, u8: Uint8Array,
ptr: number, data: BitmapTextPtrData,
): void {
- f32[ptr >> 2] = data.color.r; f32[(ptr >> 2) + 1] = data.color.g; f32[(ptr >> 2) + 2] = data.color.b; f32[(ptr >> 2) + 3] = data.color.a;
- f32[(ptr + 16) >> 2] = data.fontSize;
- u8[ptr + 20] = data.align;
- f32[(ptr + 24) >> 2] = data.spacing;
- u32[(ptr + 28) >> 2] = data.layer | 0;
- u32[(ptr + 32) >> 2] = data.font;
- u8[ptr + 36] = data.enabled ? 1 : 0;
+ f32[(ptr + 12) >> 2] = data.color.r; f32[((ptr + 12) >> 2) + 1] = data.color.g; f32[((ptr + 12) >> 2) + 2] = data.color.b; f32[((ptr + 12) >> 2) + 3] = data.color.a;
+ f32[(ptr + 28) >> 2] = data.fontSize;
+ u8[ptr + 32] = data.align;
+ f32[(ptr + 36) >> 2] = data.spacing;
+ u32[(ptr + 40) >> 2] = data.layer | 0;
+ u32[(ptr + 44) >> 2] = data.font;
+ u8[ptr + 48] = data.enabled ? 1 : 0;
}
export function createBitmapTextData(): BitmapTextPtrData {
@@ -452,12 +452,12 @@ export function fillFlexItem(
out.flexBasis = f32[(ptr + 8) >> 2];
out.order = u32[(ptr + 12) >> 2] | 0;
out.alignSelf = u8[ptr + 16];
- out.minWidth = f32[(ptr + 20) >> 2];
- out.minHeight = f32[(ptr + 24) >> 2];
- out.maxWidth = f32[(ptr + 28) >> 2];
- out.maxHeight = f32[(ptr + 32) >> 2];
- out.widthPercent = f32[(ptr + 36) >> 2];
- out.heightPercent = f32[(ptr + 40) >> 2];
+ out.minWidth = f32[(ptr + 36) >> 2];
+ out.minHeight = f32[(ptr + 40) >> 2];
+ out.maxWidth = f32[(ptr + 44) >> 2];
+ out.maxHeight = f32[(ptr + 48) >> 2];
+ out.widthPercent = f32[(ptr + 52) >> 2];
+ out.heightPercent = f32[(ptr + 56) >> 2];
}
export function writeFlexItem(
@@ -469,12 +469,12 @@ export function writeFlexItem(
f32[(ptr + 8) >> 2] = data.flexBasis;
u32[(ptr + 12) >> 2] = data.order | 0;
u8[ptr + 16] = data.alignSelf;
- f32[(ptr + 20) >> 2] = data.minWidth;
- f32[(ptr + 24) >> 2] = data.minHeight;
- f32[(ptr + 28) >> 2] = data.maxWidth;
- f32[(ptr + 32) >> 2] = data.maxHeight;
- f32[(ptr + 36) >> 2] = data.widthPercent;
- f32[(ptr + 40) >> 2] = data.heightPercent;
+ f32[(ptr + 36) >> 2] = data.minWidth;
+ f32[(ptr + 40) >> 2] = data.minHeight;
+ f32[(ptr + 44) >> 2] = data.maxWidth;
+ f32[(ptr + 48) >> 2] = data.maxHeight;
+ f32[(ptr + 52) >> 2] = data.widthPercent;
+ f32[(ptr + 56) >> 2] = data.heightPercent;
}
export function createFlexItemData(): FlexItemPtrData {
@@ -854,32 +854,32 @@ export function fillSpineAnimation(
f32: Float32Array, u32: Uint32Array, u8: Uint8Array,
ptr: number, out: SpineAnimationPtrData,
): void {
- out.timeScale = f32[ptr >> 2];
- out.loop = u8[ptr + 4] !== 0;
- out.playing = u8[ptr + 5] !== 0;
- out.flipX = u8[ptr + 6] !== 0;
- out.flipY = u8[ptr + 7] !== 0;
- const color_ = out.color; color_.r = f32[(ptr + 8) >> 2]; color_.g = f32[((ptr + 8) >> 2) + 1]; color_.b = f32[((ptr + 8) >> 2) + 2]; color_.a = f32[((ptr + 8) >> 2) + 3];
- out.layer = u32[(ptr + 24) >> 2] | 0;
- out.skeletonScale = f32[(ptr + 28) >> 2];
- out.material = u32[(ptr + 32) >> 2];
- out.enabled = u8[ptr + 36] !== 0;
+ out.timeScale = f32[(ptr + 48) >> 2];
+ out.loop = u8[ptr + 52] !== 0;
+ out.playing = u8[ptr + 53] !== 0;
+ out.flipX = u8[ptr + 54] !== 0;
+ out.flipY = u8[ptr + 55] !== 0;
+ const color_ = out.color; color_.r = f32[(ptr + 56) >> 2]; color_.g = f32[((ptr + 56) >> 2) + 1]; color_.b = f32[((ptr + 56) >> 2) + 2]; color_.a = f32[((ptr + 56) >> 2) + 3];
+ out.layer = u32[(ptr + 72) >> 2] | 0;
+ out.skeletonScale = f32[(ptr + 76) >> 2];
+ out.material = u32[(ptr + 80) >> 2];
+ out.enabled = u8[ptr + 84] !== 0;
}
export function writeSpineAnimation(
f32: Float32Array, u32: Uint32Array, u8: Uint8Array,
ptr: number, data: SpineAnimationPtrData,
): void {
- f32[ptr >> 2] = data.timeScale;
- u8[ptr + 4] = data.loop ? 1 : 0;
- u8[ptr + 5] = data.playing ? 1 : 0;
- u8[ptr + 6] = data.flipX ? 1 : 0;
- u8[ptr + 7] = data.flipY ? 1 : 0;
- f32[(ptr + 8) >> 2] = data.color.r; f32[((ptr + 8) >> 2) + 1] = data.color.g; f32[((ptr + 8) >> 2) + 2] = data.color.b; f32[((ptr + 8) >> 2) + 3] = data.color.a;
- u32[(ptr + 24) >> 2] = data.layer | 0;
- f32[(ptr + 28) >> 2] = data.skeletonScale;
- u32[(ptr + 32) >> 2] = data.material;
- u8[ptr + 36] = data.enabled ? 1 : 0;
+ f32[(ptr + 48) >> 2] = data.timeScale;
+ u8[ptr + 52] = data.loop ? 1 : 0;
+ u8[ptr + 53] = data.playing ? 1 : 0;
+ u8[ptr + 54] = data.flipX ? 1 : 0;
+ u8[ptr + 55] = data.flipY ? 1 : 0;
+ f32[(ptr + 56) >> 2] = data.color.r; f32[((ptr + 56) >> 2) + 1] = data.color.g; f32[((ptr + 56) >> 2) + 2] = data.color.b; f32[((ptr + 56) >> 2) + 3] = data.color.a;
+ u32[(ptr + 72) >> 2] = data.layer | 0;
+ f32[(ptr + 76) >> 2] = data.skeletonScale;
+ u32[(ptr + 80) >> 2] = data.material;
+ u8[ptr + 84] = data.enabled ? 1 : 0;
}
export function createSpineAnimationData(): SpineAnimationPtrData {
@@ -969,130 +969,6 @@ export function createSpriteData(): SpritePtrData {
};
}
-export interface StateVisualsPtrData {
- transitionFlags: number;
- fadeDuration: number;
- slot0Color: Color;
- slot0Sprite: number;
- slot0Scale: number;
- slot1Color: Color;
- slot1Sprite: number;
- slot1Scale: number;
- slot2Color: Color;
- slot2Sprite: number;
- slot2Scale: number;
- slot3Color: Color;
- slot3Sprite: number;
- slot3Scale: number;
- slot4Color: Color;
- slot4Sprite: number;
- slot4Scale: number;
- slot5Color: Color;
- slot5Sprite: number;
- slot5Scale: number;
- slot6Color: Color;
- slot6Sprite: number;
- slot6Scale: number;
- slot7Color: Color;
- slot7Sprite: number;
- slot7Scale: number;
-}
-
-export function fillStateVisuals(
- f32: Float32Array, u32: Uint32Array, u8: Uint8Array,
- ptr: number, out: StateVisualsPtrData,
-): void {
- out.transitionFlags = u32[ptr >> 2];
- out.fadeDuration = f32[(ptr + 4) >> 2];
- const slot0Color_ = out.slot0Color; slot0Color_.r = f32[(ptr + 8) >> 2]; slot0Color_.g = f32[((ptr + 8) >> 2) + 1]; slot0Color_.b = f32[((ptr + 8) >> 2) + 2]; slot0Color_.a = f32[((ptr + 8) >> 2) + 3];
- out.slot0Sprite = u32[(ptr + 24) >> 2];
- out.slot0Scale = f32[(ptr + 28) >> 2];
- const slot1Color_ = out.slot1Color; slot1Color_.r = f32[(ptr + 32) >> 2]; slot1Color_.g = f32[((ptr + 32) >> 2) + 1]; slot1Color_.b = f32[((ptr + 32) >> 2) + 2]; slot1Color_.a = f32[((ptr + 32) >> 2) + 3];
- out.slot1Sprite = u32[(ptr + 48) >> 2];
- out.slot1Scale = f32[(ptr + 52) >> 2];
- const slot2Color_ = out.slot2Color; slot2Color_.r = f32[(ptr + 56) >> 2]; slot2Color_.g = f32[((ptr + 56) >> 2) + 1]; slot2Color_.b = f32[((ptr + 56) >> 2) + 2]; slot2Color_.a = f32[((ptr + 56) >> 2) + 3];
- out.slot2Sprite = u32[(ptr + 72) >> 2];
- out.slot2Scale = f32[(ptr + 76) >> 2];
- const slot3Color_ = out.slot3Color; slot3Color_.r = f32[(ptr + 80) >> 2]; slot3Color_.g = f32[((ptr + 80) >> 2) + 1]; slot3Color_.b = f32[((ptr + 80) >> 2) + 2]; slot3Color_.a = f32[((ptr + 80) >> 2) + 3];
- out.slot3Sprite = u32[(ptr + 96) >> 2];
- out.slot3Scale = f32[(ptr + 100) >> 2];
- const slot4Color_ = out.slot4Color; slot4Color_.r = f32[(ptr + 104) >> 2]; slot4Color_.g = f32[((ptr + 104) >> 2) + 1]; slot4Color_.b = f32[((ptr + 104) >> 2) + 2]; slot4Color_.a = f32[((ptr + 104) >> 2) + 3];
- out.slot4Sprite = u32[(ptr + 120) >> 2];
- out.slot4Scale = f32[(ptr + 124) >> 2];
- const slot5Color_ = out.slot5Color; slot5Color_.r = f32[(ptr + 128) >> 2]; slot5Color_.g = f32[((ptr + 128) >> 2) + 1]; slot5Color_.b = f32[((ptr + 128) >> 2) + 2]; slot5Color_.a = f32[((ptr + 128) >> 2) + 3];
- out.slot5Sprite = u32[(ptr + 144) >> 2];
- out.slot5Scale = f32[(ptr + 148) >> 2];
- const slot6Color_ = out.slot6Color; slot6Color_.r = f32[(ptr + 152) >> 2]; slot6Color_.g = f32[((ptr + 152) >> 2) + 1]; slot6Color_.b = f32[((ptr + 152) >> 2) + 2]; slot6Color_.a = f32[((ptr + 152) >> 2) + 3];
- out.slot6Sprite = u32[(ptr + 168) >> 2];
- out.slot6Scale = f32[(ptr + 172) >> 2];
- const slot7Color_ = out.slot7Color; slot7Color_.r = f32[(ptr + 176) >> 2]; slot7Color_.g = f32[((ptr + 176) >> 2) + 1]; slot7Color_.b = f32[((ptr + 176) >> 2) + 2]; slot7Color_.a = f32[((ptr + 176) >> 2) + 3];
- out.slot7Sprite = u32[(ptr + 192) >> 2];
- out.slot7Scale = f32[(ptr + 196) >> 2];
-}
-
-export function writeStateVisuals(
- f32: Float32Array, u32: Uint32Array, u8: Uint8Array,
- ptr: number, data: StateVisualsPtrData,
-): void {
- u32[ptr >> 2] = data.transitionFlags;
- f32[(ptr + 4) >> 2] = data.fadeDuration;
- f32[(ptr + 8) >> 2] = data.slot0Color.r; f32[((ptr + 8) >> 2) + 1] = data.slot0Color.g; f32[((ptr + 8) >> 2) + 2] = data.slot0Color.b; f32[((ptr + 8) >> 2) + 3] = data.slot0Color.a;
- u32[(ptr + 24) >> 2] = data.slot0Sprite;
- f32[(ptr + 28) >> 2] = data.slot0Scale;
- f32[(ptr + 32) >> 2] = data.slot1Color.r; f32[((ptr + 32) >> 2) + 1] = data.slot1Color.g; f32[((ptr + 32) >> 2) + 2] = data.slot1Color.b; f32[((ptr + 32) >> 2) + 3] = data.slot1Color.a;
- u32[(ptr + 48) >> 2] = data.slot1Sprite;
- f32[(ptr + 52) >> 2] = data.slot1Scale;
- f32[(ptr + 56) >> 2] = data.slot2Color.r; f32[((ptr + 56) >> 2) + 1] = data.slot2Color.g; f32[((ptr + 56) >> 2) + 2] = data.slot2Color.b; f32[((ptr + 56) >> 2) + 3] = data.slot2Color.a;
- u32[(ptr + 72) >> 2] = data.slot2Sprite;
- f32[(ptr + 76) >> 2] = data.slot2Scale;
- f32[(ptr + 80) >> 2] = data.slot3Color.r; f32[((ptr + 80) >> 2) + 1] = data.slot3Color.g; f32[((ptr + 80) >> 2) + 2] = data.slot3Color.b; f32[((ptr + 80) >> 2) + 3] = data.slot3Color.a;
- u32[(ptr + 96) >> 2] = data.slot3Sprite;
- f32[(ptr + 100) >> 2] = data.slot3Scale;
- f32[(ptr + 104) >> 2] = data.slot4Color.r; f32[((ptr + 104) >> 2) + 1] = data.slot4Color.g; f32[((ptr + 104) >> 2) + 2] = data.slot4Color.b; f32[((ptr + 104) >> 2) + 3] = data.slot4Color.a;
- u32[(ptr + 120) >> 2] = data.slot4Sprite;
- f32[(ptr + 124) >> 2] = data.slot4Scale;
- f32[(ptr + 128) >> 2] = data.slot5Color.r; f32[((ptr + 128) >> 2) + 1] = data.slot5Color.g; f32[((ptr + 128) >> 2) + 2] = data.slot5Color.b; f32[((ptr + 128) >> 2) + 3] = data.slot5Color.a;
- u32[(ptr + 144) >> 2] = data.slot5Sprite;
- f32[(ptr + 148) >> 2] = data.slot5Scale;
- f32[(ptr + 152) >> 2] = data.slot6Color.r; f32[((ptr + 152) >> 2) + 1] = data.slot6Color.g; f32[((ptr + 152) >> 2) + 2] = data.slot6Color.b; f32[((ptr + 152) >> 2) + 3] = data.slot6Color.a;
- u32[(ptr + 168) >> 2] = data.slot6Sprite;
- f32[(ptr + 172) >> 2] = data.slot6Scale;
- f32[(ptr + 176) >> 2] = data.slot7Color.r; f32[((ptr + 176) >> 2) + 1] = data.slot7Color.g; f32[((ptr + 176) >> 2) + 2] = data.slot7Color.b; f32[((ptr + 176) >> 2) + 3] = data.slot7Color.a;
- u32[(ptr + 192) >> 2] = data.slot7Sprite;
- f32[(ptr + 196) >> 2] = data.slot7Scale;
-}
-
-export function createStateVisualsData(): StateVisualsPtrData {
- return {
- transitionFlags: 0,
- fadeDuration: 0,
- slot0Color: { r: 0, g: 0, b: 0, a: 0 },
- slot0Sprite: 0,
- slot0Scale: 0,
- slot1Color: { r: 0, g: 0, b: 0, a: 0 },
- slot1Sprite: 0,
- slot1Scale: 0,
- slot2Color: { r: 0, g: 0, b: 0, a: 0 },
- slot2Sprite: 0,
- slot2Scale: 0,
- slot3Color: { r: 0, g: 0, b: 0, a: 0 },
- slot3Sprite: 0,
- slot3Scale: 0,
- slot4Color: { r: 0, g: 0, b: 0, a: 0 },
- slot4Sprite: 0,
- slot4Scale: 0,
- slot5Color: { r: 0, g: 0, b: 0, a: 0 },
- slot5Sprite: 0,
- slot5Scale: 0,
- slot6Color: { r: 0, g: 0, b: 0, a: 0 },
- slot6Sprite: 0,
- slot6Scale: 0,
- slot7Color: { r: 0, g: 0, b: 0, a: 0 },
- slot7Sprite: 0,
- slot7Scale: 0,
- };
-}
-
export interface TilemapLayerPtrData {
cellSize: Vec2;
originOffset: Vec2;
@@ -1408,7 +1284,6 @@ export const PTR_ACCESSORS: Record<string, PtrAccessor<any>> = {
ShapeRenderer: { fill: fillShapeRenderer, write: writeShapeRenderer, create: createShapeRendererData },
SpineAnimation: { fill: fillSpineAnimation, write: writeSpineAnimation, create: createSpineAnimationData },
Sprite: { fill: fillSprite, write: writeSprite, create: createSpriteData },
- StateVisuals: { fill: fillStateVisuals, write: writeStateVisuals, create: createStateVisualsData },
TilemapLayer: { fill: fillTilemapLayer, write: writeTilemapLayer, create: createTilemapLayerData },
Transform: { fill: fillTransform, write: writeTransform, create: createTransformData },
UIInteraction: { fill: fillUIInteraction, write: writeUIInteraction, create: createUIInteractionData },
diff --git a/sdk/src/ptrLayouts.generated.ts b/sdk/src/ptrLayouts.generated.ts
index d78e4cae8..47c23a4f1 100644
--- a/sdk/src/ptrLayouts.generated.ts
+++ b/sdk/src/ptrLayouts.generated.ts
@@ -21,13 +21,13 @@ export const PTR_LAYOUTS: Record<string, PtrLayout> = {
BitmapText: {
ptrFn: 'getBitmapTextPtr',
fields: [
- { name: 'color', type: 'color', offset: 0 },
- { name: 'fontSize', type: 'f32', offset: 16 },
- { name: 'align', type: 'u8', offset: 20 },
- { name: 'spacing', type: 'f32', offset: 24 },
- { name: 'layer', type: 'i32', offset: 28 },
- { name: 'font', type: 'u32', offset: 32 },
- { name: 'enabled', type: 'bool', offset: 36 },
+ { name: 'color', type: 'color', offset: 12 },
+ { name: 'fontSize', type: 'f32', offset: 28 },
+ { name: 'align', type: 'u8', offset: 32 },
+ { name: 'spacing', type: 'f32', offset: 36 },
+ { name: 'layer', type: 'i32', offset: 40 },
+ { name: 'font', type: 'u32', offset: 44 },
+ { name: 'enabled', type: 'bool', offset: 48 },
],
},
Camera: {
@@ -131,12 +131,12 @@ export const PTR_LAYOUTS: Record<string, PtrLayout> = {
{ name: 'flexBasis', type: 'f32', offset: 8 },
{ name: 'order', type: 'i32', offset: 12 },
{ name: 'alignSelf', type: 'u8', offset: 16 },
- { name: 'minWidth', type: 'f32', offset: 20 },
- { name: 'minHeight', type: 'f32', offset: 24 },
- { name: 'maxWidth', type: 'f32', offset: 28 },
- { name: 'maxHeight', type: 'f32', offset: 32 },
- { name: 'widthPercent', type: 'f32', offset: 36 },
- { name: 'heightPercent', type: 'f32', offset: 40 },
+ { name: 'minWidth', type: 'f32', offset: 36 },
+ { name: 'minHeight', type: 'f32', offset: 40 },
+ { name: 'maxWidth', type: 'f32', offset: 44 },
+ { name: 'maxHeight', type: 'f32', offset: 48 },
+ { name: 'widthPercent', type: 'f32', offset: 52 },
+ { name: 'heightPercent', type: 'f32', offset: 56 },
],
},
GridLayout: {
@@ -228,16 +228,16 @@ export const PTR_LAYOUTS: Record<string, PtrLayout> = {
SpineAnimation: {
ptrFn: 'getSpineAnimationPtr',
fields: [
- { name: 'timeScale', type: 'f32', offset: 0 },
- { name: 'loop', type: 'bool', offset: 4 },
- { name: 'playing', type: 'bool', offset: 5 },
- { name: 'flipX', type: 'bool', offset: 6 },
- { name: 'flipY', type: 'bool', offset: 7 },
- { name: 'color', type: 'color', offset: 8 },
- { name: 'layer', type: 'i32', offset: 24 },
- { name: 'skeletonScale', type: 'f32', offset: 28 },
- { name: 'material', type: 'u32', offset: 32 },
- { name: 'enabled', type: 'bool', offset: 36 },
+ { name: 'timeScale', type: 'f32', offset: 48 },
+ { name: 'loop', type: 'bool', offset: 52 },
+ { name: 'playing', type: 'bool', offset: 53 },
+ { name: 'flipX', type: 'bool', offset: 54 },
+ { name: 'flipY', type: 'bool', offset: 55 },
+ { name: 'color', type: 'color', offset: 56 },
+ { name: 'layer', type: 'i32', offset: 72 },
+ { name: 'skeletonScale', type: 'f32', offset: 76 },
+ { name: 'material', type: 'u32', offset: 80 },
+ { name: 'enabled', type: 'bool', offset: 84 },
],
},
Sprite: {
@@ -258,37 +258,6 @@ export const PTR_LAYOUTS: Record<string, PtrLayout> = {
{ name: 'enabled', type: 'bool', offset: 80 },
],
},
- StateVisuals: {
- ptrFn: 'getStateVisualsPtr',
- fields: [
- { name: 'transitionFlags', type: 'u32', offset: 0 },
- { name: 'fadeDuration', type: 'f32', offset: 4 },
- { name: 'slot0Color', type: 'color', offset: 8 },
- { name: 'slot0Sprite', type: 'u32', offset: 24 },
- { name: 'slot0Scale', type: 'f32', offset: 28 },
- { name: 'slot1Color', type: 'color', offset: 32 },
- { name: 'slot1Sprite', type: 'u32', offset: 48 },
- { name: 'slot1Scale', type: 'f32', offset: 52 },
- { name: 'slot2Color', type: 'color', offset: 56 },
- { name: 'slot2Sprite', type: 'u32', offset: 72 },
- { name: 'slot2Scale', type: 'f32', offset: 76 },
- { name: 'slot3Color', type: 'color', offset: 80 },
- { name: 'slot3Sprite', type: 'u32', offset: 96 },
- { name: 'slot3Scale', type: 'f32', offset: 100 },
- { name: 'slot4Color', type: 'color', offset: 104 },
- { name: 'slot4Sprite', type: 'u32', offset: 120 },
- { name: 'slot4Scale', type: 'f32', offset: 124 },
- { name: 'slot5Color', type: 'color', offset: 128 },
- { name: 'slot5Sprite', type: 'u32', offset: 144 },
- { name: 'slot5Scale', type: 'f32', offset: 148 },
- { name: 'slot6Color', type: 'color', offset: 152 },
- { name: 'slot6Sprite', type: 'u32', offset: 168 },
- { name: 'slot6Scale', type: 'f32', offset: 172 },
- { name: 'slot7Color', type: 'color', offset: 176 },
- { name: 'slot7Sprite', type: 'u32', offset: 192 },
- { name: 'slot7Scale', type: 'f32', offset: 196 },
- ],
- },
TilemapLayer: {
ptrFn: 'getTilemapLayerPtr',
fields: [
diff --git a/src/esengine/bindings/WebBindings.generated.cpp b/src/esengine/bindings/WebBindings.generated.cpp
index c43e3cb94..6ccfb24d2 100644
--- a/src/esengine/bindings/WebBindings.generated.cpp
+++ b/src/esengine/bindings/WebBindings.generated.cpp
@@ -1800,13 +1800,13 @@ EMSCRIPTEN_BINDINGS(esengine_reflection) {
// compiler layout matches. A failure here means the TS pointer accessors would
// read the wrong bytes -- fix the struct or regenerate EHT. DO NOT EDIT.
-static_assert(offsetof(esengine::ecs::BitmapText, color) == 0, "ABI offset drift: esengine::ecs::BitmapText.color (EHT expected 0)");
-static_assert(offsetof(esengine::ecs::BitmapText, fontSize) == 16, "ABI offset drift: esengine::ecs::BitmapText.fontSize (EHT expected 16)");
-static_assert(offsetof(esengine::ecs::BitmapText, align) == 20, "ABI offset drift: esengine::ecs::BitmapText.align (EHT expected 20)");
-static_assert(offsetof(esengine::ecs::BitmapText, spacing) == 24, "ABI offset drift: esengine::ecs::BitmapText.spacing (EHT expected 24)");
-static_assert(offsetof(esengine::ecs::BitmapText, layer) == 28, "ABI offset drift: esengine::ecs::BitmapText.layer (EHT expected 28)");
-static_assert(offsetof(esengine::ecs::BitmapText, font) == 32, "ABI offset drift: esengine::ecs::BitmapText.font (EHT expected 32)");
-static_assert(offsetof(esengine::ecs::BitmapText, enabled) == 36, "ABI offset drift: esengine::ecs::BitmapText.enabled (EHT expected 36)");
+static_assert(offsetof(esengine::ecs::BitmapText, color) == 12, "ABI offset drift: esengine::ecs::BitmapText.color (EHT expected 12)");
+static_assert(offsetof(esengine::ecs::BitmapText, fontSize) == 28, "ABI offset drift: esengine::ecs::BitmapText.fontSize (EHT expected 28)");
+static_assert(offsetof(esengine::ecs::BitmapText, align) == 32, "ABI offset drift: esengine::ecs::BitmapText.align (EHT expected 32)");
+static_assert(offsetof(esengine::ecs::BitmapText, spacing) == 36, "ABI offset drift: esengine::ecs::BitmapText.spacing (EHT expected 36)");
+static_assert(offsetof(esengine::ecs::BitmapText, layer) == 40, "ABI offset drift: esengine::ecs::BitmapText.layer (EHT expected 40)");
+static_assert(offsetof(esengine::ecs::BitmapText, font) == 44, "ABI offset drift: esengine::ecs::BitmapText.font (EHT expected 44)");
+static_assert(offsetof(esengine::ecs::BitmapText, enabled) == 48, "ABI offset drift: esengine::ecs::BitmapText.enabled (EHT expected 48)");
static_assert(offsetof(esengine::ecs::Camera, projectionType) == 0, "ABI offset drift: esengine::ecs::Camera.projectionType (EHT expected 0)");
static_assert(offsetof(esengine::ecs::Camera, fov) == 4, "ABI offset drift: esengine::ecs::Camera.fov (EHT expected 4)");
static_assert(offsetof(esengine::ecs::Camera, orthoSize) == 8, "ABI offset drift: esengine::ecs::Camera.orthoSize (EHT expected 8)");
@@ -1870,12 +1870,12 @@ static_assert(offsetof(esengine::ecs::FlexItem, flexShrink) == 4, "ABI offset dr
static_assert(offsetof(esengine::ecs::FlexItem, flexBasis) == 8, "ABI offset drift: esengine::ecs::FlexItem.flexBasis (EHT expected 8)");
static_assert(offsetof(esengine::ecs::FlexItem, order) == 12, "ABI offset drift: esengine::ecs::FlexItem.order (EHT expected 12)");
static_assert(offsetof(esengine::ecs::FlexItem, alignSelf) == 16, "ABI offset drift: esengine::ecs::FlexItem.alignSelf (EHT expected 16)");
-static_assert(offsetof(esengine::ecs::FlexItem, minWidth) == 20, "ABI offset drift: esengine::ecs::FlexItem.minWidth (EHT expected 20)");
-static_assert(offsetof(esengine::ecs::FlexItem, minHeight) == 24, "ABI offset drift: esengine::ecs::FlexItem.minHeight (EHT expected 24)");
-static_assert(offsetof(esengine::ecs::FlexItem, maxWidth) == 28, "ABI offset drift: esengine::ecs::FlexItem.maxWidth (EHT expected 28)");
-static_assert(offsetof(esengine::ecs::FlexItem, maxHeight) == 32, "ABI offset drift: esengine::ecs::FlexItem.maxHeight (EHT expected 32)");
-static_assert(offsetof(esengine::ecs::FlexItem, widthPercent) == 36, "ABI offset drift: esengine::ecs::FlexItem.widthPercent (EHT expected 36)");
-static_assert(offsetof(esengine::ecs::FlexItem, heightPercent) == 40, "ABI offset drift: esengine::ecs::FlexItem.heightPercent (EHT expected 40)");
+static_assert(offsetof(esengine::ecs::FlexItem, minWidth) == 36, "ABI offset drift: esengine::ecs::FlexItem.minWidth (EHT expected 36)");
+static_assert(offsetof(esengine::ecs::FlexItem, minHeight) == 40, "ABI offset drift: esengine::ecs::FlexItem.minHeight (EHT expected 40)");
+static_assert(offsetof(esengine::ecs::FlexItem, maxWidth) == 44, "ABI offset drift: esengine::ecs::FlexItem.maxWidth (EHT expected 44)");
+static_assert(offsetof(esengine::ecs::FlexItem, maxHeight) == 48, "ABI offset drift: esengine::ecs::FlexItem.maxHeight (EHT expected 48)");
+static_assert(offsetof(esengine::ecs::FlexItem, widthPercent) == 52, "ABI offset drift: esengine::ecs::FlexItem.widthPercent (EHT expected 52)");
+static_assert(offsetof(esengine::ecs::FlexItem, heightPercent) == 56, "ABI offset drift: esengine::ecs::FlexItem.heightPercent (EHT expected 56)");
static_assert(offsetof(esengine::ecs::GridLayout, direction) == 0, "ABI offset drift: esengine::ecs::GridLayout.direction (EHT expected 0)");
static_assert(offsetof(esengine::ecs::GridLayout, crossAxisCount) == 4, "ABI offset drift: esengine::ecs::GridLayout.crossAxisCount (EHT expected 4)");
static_assert(offsetof(esengine::ecs::GridLayout, itemSize) == 8, "ABI offset drift: esengine::ecs::GridLayout.itemSize (EHT expected 8)");
@@ -1937,16 +1937,16 @@ static_assert(offsetof(esengine::ecs::ShapeRenderer, size) == 20, "ABI offset dr
static_assert(offsetof(esengine::ecs::ShapeRenderer, cornerRadius) == 28, "ABI offset drift: esengine::ecs::ShapeRenderer.cornerRadius (EHT expected 28)");
static_assert(offsetof(esengine::ecs::ShapeRenderer, layer) == 32, "ABI offset drift: esengine::ecs::ShapeRenderer.layer (EHT expected 32)");
static_assert(offsetof(esengine::ecs::ShapeRenderer, enabled) == 36, "ABI offset drift: esengine::ecs::ShapeRenderer.enabled (EHT expected 36)");
-static_assert(offsetof(esengine::ecs::SpineAnimation, timeScale) == 0, "ABI offset drift: esengine::ecs::SpineAnimation.timeScale (EHT expected 0)");
-static_assert(offsetof(esengine::ecs::SpineAnimation, loop) == 4, "ABI offset drift: esengine::ecs::SpineAnimation.loop (EHT expected 4)");
-static_assert(offsetof(esengine::ecs::SpineAnimation, playing) == 5, "ABI offset drift: esengine::ecs::SpineAnimation.playing (EHT expected 5)");
-static_assert(offsetof(esengine::ecs::SpineAnimation, flipX) == 6, "ABI offset drift: esengine::ecs::SpineAnimation.flipX (EHT expected 6)");
-static_assert(offsetof(esengine::ecs::SpineAnimation, flipY) == 7, "ABI offset drift: esengine::ecs::SpineAnimation.flipY (EHT expected 7)");
-static_assert(offsetof(esengine::ecs::SpineAnimation, color) == 8, "ABI offset drift: esengine::ecs::SpineAnimation.color (EHT expected 8)");
-static_assert(offsetof(esengine::ecs::SpineAnimation, layer) == 24, "ABI offset drift: esengine::ecs::SpineAnimation.layer (EHT expected 24)");
-static_assert(offsetof(esengine::ecs::SpineAnimation, skeletonScale) == 28, "ABI offset drift: esengine::ecs::SpineAnimation.skeletonScale (EHT expected 28)");
-static_assert(offsetof(esengine::ecs::SpineAnimation, material) == 32, "ABI offset drift: esengine::ecs::SpineAnimation.material (EHT expected 32)");
-static_assert(offsetof(esengine::ecs::SpineAnimation, enabled) == 36, "ABI offset drift: esengine::ecs::SpineAnimation.enabled (EHT expected 36)");
+static_assert(offsetof(esengine::ecs::SpineAnimation, timeScale) == 48, "ABI offset drift: esengine::ecs::SpineAnimation.timeScale (EHT expected 48)");
+static_assert(offsetof(esengine::ecs::SpineAnimation, loop) == 52, "ABI offset drift: esengine::ecs::SpineAnimation.loop (EHT expected 52)");
+static_assert(offsetof(esengine::ecs::SpineAnimation, playing) == 53, "ABI offset drift: esengine::ecs::SpineAnimation.playing (EHT expected 53)");
+static_assert(offsetof(esengine::ecs::SpineAnimation, flipX) == 54, "ABI offset drift: esengine::ecs::SpineAnimation.flipX (EHT expected 54)");
+static_assert(offsetof(esengine::ecs::SpineAnimation, flipY) == 55, "ABI offset drift: esengine::ecs::SpineAnimation.flipY (EHT expected 55)");
+static_assert(offsetof(esengine::ecs::SpineAnimation, color) == 56, "ABI offset drift: esengine::ecs::SpineAnimation.color (EHT expected 56)");
+static_assert(offsetof(esengine::ecs::SpineAnimation, layer) == 72, "ABI offset drift: esengine::ecs::SpineAnimation.layer (EHT expected 72)");
+static_assert(offsetof(esengine::ecs::SpineAnimation, skeletonScale) == 76, "ABI offset drift: esengine::ecs::SpineAnimation.skeletonScale (EHT expected 76)");
+static_assert(offsetof(esengine::ecs::SpineAnimation, material) == 80, "ABI offset drift: esengine::ecs::SpineAnimation.material (EHT expected 80)");
+static_assert(offsetof(esengine::ecs::SpineAnimation, enabled) == 84, "ABI offset drift: esengine::ecs::SpineAnimation.enabled (EHT expected 84)");
static_assert(offsetof(esengine::ecs::Sprite, texture) == 0, "ABI offset drift: esengine::ecs::Sprite.texture (EHT expected 0)");
static_assert(offsetof(esengine::ecs::Sprite, color) == 4, "ABI offset drift: esengine::ecs::Sprite.color (EHT expected 4)");
static_assert(offsetof(esengine::ecs::Sprite, size) == 20, "ABI offset drift: esengine::ecs::Sprite.size (EHT expected 20)");
@@ -1960,32 +1960,6 @@ static_assert(offsetof(esengine::ecs::Sprite, tileSize) == 60, "ABI offset drift
static_assert(offsetof(esengine::ecs::Sprite, tileSpacing) == 68, "ABI offset drift: esengine::ecs::Sprite.tileSpacing (EHT expected 68)");
static_assert(offsetof(esengine::ecs::Sprite, material) == 76, "ABI offset drift: esengine::ecs::Sprite.material (EHT expected 76)");
static_assert(offsetof(esengine::ecs::Sprite, enabled) == 80, "ABI offset drift: esengine::ecs::Sprite.enabled (EHT expected 80)");
-static_assert(offsetof(esengine::ecs::StateVisuals, transitionFlags) == 0, "ABI offset drift: esengine::ecs::StateVisuals.transitionFlags (EHT expected 0)");
-static_assert(offsetof(esengine::ecs::StateVisuals, fadeDuration) == 4, "ABI offset drift: esengine::ecs::StateVisuals.fadeDuration (EHT expected 4)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot0Color) == 8, "ABI offset drift: esengine::ecs::StateVisuals.slot0Color (EHT expected 8)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot0Sprite) == 24, "ABI offset drift: esengine::ecs::StateVisuals.slot0Sprite (EHT expected 24)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot0Scale) == 28, "ABI offset drift: esengine::ecs::StateVisuals.slot0Scale (EHT expected 28)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot1Color) == 32, "ABI offset drift: esengine::ecs::StateVisuals.slot1Color (EHT expected 32)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot1Sprite) == 48, "ABI offset drift: esengine::ecs::StateVisuals.slot1Sprite (EHT expected 48)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot1Scale) == 52, "ABI offset drift: esengine::ecs::StateVisuals.slot1Scale (EHT expected 52)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot2Color) == 56, "ABI offset drift: esengine::ecs::StateVisuals.slot2Color (EHT expected 56)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot2Sprite) == 72, "ABI offset drift: esengine::ecs::StateVisuals.slot2Sprite (EHT expected 72)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot2Scale) == 76, "ABI offset drift: esengine::ecs::StateVisuals.slot2Scale (EHT expected 76)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot3Color) == 80, "ABI offset drift: esengine::ecs::StateVisuals.slot3Color (EHT expected 80)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot3Sprite) == 96, "ABI offset drift: esengine::ecs::StateVisuals.slot3Sprite (EHT expected 96)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot3Scale) == 100, "ABI offset drift: esengine::ecs::StateVisuals.slot3Scale (EHT expected 100)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot4Color) == 104, "ABI offset drift: esengine::ecs::StateVisuals.slot4Color (EHT expected 104)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot4Sprite) == 120, "ABI offset drift: esengine::ecs::StateVisuals.slot4Sprite (EHT expected 120)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot4Scale) == 124, "ABI offset drift: esengine::ecs::StateVisuals.slot4Scale (EHT expected 124)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot5Color) == 128, "ABI offset drift: esengine::ecs::StateVisuals.slot5Color (EHT expected 128)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot5Sprite) == 144, "ABI offset drift: esengine::ecs::StateVisuals.slot5Sprite (EHT expected 144)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot5Scale) == 148, "ABI offset drift: esengine::ecs::StateVisuals.slot5Scale (EHT expected 148)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot6Color) == 152, "ABI offset drift: esengine::ecs::StateVisuals.slot6Color (EHT expected 152)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot6Sprite) == 168, "ABI offset drift: esengine::ecs::StateVisuals.slot6Sprite (EHT expected 168)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot6Scale) == 172, "ABI offset drift: esengine::ecs::StateVisuals.slot6Scale (EHT expected 172)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot7Color) == 176, "ABI offset drift: esengine::ecs::StateVisuals.slot7Color (EHT expected 176)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot7Sprite) == 192, "ABI offset drift: esengine::ecs::StateVisuals.slot7Sprite (EHT expected 192)");
-static_assert(offsetof(esengine::ecs::StateVisuals, slot7Scale) == 196, "ABI offset drift: esengine::ecs::StateVisuals.slot7Scale (EHT expected 196)");
static_assert(offsetof(esengine::ecs::TilemapLayer, cellSize) == 0, "ABI offset drift: esengine::ecs::TilemapLayer.cellSize (EHT expected 0)");
static_assert(offsetof(esengine::ecs::TilemapLayer, originOffset) == 8, "ABI offset drift: esengine::ecs::TilemapLayer.originOffset (EHT expected 8)");
static_assert(offsetof(esengine::ecs::TilemapLayer, tileset) == 16, "ABI offset drift: esengine::ecs::TilemapLayer.tileset (EHT expected 16)");
@@ -2030,7 +2004,7 @@ static_assert(offsetof(esengine::ecs::Velocity, angular) == 12, "ABI offset drif
// ABI Hash -- runtime handshake against the SDK bundle
// =============================================================================
-static const char* kEsAbiLayoutHash = "f5d18743d00de675";
+static const char* kEsAbiLayoutHash = "579120e76e895e7c";
std::string esengineGetAbiLayoutHash() {
return std::string(kEsAbiLayoutHash);
diff --git a/tools/eht/generators/ptr_layout.py b/tools/eht/generators/ptr_layout.py
index 33250bcf6..585aa0406 100644
--- a/tools/eht/generators/ptr_layout.py
+++ b/tools/eht/generators/ptr_layout.py
@@ -45,24 +45,49 @@ class PtrLayoutGenerator:
self.layouts: List[Dict] = []
self._compute()
- def _get_size(self, cpp_type: str) -> Optional[int]:
+ # Sizes/alignments of space-occupying field types that are NOT exposed to
+ # JS via the pointer path but still occupy bytes in the struct, so the
+ # offset cursor must advance past them. Values are for the wasm32 target
+ # (emscripten libc++), verified against the compiler. A field whose space
+ # is not accounted for shifts every later field's offset — the exact bug
+ # the generated static_asserts in WebBindings.generated.cpp now catch.
+ NONPTR_SIZE_ALIGN = {
+ 'std::string': (12, 4),
+ 'glm::mat4': (64, 4),
+ }
+
+ ENUM_UNDERLYING_SIZE = {
+ 'u8': 1, 'i8': 1, 'bool': 1,
+ 'u16': 2, 'i16': 2,
+ 'u32': 4, 'i32': 4, 'int': 4, 'unsigned': 4,
+ 'u64': 8, 'i64': 8,
+ }
+
+ def _enum_size_align(self, t: str):
+ for e in self.types.enums:
+ if e.name == t or (e.namespace and f'{e.namespace}::{e.name}' == t):
+ sz = self.ENUM_UNDERLYING_SIZE.get(e.underlying_type, 4)
+ return (sz, sz)
+ return (1, 1)
+
+ def _field_size_align(self, cpp_type: str):
+ """Return (size, align) for ANY field type so the offset cursor can
+ advance past it, or None if the size is genuinely unknown."""
t = self.types.clean_type(cpp_type)
if t in self.TYPE_SIZES:
- return self.TYPE_SIZES[t]
+ return (self.TYPE_SIZES[t], self.TYPE_ALIGNS[t])
if self.types.is_handle(t):
- return 4
+ return (4, 4)
if self.types.is_enum(t):
- return 1
+ return self._enum_size_align(t)
+ if t in self.NONPTR_SIZE_ALIGN:
+ return self.NONPTR_SIZE_ALIGN[t]
+ if t.startswith('std::function'):
+ return (24, 8)
+ if t.startswith('std::vector') or t in self.types.VECTOR_TYPES:
+ return (12, 4)
return None
- def _get_align(self, cpp_type: str) -> int:
- t = self.types.clean_type(cpp_type)
- if t in self.TYPE_ALIGNS:
- return self.TYPE_ALIGNS[t]
- if self.types.is_handle(t) or self.types.is_enum(t):
- return 4 if self.types.is_handle(t) else 1
- return 4
-
def _get_ptr_type(self, cpp_type: str, prop: Property) -> Optional[str]:
t = self.types.clean_type(cpp_type)
if t in self.CPP_TO_PTR_TYPE:
@@ -76,26 +101,31 @@ class PtrLayoutGenerator:
return None
def _compute(self):
+ import sys
for comp in self.components:
fields = []
offset = 0
for prop in comp.properties:
- size = self._get_size(prop.cpp_type)
- if size is None:
- continue
- ptr_type = self._get_ptr_type(prop.cpp_type, prop)
- if ptr_type is None:
- continue
-
- align = self._get_align(prop.cpp_type)
+ sa = self._field_size_align(prop.cpp_type)
+ if sa is None:
+ # Unknown size — every later offset would be unreliable, so
+ # stop emitting accessors for this component rather than ship
+ # wrong offsets. (The static_asserts would catch it anyway.)
+ print(f" WARNING: {comp.name}.{prop.name}: cannot size type "
+ f"'{prop.cpp_type}' for pointer layout; truncating accessors",
+ file=sys.stderr)
+ break
+ size, align = sa
if offset % align != 0:
offset += align - (offset % align)
- fields.append({
- 'name': prop.name,
- 'type': ptr_type,
- 'offset': offset,
- })
+ ptr_type = self._get_ptr_type(prop.cpp_type, prop)
+ if ptr_type is not None:
+ fields.append({
+ 'name': prop.name,
+ 'type': ptr_type,
+ 'offset': offset,
+ })
offset += size
if fields: