New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializing all.smft to binary fails #24

Closed
io7m opened this Issue Dec 29, 2016 · 4 comments

Comments

Projects
None yet
1 participant
@io7m
Owner

io7m commented Dec 29, 2016

smf: SMFBV1Serializer: TRACE: padding required: 16 octets
smf: Main: ERROR: Invariant violation.
  Received: 16
  Violated conditions: 
    [0]: Difference 16 must be <= 8

com.io7m.jaffirm.core.InvariantViolationException: Invariant violation.
  Received: 16
  Violated conditions: 
    [0]: Difference 16 must be <= 8

	at com.io7m.jaffirm.core.Invariants.invariantsFailed(Invariants.java:767)
	at com.io7m.jaffirm.core.Invariants.checkInvariantL(Invariants.java:431)
	at com.io7m.smfj.format.binary.SMFBV1Serializer.insertAlignmentPadding(SMFBV1Serializer.java:338)
	at com.io7m.smfj.format.binary.SMFBV1Serializer.serializeDataInsertAlignmentPadding(SMFBV1Serializer.java:317)
	at com.io7m.smfj.format.binary.SMFBV1Serializer.serializeData(SMFBV1Serializer.java:288)
	at com.io7m.smfj.processing.SMFMemoryMeshSerializer.serialize(SMFMemoryMeshSerializer.java:70)
	at com.io7m.smfj.cmdline.Main$CommandFilter.call(Main.java:357)
	at com.io7m.smfj.cmdline.Main$CommandFilter.call(Main.java:256)
	at com.io7m.smfj.cmdline.Main.run(Main.java:136)
	at com.io7m.smfj.cmdline.Main.main(Main.java:108)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
	Suppressed: java.lang.IllegalStateException: Closed a serializer with 18 attributes remaining
		at com.io7m.smfj.format.binary.SMFBV1Serializer.close(SMFBV1Serializer.java:1009)
		at com.io7m.smfj.cmdline.Main$CommandFilter.call(Main.java:358)
		... 8 common frames omitted

@io7m io7m added the bug label Dec 29, 2016

@io7m io7m added this to the 0.4.0 milestone Dec 29, 2016

@io7m io7m self-assigned this Dec 29, 2016

@io7m

This comment has been minimized.

Show comment
Hide comment
@io7m

io7m Dec 29, 2016

Owner

The problem appears to be the i8_3 attribute (three 8-bit values):

smf: SMFBV1Offsets: TRACE: OFFSET_HEADER:                             0x10
smf: SMFBV1Offsets: TRACE: OFFSET_HEADER_ATTRIBUTES_DATA:             0x48
smf: SMFBV1Offsets: DEBUG: vertex data offset: 152
smf: SMFBV1Offsets: TRACE: align 9 -> 16
smf: SMFBV1Offsets: DEBUG: attribute i8_3             start 152      exclusive-upper 169      size-unpadded 9        size-final 16      
smf: SMFBV1Offsets: DEBUG: triangles offset: 168
smf: SMFBV1Offsets: TRACE: align 171 -> 176
smf: SMFBV1Offsets: DEBUG: meta data offset: 176
smf: SMFBV1Serializer: DEBUG: serializing data for i8_3
smf: SMFBV1Serializer: TRACE: padding required: 0 octets
smf: Main: ERROR: Invariant violation.
  Received: 152
  Violated conditions: 
    [0]: Writer must be at correct offset for first triangle

com.io7m.jaffirm.core.InvariantViolationException: Invariant violation.
  Received: 152
  Violated conditions: 
    [0]: Writer must be at correct offset for first triangle

	at com.io7m.jaffirm.core.Invariants.invariantsFailed(Invariants.java:767)
	at com.io7m.jaffirm.core.Invariants.checkInvariantL(Invariants.java:431)
	at com.io7m.smfj.format.binary.SMFBV1Serializer.serializeTriangleWrite(SMFBV1Serializer.java:947)
	at com.io7m.smfj.format.binary.SMFBV1Serializer.serializeTriangle(SMFBV1Serializer.java:867)
	at com.io7m.smfj.processing.SMFMemoryMeshSerializer.serialize(SMFMemoryMeshSerializer.java:89)
	at com.io7m.smfj.cmdline.Main$CommandFilter.call(Main.java:357)
	at com.io7m.smfj.cmdline.Main$CommandFilter.call(Main.java:256)
	at com.io7m.smfj.cmdline.Main.run(Main.java:136)
	at com.io7m.smfj.cmdline.Main.main(Main.java:108)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
	Suppressed: java.lang.IllegalStateException: Closed a serializer with 1 triangles remaining
		at com.io7m.smfj.format.binary.SMFBV1Serializer.close(SMFBV1Serializer.java:1015)
		at com.io7m.smfj.cmdline.Main$CommandFilter.call(Main.java:358)
		... 8 common frames omitted
Owner

io7m commented Dec 29, 2016

The problem appears to be the i8_3 attribute (three 8-bit values):

