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
java.lang.ClassCastException with CGBitmapContext #837
Comments
I can not reproduce the issue, using this sample:
Calling
Which is what we'd expect. Which version of PlayN are you using? Does it depend on the latest RoboVM snapshot? |
I used the version compatible with the RoboVM API of snapshot 20150309 which can be found at https://github.com/tomfisher/playn, and the following code:
It worked fine with alpha-02 if the memory serves me right. |
Badlogic, We're blocked to release the iOS product because of this. I want to know whether you have any plan of working on this issue so that we can reschedule our works. Thanks. |
Sorry, we were super busy with 1.0. I'll try to fix this until monday. |
Would it be possible for you to send an example project that's properly setup? That's help me focus on the issue instead of trying to figure out how to setup PlayN :) |
Sure, give me a moment. |
I updated to the 1.0.0 version and the bug just happened sometimes such as a build without any cache may work but it came out sometimes even with a clean build. Please just ignore this at the moment and keep if open for a while. I'll do more test and let you know the result. |
Sounds good. We'll definitely not close this heisenbug :)
|
I found an interesting problem that the bug may be generated during the compiling or linking process. The code https://github.com/tomfisher/issue837/blob/master/src/org/robovm/cases/issue837/Main.java includes a private method that is never used in the application and contains the application logics and views based on PlayN. If that method is removed out from the code, the Do you guys have any thought about this? BTW, I'm still working on this to narrow down the problem, which is really tedious :-( |
Sorry, clicked on the wrong button. |
More strange things happened. I put a line code
According to the exception, it should be caused by some classes relevant to CGBitmapContext or CGContext such as UIWebView. However, removing the reference to RoboFile will eliminate the cast exception although RoboFile just refers to a few foundation classes:
The more strange thing is that removing the instance 'result' of the interface ResultBuilder also eliminates the cast exception, as well as the instance 'creator'. As usual, the cast exception disappears when removing some classes and then appears again when removing other classes regardless of whether they are relevant to CGContext or even called when running. I'll carry on isolating the problem from the complicated project and hope the above info could be enough for you to tackle the problem :) |
Could you please try to force link the necessary classes like CGBitmapContext in your robovm.xml? |
I did and failed as usual. |
I have test run your code in the simulator (32-bit iPad2 iOS 8.1) but it seems to be working just fine here. Is there something else I need to do to make it crash? You were talking about adding/removing methods? Is the code in https://github.com/tomfisher/issue837 the code that fails for you? Are you running on device or in the simulator? Which iOS version and (simulated) device? |
Sorry, the current code just demonstrates the brief scenario. I am working on the local project and trying to remove unrelated code in order to submit a project that focuses on the problem. But the problem is any code removal magically eliminates the exception sometime and does not sometime without any observable pattern. For the moment, we could guess it's a compile or linking problem. I would like share the project that still contains a a few code after days of removal if you don't mind. |
The full source code is uploaded to https://github.com/tomfisher/issue837. It fails on all simulators and devices, as well as on all iOS sdks. See code and comments in method |
Is there someone working on this? Don't know whether you guys can reproduce the bug with the above code. |
Sorry, we are currently juggling a lot of balls, so things take a while. I just tried your sample project using RoboVM 1.0.0, compiling via Eclipse (i added Next i tried running it via Maven ( This was with an empty cache. I recompiled and deployed to sim a couple more times via Maven, i never got an error. I'm afraid as long as we can't reproduce it on our end, we can't do much :/ |
Did you click the red area? |
I cleaned everything including mvn repo, robovm cache and eclipse cache and got the error in console. I do hope you forgot clicking the red area :-) |
Of course I did not click the red area :( I'll check it tomorrow but can't make any promises on a fixe eta.
|
Without doing anything, i now get this exception on startup: java.lang.NullPointerException
at playn.robovm.RoboCanvas.data(RoboCanvas.java:82)
at playn.robovm.RoboCanvasImage.updateTexture(RoboCanvasImage.java:78)
at playn.core.gl.ImageGL.createMainTex(ImageGL.java:79)
at playn.core.gl.ImageGL.ensureTexture(ImageGL.java:43)
at playn.robovm.RoboCanvasImage.ensureTexture(RoboCanvasImage.java:67)
at playn.core.gl.AbstractImageGL.draw(AbstractImageGL.java:79)
at playn.core.gl.AbstractImageGL.draw(AbstractImageGL.java:69)
at playn.core.gl.ImageLayerGL.paint(ImageLayerGL.java:95)
at playn.core.gl.GroupLayerGL.render(GroupLayerGL.java:184)
at playn.core.gl.GroupLayerGL.paint(GroupLayerGL.java:177)
at playn.core.gl.GL20Context.paint(GL20Context.java:70)
at playn.robovm.RoboGraphics.paint(RoboGraphics.java:166)
at playn.robovm.RoboPlatform.paint(RoboPlatform.java:277)
at playn.robovm.RoboViewController$1.draw(RoboViewController.java:73)
at org.robovm.apple.uikit.UIView.$cb$drawRect$(UIView.java)
at org.robovm.apple.uikit.UIApplication.main(Native Method)
at org.robovm.apple.uikit.UIApplication.main(UIApplication.java:362)
at org.robovm.issue837.Main.main(Main.java:79) Will continue investigating, but it may take a bit. |
So strange. ClassCastException happens constantly just when clicking the area in my environment, rather than NPE on startup. |
Hi, guys: Are you still working on this issue? Is there anything that I can help ? |
No one's working on it ATM but we'll keep it open. I know I tried your repo to try to reproduce it but I couldn't get it to crash here. @badlogic also tried but never got the same exception. So I think we're a bit out of ideas at the moment. You have tried all SDKs with the simulator and also on device, right? Which iOS version do you have on your device? What kind of device? Did you try with the latest Xcode 6.3? |
Ok, I'll give a try with the latest Xcode and let you know whether this exists. |
It worked just once with the latest Xcode and SDK. After recompiling another project involved with CGBitmapContext, then every project just failed as before. Is is possible related with the compiling cache? I did remove ~/.robovm and workspace/.metadata/org.robovm.xx folders for the first compile and consequent compiles. Don't know why the first magically worked. |
My guess is that PlayN and your project (and/or another project you depend
|
I did clean everything and even try the RoboVM 1.1.0 using the case, and still got the error. Are you guys sure the error cannot be reproduced in your environment? The error will be shown just when clicking in the red square in the demo rather than during the compiling and linking process. I am using: uname -a
xcodebuild -showsdks
clang --version
mvn dependency:resolve
Is there any mismatching with what you use or anything else that I should check? |
FWIW: I also just checked out the project, and ran
My relevant infos:
The last time I saw this was circa issue 728, but when I bumped to the release where that was CNR, the problem also went away for me. But as we're now discovering, that was probably a red herring. Something wiggled around and the bug wasn't being triggered, but it doesn't seem to have gone away. I would also be happy to poke at things if there is more useful info we can provide. |
Guys, Have you reproduced the error? I'll be really appreciated if you have any plan on this issue. |
A stacktrace with linenumbers would help. I assume it's around this line in I had a theory back in #728 about our static CFType toObject(Class<? extends CFType> cls, long handle, long flags, boolean retain) {
if (handle == 0) {
return null;
}
long typeId = getTypeID(handle);
Class<? extends CFType> cfTypeClass = allCFTypeClasses.get(typeId);
if (cfTypeClass != null) {
cls = cfTypeClass;
}
CFType o = (CFType) NativeObject.Marshaler.toObject(cls, handle, flags);
if (retain) {
retain(handle);
}
return o;
} I can see how this can fail when passing in What I don't understand is why this code works for some of us. It should fail always! Wait, could be due to the code that populates static {
@SuppressWarnings("unchecked")
Class<? extends CFType>[] classes = (Class<? extends CFType>[])
VM.listClasses(CFType.class, ClassLoader.getSystemClassLoader());
Class<?>[] emptyArgs = new Class<?>[0];
final Class<?> cfTypeClass = CFType.class;
for (Class<? extends CFType> cls : classes) {
if (cls != cfTypeClass && (cls.getModifiers() & ABSTRACT) == 0) {
try {
java.lang.reflect.Method m = cls.getMethod("getClassTypeID", emptyArgs);
Long typeId = (Long) m.invoke(null);
allCFTypeClasses.put(typeId, cls);
} catch (Throwable e) {
// Ignore, because several of Apple's CFType subclasses don't contain a getClassTypeID() method.
}
}
}
} We should probably use |
Ok, I can reproduce it when switching to using
I think I know how we can fix this... |
Great! wait your good news. |
…ould be added to the allCFTypeClasses map in place of the superclass which actually has the getClassTypeId() method. Changed CFType.Marshaler.toObject() to only use the class from allCFTypeClasses if that class is a subclass of the class passed to toObject(). (#837)
Ok, pushed a fix for this issue. Please test with the next nightly build tomorrow and let us know if the problem is gone. http://docs.robovm.com/advanced-topics/nightlies.html |
It works for the demo project, as well as the originated one. Thanks you guys all. |
This happens again in the latest SNAPSHOT, as reported as issue #728
The text was updated successfully, but these errors were encountered: