Physics Body Editor error - libgdx

I get this error when trying to initialize BodyEditorLoader from this library http://www.aurelienribon.com/blog/projects/physics-body-editor/
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.UnsatisfiedLinkError: com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape()J
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:127)
Caused by: java.lang.UnsatisfiedLinkError: com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape()J
at com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape(Native Method)
at com.badlogic.gdx.physics.box2d.PolygonShape.<init>(PolygonShape.java:29)
at aurelienribon.bodyeditor.BodyEditorLoader.<init>(BodyEditorLoader.java:31)
How can i fix it?

to see the code where it is called, but I venture to say that the problem is the call to your world this must be called before here's an example:
This a example compile good:
oWorld = new World(gravedad, dormir);
loader = new BodyEditorLoaderNewW(
Gdx.files.internal("data/test.json"));
This a example not compile good:
loader = new BodyEditorLoaderNewW(
Gdx.files.internal("data/test.json"));
oWorld = new World(gravedad, dormir);
recive this:
java.lang.UnsatisfiedLinkError:
com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape () J
note the difference in the world is called one after so gives:
it is possible that in the future can, need this:
BodyEditorLoader - noSuchMethod
but if this is not the solution you could put some of the code, I hope you help

Based on this https://github.com/libgdx/libgdx/issues/2393 the problem is because natives aren't loaded before creating shape.
There are two solutions:
First is creating World instance before creating any shapes.
Second is calling Box2D.init(); before creating any shapes. This method is preferred because you don't need to create World instance and it's much more obvious.
Use this version https://gist.github.com/grulg/8691e7ee7709367ce165 instead of version from Google Code.

Related

how to resolve stringIndexOutofBoundsException when bitmap is initialized

I am learning to develop a game using libgdix.I follow the book Learning LibGDX game development,second edition.
I am getting stuck on using Bitmapfont.
public class AssetsFonts
{
public final BitmapFont defaultSmall;
public final BitmapFont defaultNormal;
public final BitmapFont defaultBig;
public AssetsFonts()
{
defaultSmall = new BitmapFont(Gdx.files.internal("images/arial-15.fnt"),true);
defaultNormal = new BitmapFont(Gdx.files.internal("images/arial-15.fnt"),true);
defaultBig = new BitmapFont(Gdx.files.internal("images/arial-15.fnt"),true);
defaultSmall.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
defaultNormal.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
defaultBig.getRegion().getTexture().setFilter(TextureFilter.Linear,TextureFilter.Linear);
}
}
when i run this am getting the following error
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Error loading font file: images/arial-15.fnt
at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.load(BitmapFont.java:650)
at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.<init>(BitmapFont.java:465)
at com.badlogic.gdx.graphics.g2d.BitmapFont.<init>(BitmapFont.java:115)
at com.packtpub.libgdx.canyonbunny.game.Assets$AssetsFonts.<init>(Assets.java:125)
at com.packtpub.libgdx.canyonbunny.game.Assets.init(Assets.java:49)
at com.packtpub.libgdx.canyonbunny.CanyonBunnyMain.create(CanyonBunnyMain.java:22)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:143)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -7
at java.lang.String.substring(String.java:1918)
at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.load(BitmapFont.java:476)
... 7 more
The exception you've got is this one. Practically saying that something went wrong while loading the file. The inner exception shows what went wrong while loading:
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -7
at java.lang.String.substring(String.java:1918)
at com.badlogic.gdx.graphics.g2d.BitmapFont$BitmapFontData.load(BitmapFont.java:476)
Since there's no call to String#substring at line 476, this is an indication that you're using an older version of libgdx (which is to be expected, because a lot has changed to that file recently). So I'd suggest that you update to the latest nightly (or check the github history at the time of the version you're using), so you know which call is actually causing the error.
Either way, the fact that a substring call failed while loading your file is a good indication that the file is likely to be corrupt or doesnt meet the expected format in another way. Assuming you want to use the font that the libgdx tests uses, then you can download the correct version here and the required image here. Make sure to place the image in the same folder as the fnt file.
Your real problem is that it can't find the font file...
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Error loading font file: images/arial-15.fnt
Make sure the file is in the correct place, which is probably android/assets/images but depends on your project setup.
Also ensure that your run the desktop version with android/assets as the working folder.

