Skip to content
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

1982: Negative Native Object Id Issue #2051

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public float getDuration() {

@Override
public void resetObject() {
this.id = -1;
setUpdateNeeded();
invalidate();
setUpdateNeeded();
}

@Override
Expand All @@ -57,11 +57,11 @@ public void setCurrentVolume(float currentVolume) {

@Override
public NativeObject createDestructableClone() {
return new AndroidAudioData(id);
return new AndroidAudioData(getId());
}

@Override
public long getUniqueId() {
return ((long)OBJTYPE_AUDIOBUFFER << 32) | ((long)id);
return ((long)OBJTYPE_AUDIOBUFFER << 32) | (getId());
}
}
8 changes: 4 additions & 4 deletions jme3-core/src/main/java/com/jme3/audio/AudioBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public float getDuration() {
@Override
public String toString() {
return getClass().getSimpleName()
+ "[id=" + id + ", ch=" + channels + ", bits=" + bitsPerSample
+ "[id=" + getId() + ", ch=" + channels + ", bits=" + bitsPerSample
+ ", rate=" + sampleRate + ", duration=" + getDuration() + "]";
}

Expand Down Expand Up @@ -109,7 +109,7 @@ public ByteBuffer getData() {

@Override
public void resetObject() {
id = -1;
invalidate();
setUpdateNeeded();
}

Expand All @@ -127,11 +127,11 @@ public void deleteObject(Object rendererObject) {

@Override
public NativeObject createDestructableClone() {
return new AudioBuffer(id);
return new AudioBuffer(getId());
}

@Override
public long getUniqueId() {
return ((long) OBJTYPE_AUDIOBUFFER << 32) | (0xffffffffL & (long) id);
return ((long) OBJTYPE_AUDIOBUFFER << 32) | (0xffffffffL & getId());
}
}
2 changes: 1 addition & 1 deletion jme3-core/src/main/java/com/jme3/audio/AudioData.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public int getSampleRate() {
* @param sampleRate Sample rate, 44100, 22050, etc.
*/
public void setupFormat(int channels, int bitsPerSample, int sampleRate) {
if (id != -1)
if (isValid())
throw new IllegalStateException("Already set up");

this.channels = channels;
Expand Down
7 changes: 3 additions & 4 deletions jme3-core/src/main/java/com/jme3/audio/AudioStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected AudioStream(int[] ids) {
}

public void updateData(InputStream in, float duration) {
if (id != -1 || this.in != null) {
if (isValid() || this.in != null) {
throw new IllegalStateException("Data already set!");
}

Expand Down Expand Up @@ -157,8 +157,7 @@ public DataType getDataType() {

@Override
public void resetObject() {
id = -1;
ids = null;
invalidate();
setUpdateNeeded();
}

Expand Down Expand Up @@ -222,6 +221,6 @@ public void setTime(float time) {

@Override
public long getUniqueId() {
return ((long) OBJTYPE_AUDIOSTREAM << 32) | (0xffffffffL & (long) ids[0]);
return ((long) OBJTYPE_AUDIOSTREAM << 32) | (0xffffffffL & ids[0]);
}
}
2 changes: 1 addition & 1 deletion jme3-core/src/main/java/com/jme3/audio/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void read(JmeImporter im) throws IOException {

@Override
public void resetObject() {
this.id = -1;
invalidate();
setUpdateNeeded();
}

Expand Down
4 changes: 2 additions & 2 deletions jme3-core/src/main/java/com/jme3/audio/LowPassFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ public void read(JmeImporter im) throws IOException {

@Override
public NativeObject createDestructableClone() {
return new LowPassFilter(id);
return new LowPassFilter(getId());
}

@Override
public long getUniqueId() {
return ((long) OBJTYPE_FILTER << 32) | (0xffffffffL & (long) id);
return ((long) OBJTYPE_FILTER << 32) | (0xffffffffL & getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public void cleanup() {

private void updateFilter(Filter f) {
int id = f.getId();
if (id == -1) {
if (f.isInvalid()) {
ib.position(0).limit(1);
efx.alGenFilters(1, ib);
id = ib.get(0);
Expand Down
10 changes: 5 additions & 5 deletions jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ public int convertShaderType(ShaderType type) {

public void updateShaderSourceData(ShaderSource source) {
int id = source.getId();
if (id == -1) {
if (source.isInvalid()) {
// Create id
id = gl.glCreateShader(convertShaderType(source.getType()));
if (id <= 0) {
Expand Down Expand Up @@ -1588,7 +1588,7 @@ public void updateShaderSourceData(ShaderSource source) {
public void updateShaderData(Shader shader) {
int id = shader.getId();
boolean needRegister = false;
if (id == -1) {
if (shader.isInvalid()) {
// create program
id = gl.glCreateProgram();
if (id == 0) {
Expand Down Expand Up @@ -1972,7 +1972,7 @@ public void updateFrameBuffer(FrameBuffer fb) {
}

int id = fb.getId();
if (id == -1) {
if (fb.isInvalid()) {
glfbo.glGenFramebuffersEXT(intBuf1);
id = intBuf1.get(0);
fb.setId(id);
Expand Down Expand Up @@ -2503,7 +2503,7 @@ private void bindTextureOnly(int target, Image img, int unit) {
*/
public void updateTexImageData(Image img, Texture.Type type, int unit, boolean scaleToPot) {
int texId = img.getId();
if (texId == -1) {
if (img.isInvalid()) {
// create texture
gl.glGenTextures(intBuf1);
texId = intBuf1.get(0);
Expand Down Expand Up @@ -2774,7 +2774,7 @@ private int convertFormat(Format format) {
public void updateBufferData(VertexBuffer vb) {
int bufId = vb.getId();
boolean created = false;
if (bufId == -1) {
if (vb.isInvalid()) {
// create buffer
gl.glGenBuffers(intBuf1);
bufId = intBuf1.get(0);
Expand Down
18 changes: 9 additions & 9 deletions jme3-core/src/main/java/com/jme3/scene/VertexBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ public int getBaseInstanceCount() {
* argument.
*/
public void setupData(Usage usage, int components, Format format, Buffer data) {
if (id != -1) {
if (isValid()) {
throw new UnsupportedOperationException("Data has already been sent. Cannot setupData again.");
}

Expand Down Expand Up @@ -690,7 +690,7 @@ public void setupData(Usage usage, int components, Format format, Buffer data) {
* @param data The data buffer to set
*/
public void updateData(Buffer data) {
if (id != -1) {
if (isValid()) {
// request to update data is okay
}

Expand Down Expand Up @@ -730,7 +730,7 @@ public void clearUpdateNeeded() {
* Converts single floating-point data to {@link Format#Half half} floating-point data.
*/
public void convertToHalf() {
if (id != -1) {
if (isValid()) {
throw new UnsupportedOperationException("Data has already been sent.");
}

Expand Down Expand Up @@ -1037,7 +1037,7 @@ public VertexBuffer clone() {
// e.g. re-use ID.
VertexBuffer vb = (VertexBuffer) super.clone();
vb.handleRef = new Object();
vb.id = -1;
vb.invalidate();
if (data != null) {
// Make sure to pass a read-only buffer to clone so that
// the position information doesn't get clobbered by another
Expand Down Expand Up @@ -1068,7 +1068,7 @@ public VertexBuffer clone(Type overrideType) {
vb.data = BufferUtils.clone(getDataReadOnly());
vb.format = format;
vb.handleRef = new Object();
vb.id = -1;
vb.invalidate();
vb.normalized = normalized;
vb.instanceSpan = instanceSpan;
vb.offset = offset;
Expand All @@ -1092,8 +1092,8 @@ public String toString() {

@Override
public void resetObject() {
// assert this.id != -1;
this.id = -1;
// assert isValid
invalidate();
setUpdateNeeded();
}

Expand All @@ -1111,12 +1111,12 @@ protected void deleteNativeBuffers() {

@Override
public NativeObject createDestructableClone() {
return new VertexBuffer(id);
return new VertexBuffer(getId());
}

@Override
public long getUniqueId() {
return ((long) OBJTYPE_VERTEXBUFFER << 32) | (0xffffffffL & (long) id);
return ((long) OBJTYPE_VERTEXBUFFER << 32) | (0xffffffffL & getId());
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions jme3-core/src/main/java/com/jme3/shader/BufferObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public int getBinding() {

@Override
public void resetObject() {
this.id = -1;
invalidate();
setUpdateNeeded();
}

Expand Down Expand Up @@ -829,6 +829,6 @@ protected void deleteNativeBuffers() {

@Override
public long getUniqueId() {
return ((long) OBJTYPE_BO << 32) | (0xffffffffL & (long) id);
return ((long) OBJTYPE_BO << 32) | (0xffffffffL & getId());
}
}
12 changes: 6 additions & 6 deletions jme3-core/src/main/java/com/jme3/shader/Shader.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public ShaderSource(ShaderType type) {
}

protected ShaderSource(ShaderSource ss) {
super(ss.id);
super(ss.getId());
// No data needs to be copied.
// (This is a destructible clone)
}
Expand Down Expand Up @@ -189,7 +189,7 @@ public String getDefines() {

@Override
public long getUniqueId() {
return ((long)OBJTYPE_SHADERSOURCE << 32) | (0xffffffffL & (long)id);
return ((long)OBJTYPE_SHADERSOURCE << 32) | (0xffffffffL & getId());
}

@Override
Expand All @@ -207,7 +207,7 @@ public String toString() {

@Override
public void resetObject() {
id = -1;
invalidate();
setUpdateNeeded();
}

Expand Down Expand Up @@ -241,7 +241,7 @@ public Shader() {
* @param s (not null)
*/
protected Shader(Shader s) {
super(s.id);
super(s.getId());

// Shader sources cannot be shared, therefore they must
// be destroyed together with the parent shader.
Expand Down Expand Up @@ -443,7 +443,7 @@ public void setUpdateNeeded(){
*/
@Override
public void resetObject() {
this.id = -1;
invalidate();
for (ShaderSource source : shaderSourceList){
source.resetObject();
}
Expand All @@ -462,6 +462,6 @@ public NativeObject createDestructableClone(){

@Override
public long getUniqueId() {
return ((long)OBJTYPE_SHADER << 32) | (0xffffffffL & (long)id);
return ((long)OBJTYPE_SHADER << 32) | (0xffffffffL & getId());
}
}
Loading