smf: SMFBV1Offsets: TRACE: OFFSET_HEADER:                             0x10
smf: SMFBV1Offsets: TRACE: OFFSET_HEADER_ATTRIBUTES_DATA:             0x48
smf: SMFBV1Offsets: DEBUG: vertex data offset: 152
smf: SMFBV1Offsets: TRACE: align 9 -> 16
smf: SMFBV1Offsets: DEBUG: attribute i8_3             start 152      exclusive-upper 169      size-unpadded 9        size-final 16      
smf: SMFBV1Offsets: DEBUG: triangles offset: 168
smf: SMFBV1Offsets: TRACE: align 171 -> 176
smf: SMFBV1Offsets: DEBUG: meta data offset: 176
smf: SMFBV1Serializer: DEBUG: serializing data for i8_3
smf: SMFBV1Serializer: TRACE: padding required: 0 octets
smf: Main: ERROR: Invariant violation.
  Received: 152
  Violated conditions: 
    [0]: Writer must be at correct offset for first triangle

com.io7m.jaffirm.core.InvariantViolationException: Invariant violation.
  Received: 152
  Violated conditions: 
    [0]: Writer must be at correct offset for first triangle

	at com.io7m.jaffirm.core.Invariants.invariantsFailed(Invariants.java:767)
	at com.io7m.jaffirm.core.Invariants.checkInvariantL(Invariants.java:431)
	at com.io7m.smfj.format.binary.SMFBV1Serializer.serializeTriangleWrite(SMFBV1Serializer.java:947)
	at com.io7m.smfj.format.binary.SMFBV1Serializer.serializeTriangle(SMFBV1Serializer.java:867)
	at com.io7m.smfj.processing.SMFMemoryMeshSerializer.serialize(SMFMemoryMeshSerializer.java:89)
	at com.io7m.smfj.cmdline.Main$CommandFilter.call(Main.java:357)
	at com.io7m.smfj.cmdline.Main$CommandFilter.call(Main.java:256)
	at com.io7m.smfj.cmdline.Main.run(Main.java:136)
	at com.io7m.smfj.cmdline.Main.main(Main.java:108)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
	Suppressed: java.lang.IllegalStateException: Closed a serializer with 1 triangles remaining
		at com.io7m.smfj.format.binary.SMFBV1Serializer.close(SMFBV1Serializer.java:1015)
		at com.io7m.smfj.cmdline.Main$CommandFilter.call(Main.java:358)
		... 8 common frames omitted
@io7m

This comment has been minimized.

Show comment
Hide comment
@io7m

io7m Dec 29, 2016

Owner

This is a fantastic bug that comes from me ignoring the static analysis that told me that switch statements did not have default branches.

    switch (this.attribute_current.componentSizeBits()) {
        case 16: {
          this.writer.putS16(x);
          break;
        }
        case 32: {
          this.writer.putS32(x);
          break;
        }
        case 64: {
          this.writer.putS64(x);
          break;
        }
      }

Note the lack of a branch for 8: 8-bit data is simply never written.

Owner

io7m commented Dec 29, 2016

This is a fantastic bug that comes from me ignoring the static analysis that told me that switch statements did not have default branches.

    switch (this.attribute_current.componentSizeBits()) {
        case 16: {
          this.writer.putS16(x);
          break;
        }
        case 32: {
          this.writer.putS32(x);
          break;
        }
        case 64: {
          this.writer.putS64(x);
          break;
        }
      }

Note the lack of a branch for 8: 8-bit data is simply never written.

@io7m

This comment has been minimized.

Show comment
Hide comment
@io7m

io7m Dec 29, 2016

Owner

Intellij has a new setting that allows for turning the above code into an error without requiring default branches for enumerated types. Enabled!

Owner

io7m commented Dec 29, 2016

Intellij has a new setting that allows for turning the above code into an error without requiring default branches for enumerated types. Enabled!

@io7m

This comment has been minimized.

Show comment
Hide comment
@io7m

io7m Dec 29, 2016

Owner

Additionally, none of the tests caught this.

A simple round-trip test should be added: Parse all.smft as an in-memory mesh, serialize it to binary, read the binary into an in-memory mesh, and compare the final result with the original mesh.

Owner

io7m commented Dec 29, 2016

Additionally, none of the tests caught this.

A simple round-trip test should be added: Parse all.smft as an in-memory mesh, serialize it to binary, read the binary into an in-memory mesh, and compare the final result with the original mesh.

@io7m io7m closed this in f3f7578 Dec 29, 2016

io7m added a commit that referenced this issue Dec 29, 2016

Merge branch 'release/0.4.0'
Release: io7m-smfj 0.4.0
Code new: Add schema-set and schema-check commands. (tickets: #19)
Code new: Add trim command. (tickets: #21)
Code change: Update the random access parser API to deliver metadata. (tickets: #23)
Code new: Add an adapter that can deliver parser events from an SMFMemoryMesh. (tickets: #18)
Code change: Add an optional exception to parse and processing errors. (tickets: #22)
Code fix: Fix a major issue with 8-bit data not being serialized. (tickets: #24)
Code change: Make the SMFMetadata vendor/schema fields into long values to ease the use of them as unsigned 32 bit values.

io7m added a commit that referenced this issue Dec 29, 2016

Merge tag 'io7m-smf-0.4.0' into develop
Release: io7m-smfj 0.4.0

Code new: Add schema-set and schema-check commands. (tickets: #19)
Code new: Add trim command. (tickets: #21)
Code change: Update the random access parser API to deliver metadata. (tickets: #23)
Code new: Add an adapter that can deliver parser events from an SMFMemoryMesh. (tickets: #18)
Code change: Add an optional exception to parse and processing errors. (tickets: #22)
Code fix: Fix a major issue with 8-bit data not being serialized. (tickets: #24)
Code change: Make the SMFMetadata vendor/schema fields into long values to ease the use of them as unsigned 32 bit values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment