Skip to content

Commit 93625b1

Browse files
committed
fix EcsRest struct size mismatch
1 parent b6d10b1 commit 93625b1

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.github.elebras1.flecs.examples;
2+
3+
import com.github.elebras1.flecs.Flecs;
4+
5+
public class RestLifecycleExample {
6+
7+
public static void main(String[] args) throws InterruptedException {
8+
try (Flecs world = new Flecs()) {
9+
System.out.println("=== Flecs REST Lifecycle Test ===");
10+
11+
for(int i = 0; i < 50; i++) {
12+
System.out.println("[" + i + "] Enabling REST...");
13+
world.enableRest();
14+
world.progress(0.016f);
15+
Thread.sleep(100);
16+
System.out.println(" -> REST should be active.");
17+
System.out.println("[" + i + "] Disabling REST...");
18+
world.disableRest();
19+
20+
world.progress(0.016f);
21+
Thread.sleep(100);
22+
System.out.println(" -> REST should be inactive.");
23+
}
24+
}
25+
}
26+
}

src/main/java/com/github/elebras1/flecs/Flecs.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,10 @@ public void fromJson(String json) {
725725
}
726726
}
727727

728+
public void enableRest() {
729+
this.enableRest((short) 27750);
730+
}
731+
728732
public void enableRest(short port) {
729733
this.checkClosed();
730734

@@ -739,13 +743,14 @@ public void enableRest(short port) {
739743
long restCompId = flecs_h.ecs_lookup(this.nativeWorld, restCompName);
740744

741745
if (restCompId == 0) {
742-
throw new IllegalStateException("Failed to find flecs.rest.Rest component. Make sure FlecsRest module is imported.");
746+
throw new IllegalStateException("Failed to find flecs.rest.Rest component.");
743747
}
744748

745-
MemorySegment restData = arena.allocate(2);
749+
MemorySegment restData = arena.allocate(32);
750+
restData.fill((byte) 0);
746751
restData.set(ValueLayout.JAVA_SHORT, 0, port);
747752

748-
flecs_h.ecs_set_id(this.nativeWorld, restCompId, restCompId, 2, restData);
753+
flecs_h.ecs_set_id(this.nativeWorld, restCompId, restCompId, 32, restData);
749754
}
750755
}
751756

0 commit comments

Comments
 (0)