WriteMessageText() - example code compile error - error CS0103: The name 'Window' does not exist in the current context

I'm trying to create an application using the NFC (proximity) API on Windows Phone 8. When I copy the example code from the documentation, I get the following compile error...
error CS0103: The name 'Window' does not exist in the current context ...
This error is all over the internet and the common solution seems to be that it only works for native (or C++) code. However the documentation says that it works for managed or native code. How do I get the examples to work in my managed code?
In order to gain access to the active Windows.UI.Core.CoreDispatcher object, you simply need to request Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher.
ORIGINAL EXAMPLE CODE
// Write a message to MessageBlock on the UI thread.
private Windows.UI.Core.CoreDispatcher messageDispatcher =
Window.Current.CoreWindow.Dispatcher;
CORRECTED CODE
// Write a message to MessageBlock on the UI thread.
private Windows.UI.Core.CoreDispatcher dispatcher =
Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
The one small change makes all the examples work! Enjoy.

trouble getting flashdevelop to correctly identify sampling rate of a sound file

I'm trying to put a sound file into a flash program with the following code.
[Embed(source="../lib/DST-Aircord.mp3")]
static var sndtrck:Class; //used to represent the background music file
static var soundtrack:Sound; //used to handle the soundtrack file
soundtrack = new Sound();
soundtrack.load(sndtrck);
soundtrack.play();
I'm not sure that this is correct but it is throwing the following errors.
Error: Unsupported sampling rate (32000Hz)
Error: Unable to transcode ../lib/DST-Aircode.mp3.
Regarding the first error I checked in iTunes and the sampling rate is 44100Hz which I believe is what Flash needs to run. However FlashDevelop is incorrectly determining the sampling rate? I'm guessing that the second error is caused by the first although I'm not entirely sure what it means. Does anyone know what I might be missing in my attempt to embed sound into this SWF?
EDIT: changing the load function to use the path specified in the embed code yields the same error.
the load function of the Sound class only takes a URL of an external sound file. Im not sure what the class your putting into it is, but it probably throws the errors because a Class itself is not a sound file.
This is a link to the load() function of the Sound class, everything about it is there.
While writing this answer I realized that the question is pretty old. ;)
Anyhow, I ran into the same problem a while back and it could be solved
by this: Unsupported sampling flex/actionscript

Flash Error 2012 Can't instantiate Shared Object class?

I have no idea why i am getting this error can somebody please tell me.. what causes this error and how to fix it...
It sounds like you're using new SharedObject(), but Shared Objects are a bit different from normal. Instead of trying to create a new instance yourself, you should be using SharedObject.getLocal like this:
private var mySo:SharedObject = SharedObject.getLocal("application-name");
But obviously change "application-name" to be something specific to your project.
There is a more detailed example in the documentation here: Shared Object Examples

How to debug a runtime stack underflow error?

I'm really struggling to resolve a stack underflow that I'm getting. The traceback I get at runtime is:
VerifyError: Error #1024: Stack underflow occurred.
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
This is particularly difficult to debug because when I run in debug mode it does not happen at all. It only happens when compiled as a release.
Does anyone have any tips on how to debug a Stack Underflow? Are have a clean explanation of what that means for Flash?
In case it helps, this error is occurring when I click a button whose handler makes an RPC call, which uses a URLLoader, an AsyncToken, and then invokes the set of AsyncResponder instances associated with the AsyncToken. With some server-side logging as well as some logging hacked into the swf, I know that the UrlLoader is successfully doing and GET'ing a crossdomain.xml file, is correctly processing it (ie: if I wreck it, I get a security error), and is also successfully completing the "load" request (the server sends the data). The underflow seems to be happening in the Event.COMPLETE listening/handling process (as is, of course, implied by the traceback as well).
mxmlc used = from flex_sdk_4.5.0.20967
Example player (I've tried a few) = 10.2.153.1
UPDATE: My specific problem is solved... but I'm leaving the question as-is since I would like to know how to generally debug such a problem, rather than just getting my specific solution.
In my code I had the following Application definition:
<s:Application height="100%" width="100%"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
initialize="InitData();">
Note that the code is/was attached to the initialize event.
InitData() and relevant defintions are/were:
import classes.RpcServerProxy;
public var SP:RpcServerProxy;
public function InitData():void {
SP = new RpcServerProxy("http://192.168.1.102:1234");
}
When I switched the InitData() call to be on the onCompletion event instead of initialize (thanks J_A_X!), the problem goes away entirely. What seems to have been happening was that the Event.COMPLETE event handler (onComplete in the stack trace) was using the global SP object. Something about the release (vs debug) compilation must have been affecting the startup timing of the SP variable initialization. Moving the handler later to the onCompletion event resolved all issues.
As said above, I would still like to know what tricks/tools are available for debugging initialization issues like this.
UPDATE 2:
applicationComplete seems to be an even better event than creationComplete to put application initialization code. See this blog entry for some explanation, and and this video (around 4:25) by an Adobe Tech Evangelist for an example of simple "start of application" data initialization.
I got rid of this error by adding compiler argument:
-omit-trace-statements=false
Stack underflow basically means the compiler messed up.
You can use SWFWire Inspector to look at the bytecode of the event handler, if you want to know exactly how it messed up. You can also use SWFWire Debugger to see which methods were called, but in this case, you already knew where it was happening.
If you post the broken swf, I can give you more info.
Sean is right that to debug it you can look at the byte code, but that didn't sound appealing to me.
Based on my experience and research, it is often due to the presence of a trace statement that incorrectly gets compiled out in release mode, and generates invalid byte code. So, I would say to "debug" it, "Look for places where you are using trace. Try commenting them all out in the offending function and see if the issue goes away."
In my case, it was a trace statement as the first line of a catch block:
catch (e:TypeError) {
trace(e.getStackTrace()); //This line is the problem
throw new Error("Unexpected type encountered");
}
I found someone else with this exact issue here.
This code also leads to stack underflow only in release mode (flag -debug=false):
true && trace('123');
mxlmc flex sdk version 4.5.0.20967, flashplayer version 10.3.181.14 (linux).
Check your code for similar expressions.
This code caused me issues when I compiled a release candidate from flash builder 4.5
public function set configVO( value:PopupConfigVO ):void
{trace("CHANGING")
Resolved by inserting a space between the the trace and curly brace
public function set configVO( value:PopupConfigVO ):void
{ trace("CHANGING")
Hope this helps.
For people looking for the same problem, I just got this caused by a trace statement in the 'default' case of a switch statement. Commented out the trace, stack underflow resolved.
Interesting... I was getting this error with a SWF that I'd pulled off the web, an Away3D based graphics demo. At the time I was running this on the Tamarin VM rather than the actual Flash/AIR runtimes, so could stick a breakpoint on the "verifyFailed(kStackUnderflowError)" line and see what was happening.
The -Dverbose flag also helped find the culprit:
typecheck MethodInfo-1480()
outer-scope = [global]
[Object~ Object] {} ()
0:pop
VERIFY FAILED: Error #1024: Stack underflow occurred.
And looking at the ABC using SWFInvestigator, I found this:
var function(Object):void /* disp_id=0 method_id=1480 nameIndex = 0 */
{
// local_count=2 max_scope=0 max_stack=0 code_len=2
// method position=52968 code position=155063
0 pop
1 returnvoid
}
So there is an obvious issue where the 'trace' has been removed but the compiler has put a 'pop' in there: I wouldn't have thought this was needed as a trace call should presumably have been made via 'callpropvoid'?
Quite why this doesn't fail on AIR/Flash I don't know..
Anyway: looks to me like an ASC compiler problem i.e perhaps one of the ActionScript3 compilers had a fault with this - hence the workarounds that have been mentioned so far.
It's quite simple, and it doesn't have anything to do with spaces before or after brackets, trace commands or whatever else: it's just 1 really simple thingy:
DO NOT LOOP EMPTY!
Meaning, while developing, we all //comment some lines sometimes, and when that results in
for (...) {
// skip for now
}
the compiler gets :
for(...){}
and that my good friends, is something the compiler doesn't like!
so, NO empty loops, and you're on your way again...
Happy hunting,
P.
I had the exact same problem, but in my case the cause of the problem was a trace statement in a place where the compiler didn't expect it to find it, right after a package declaration at the beginning of the class:
package utils
{
trace ("trace something here");
And that's why compiling in debug mode removed the problem.