Closed endison1986 closed 1 year ago
In my actual project, I create monster entities in a System. In order to take advantage of multi-core, I use parallelStream and create monster entities in it, and cache the Entity to Component, but I found that in the next System, the Entity in the Component obtained by the context.findEntitiesWith()
method is different from the hashCode of ResultSet.entity()
example code like this.
public enum State {
S1, S2, S3;
}
public static class C {
private final Entity entity;
public C(Entity entity) {
this.entity = entity;
}
}
public static class B {
}
public static class A {
private C c;
public A(Dominion dominion) {
c = new C(dominion.createEntity(this));
c.entity.setState(S1);
}
}
public static void main(String[] args) {
final Dominion dominion = Dominion.create();
final var list = List.<Runnable>of(() -> {
for (int i = 0; i < 200; i++) {
final var a = new A(dominion);
a.c.entity.add(new B());
}
}, () -> {
for (int i = 0; i < 200; i++) {
final var a = new A(dominion);
a.c.entity.add(new B());
}
}, () -> {
for (int i = 0; i < 200; i++) {
final var a = new A(dominion);
a.c.entity.add(new B());
}
});
final var scheduler = dominion.createScheduler();
scheduler.schedule(() -> list.parallelStream().forEach(Runnable::run));
scheduler.schedule(() -> {
dominion.findEntitiesWith(A.class).stream().forEach(rs->{
if(rs.entity().hashCode() != rs.comp().c.entity.hashCode()) {
System.out.println("1111111111111111111");
System.exit(-1);
}
});
System.exit(0);
});
scheduler.tickAtFixedRate(10);
}
If I remove a.c.entity.add(new B());
, the program is fine.
If I change paralleStream()
to stream()
, this program is fine.
Hi @endison1986 , the last message seems to be a different problem, could you please open a different issue and move the message into the new issue? thanks
Ok, I've moved the problem to a new issue @enricostara I am very happy to hear from you. I analyzed it all morning and couldn't find the cause of the problem. But there is some progress, I will add information in the new issue.
Hi @endison1986, the fix has been merged as EA and is available by using the last 0.9.0-SNAPSHOT, let me know if it works as expected
Thanks, @enricostara This problem has been fixed in the test code, and I tested in my actual project, no errors reported. But this problem was discovered when I reproduced #156, not in my actual project.
Thanks @endison1986 , issue #165 is completely different and not even related to this one. Then I'm closing this as it is already covered by new tests
this code is fine.
this code is also fine.
but I get some error with this code
and this code