Comments (3)
About this issue, I analysis source code, and found that the problem might be here.
dev.dominion.ecs.engine.system.ClassIndex.java
public IndexKey getIndexKey(Object[] objects) {
int length = objects.length;
boolean[] checkArray = new boolean[index + length + 1];
int min = Integer.MAX_VALUE, max = 0;
for (int i = 0; i < length; i++) {
int value = getIndex(objects[i].getClass());
value = value == 0 ? getIndexOrAddClass(objects[i].getClass()) : value;
if (checkArray[value]) {
throw new IllegalArgumentException("Duplicate object types are not allowed");
}
checkArray[value] = true;
min = Math.min(value, min);
max = Math.max(value, max);
}
return new IndexKey(checkArray, min, max, length);
}
under lines has concurrency problem.
int value = getIndex(objects[i].getClass());
value = value == 0 ? getIndexOrAddClass(objects[i].getClass()) : value;
If I createEntity in multiple threads, getIndex
method will be called by multiple thread with result in zero. Also the getIndexOrAddClass
method will be called multiple times. So I add a synchronized block to fix this issue temporary, Hope you have better way.
private final Object lock = new Object();
@SuppressWarnings("ForLoopReplaceableByForEach")
public IndexKey getIndexKey(Object[] objects) {
int length = objects.length;
boolean[] checkArray = new boolean[index + length + 1];
int min = Integer.MAX_VALUE, max = 0;
for (int i = 0; i < length; i++) {
var componentClass = objects[i].getClass();
var value = getIndex(componentClass);
if (value == 0) {
synchronized (lock) {
value = getIndex(componentClass);
if (value == 0) {
value = getIndexOrAddClass(componentClass);
}
}
}
if (checkArray[value]) {
throw new IllegalArgumentException("Duplicate object types are not allowed");
}
checkArray[value] = true;
min = Math.min(value, min);
max = Math.max(value, max);
}
return new IndexKey(checkArray, min, max, length);
}
from dominion-ecs-java.
Thanks for reporting, I'll look into this issue after I fix issue #117 (still in progress)
from dominion-ecs-java.
Hi @endison1986, issue fixed by #122
from dominion-ecs-java.
Related Issues (20)
- how to get component from entity HOT 2
- about thread safe HOT 14
- NullPointerException and ArrayIndexOutOfBoundsException HOT 7
- Cannot found entity after some and/remove operation HOT 6
- I pull a request, but Iām not sure which branch should be megin into
- withState() doesn't seem to be working HOT 3
- Add Ability to Retrieve All Entities HOT 4
- When I created entities in parallel, some errors occurred HOT 6
- When I create entities and add components in multiple threads, there are unforeseen concurrency issues HOT 8
- Question: What's the best way to save the world state and restore it? HOT 4
- Bug with Inheritance HOT 4
- Support for optional, not, relationships etc HOT 4
- Are there any logical loopholes in ClassIndex? HOT 15
- I have another question about IndexKey
- Test Failures
- A concurrency issue HOT 5
- A question about Item HOT 2
- Thread-safe for IntStack HOT 4
- java.lang.ClassCastException HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dominion-ecs-java.