Skip to content

Commit

Permalink
return size = 0 if no unsigned array
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Dec 31, 2023
1 parent df61916 commit ab2a663
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/buffer-views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,16 @@ function getSizeAndAlignmentOfUnsizedArrayElementOfTypeDef(typeDef: TypeDefiniti
const fields = asStructDef.fields;
if (fields) {
const lastField = Object.values(fields).pop()!;
return getSizeAndAlignmentOfUnsizedArrayElementOfTypeDef(lastField.type);
if (lastField.type.size === 0) {
return getSizeAndAlignmentOfUnsizedArrayElementOfTypeDef(lastField.type);
}
}

throw new Error('no unsigned array element');
return {
size: 0,
unalignedSize: 0,
align: 1,
};
}

/**
Expand Down Expand Up @@ -625,6 +631,7 @@ function getSizeAndAlignmentOfUnsizedArrayElementOfTypeDef(typeDef: TypeDefiniti
* ```
* @param varDef A variable definition provided by @link {makeShaderDataDefinitions}
* @returns the size, align, and unalignedSize in bytes of the unsized array element in this type definition.
* If there is no unsized array, size = 0.
*/
export function getSizeAndAlignmentOfUnsizedArrayElement(varDef: VariableDefinition | StructDefinition): {size: number, align: number} {
const asVarDef = varDef as VariableDefinition;
Expand Down

0 comments on commit ab2a663

Please sign in to comment.