Skip to content

Commit

Permalink
Core Editor: Fix objects with unknown types not showing
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadelessFox committed Aug 4, 2024
1 parent 7eb8fb6 commit fdcccca
Showing 1 changed file with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public record Reader(@NotNull RTTITypeRegistry registry) implements RTTICoreFile

@NotNull
@Override
public RTTICoreFile read(@NotNull InputStream is, @NotNull ErrorHandlingStrategy errorHandlingStrategy) throws IOException {
public RTTICoreFile read(@NotNull InputStream is, @NotNull ErrorHandlingStrategy handler) throws IOException {
final List<RTTIObject> objects = new ArrayList<>();

final ByteBuffer header = ByteBuffer
Expand All @@ -47,31 +47,29 @@ public RTTICoreFile read(@NotNull InputStream is, @NotNull ErrorHandlingStrategy
final ByteBuffer data;

if (read != header.limit()) {
errorHandlingStrategy.handle(new IOException("Unexpected end of stream while reading object header"));
handler.handle(new IOException("Unexpected end of stream while reading object header"));
continue;
}

hash = header.getLong(0);
data = ByteBuffer.allocate(header.getInt(8)).order(ByteOrder.LITTLE_ENDIAN);

if (is.read(data.array()) != data.capacity()) {
errorHandlingStrategy.handle(new IOException("Unexpected end of stream while reading object data"));
continue;
}

final RTTIClass type = registry.find(hash);

if (type == null) {
errorHandlingStrategy.handle(new IllegalArgumentException("Can't find type with hash %018x in the registry".formatted(hash)));
handler.handle(new IOException("Unexpected end of stream while reading object data"));
continue;
}

RTTIClass type = registry.find(hash);
RTTIObject object = null;

try {
object = type.read(registry, data);
} catch (Exception e) {
errorHandlingStrategy.handle(new IllegalArgumentException("Failed to construct object of type " + type, e));
if (type != null) {
try {
object = type.read(registry, data);
} catch (Exception e) {
handler.handle(new IllegalArgumentException("Failed to construct object of type " + type, e));
}
} else {
handler.handle(new IllegalArgumentException("Can't find type with hash %018x in the registry".formatted(hash)));
}

if (object == null || data.remaining() > 0) {
Expand Down

0 comments on commit fdcccca

Please sign in to comment.