Commit 31050a5a authored by IjzerenHein's avatar IjzerenHein

Made RNGLContext.java thread-safe (fixes rare exception when a shader is used...

Made RNGLContext.java thread-safe (fixes rare exception when a shader is used in multiple surfaces at the same time)

+ can potentionally explain/fix other witnessed crashes
parent bcc1b1f7
...@@ -38,29 +38,43 @@ public class RNGLContext extends ReactContextBaseJavaModule { ...@@ -38,29 +38,43 @@ public class RNGLContext extends ReactContextBaseJavaModule {
} }
public GLShaderData getShader (Integer id) { public GLShaderData getShader (Integer id) {
return shaders.get(id); GLShaderData data;
synchronized (this) {
data = shaders.get(id);
}
return data;
} }
@ReactMethod @ReactMethod
public void addShader (final Integer id, final ReadableMap config, final Callback onCompile) { public void addShader (final Integer id, final ReadableMap config, final Callback onCompile) {
final String frag = config.getString("frag"); final String frag = config.getString("frag");
final String name = config.getString("name"); final String name = config.getString("name");
shaders.put(id, new GLShaderData(name, STATIC_VERT, frag)); GLShaderData data = new GLShaderData(name, STATIC_VERT, frag);
synchronized (this) {
shaders.put(id, data);
if (onCompile != null) { if (onCompile != null) {
onCompileCallbacks.put(id, onCompile); onCompileCallbacks.put(id, onCompile);
} }
} }
}
@ReactMethod @ReactMethod
public void removeShader (final Integer id) { public void removeShader (final Integer id) {
GLShaderData shader = shaders.remove(id); GLShaderData shader;
synchronized (this) {
shader = shaders.remove(id);
}
if (shader == null) { if (shader == null) {
throw new Error("removeShader("+id+"): shader does not exist"); throw new Error("removeShader("+id+"): shader does not exist");
} }
} }
public void shaderFailedToCompile(Integer id, GLShaderCompilationFailed e) { public void shaderFailedToCompile(Integer id, GLShaderCompilationFailed e) {
Callback onCompile = onCompileCallbacks.get(id); Callback onCompile;
synchronized (this) {
onCompile = onCompileCallbacks.get(id);
onCompileCallbacks.remove(id);
}
if (onCompile == null) { if (onCompile == null) {
Log.e("RNGLContext", e.getMessage()); Log.e("RNGLContext", e.getMessage());
} }
...@@ -70,8 +84,11 @@ public class RNGLContext extends ReactContextBaseJavaModule { ...@@ -70,8 +84,11 @@ public class RNGLContext extends ReactContextBaseJavaModule {
} }
public void shaderSucceedToCompile(Integer id, Map<String, Integer> uniformTypes) { public void shaderSucceedToCompile(Integer id, Map<String, Integer> uniformTypes) {
Callback onCompile = onCompileCallbacks.get(id); Callback onCompile;
synchronized (this) {
onCompile = onCompileCallbacks.get(id);
onCompileCallbacks.remove(id); onCompileCallbacks.remove(id);
}
if (onCompile != null) { if (onCompile != null) {
WritableMap res = Arguments.createMap(); WritableMap res = Arguments.createMap();
WritableMap uniforms = Arguments.createMap(); WritableMap uniforms = Arguments.createMap();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment