I'm trying to implement chipmunk physics engine for a cocos2d-js game. I'm getting the following error when i run it.
jsb: ERROR: File Y:\Documents\cocos\PrebuiltRuntimeJs\frameworks\js-bindings\bindings\auto\jsb_cocos2dx_auto.cpp: Line: 2143, Function: js_cocos2dx_Node_setPhysicsBody
Invalid Native Object
JS: D:/PROJECTS/cocos/Sliderule/runtime/win32/../../src/app.js:32:Error: Invalid Native Object
Here is the code i'm working with
`init:function () {
this._super();
var size = cc.winSize;
this.rect1 = new cc.Sprite(res.null_png,cc.rect(0,0, 200, 25));
this.rect1.setColor(cc.color(255,50,50,1));
this.rect1.setPosition(size.width/2, size.height-12.5);
this.rect1._setAnchorX(0.5);
this.rect1._setAnchorY(0.5);
this.rectbody1 = new cp.Body(1,cp.momentForBox(1,this.rect1.getContentSize().width, this.rect1.getContentSize().height));
this.rectbody1.p = cc.p(size.width/2, size.height-12.5);
this.space.addBody(this.rectbody1);
this.rectshape1 = new cp.BoxShape(this.rectbody1, this.rect1.getContentSize().width - 14, this.rect1.getContentSize().height);
this.space.addShape(this.rectshape1);
this.rect1.setPhysicsBody(this.rectbody1);
this.addChild(this.rect1,1);
`
I get the problem when setting the body to the sprite. Thanks in Advance.
This error message usually appears because of a missing retain(). You have to explicitly set sprites to be kept by the native system (Android, iOS) otherwise it's not valid after some time. And then, if you don't need it anymore: release it.
Try:
this.rect1.retain()
after you created the sprite. And then
this.rect1.release()
when you don't need it anymore.
Related
With the following function I am trying to load the model into the earlier initialized viewer.
viewer.loadModel("https://developer.api.autodesk.com/modelderivative/v2/designdata/dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6aW1wbGVuaWFfaW1kL1JhaV8wNC4zZHM/manifest/urn%3Aadsk.viewing%3Afs.file%3AdXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6aW1wbGVuaWFfaW1kL1JhaV8wNC4zZHM%2Foutput%2FRai_04.3ds.svf")
Unfortuneately I get the following error for the function:
viewer3D.js:74844 Error while processing SVF: {"url":"https://developer.api.autodesk.com/modelderivative/v2/designdata/dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6aW1wbGVuaWFfaW1kL1JhaV8wNC4zZHM/manifest/urn%253Aadsk.viewing%253Afs.file%253AdXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6aW1wbGVuaWFfaW1kL1JhaV8wNC4zZHM%252Foutput%252FRai_04.3ds.svf?domain=http%3A%2F%2Flocalhost%3A3002","httpStatus":400,"httpStatusText":"Bad Request","data":{"url":"https://developer.api.autodesk.com/modelderivative/v2/designdata/dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6aW1wbGVuaWFfaW1kL1JhaV8wNC4zZHM/manifest/urn%253Aadsk.viewing%253Afs.file%253AdXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6aW1wbGVuaWFfaW1kL1JhaV8wNC4zZHM%252Foutput%252FRai_04.3ds.svf?domain=http%3A%2F%2Flocalhost%3A3002"}}
This is the way I initialize my viewer:
function onInitialized() { //console.log("viewer inizialized");
var config = Autodesk.Viewing.createViewerConfig();
config.extensions.push('Autodesk.Viewing.ZoomWindow');
config.startOnInitialize = true;
config.theme = 'light-theme';
viewerApp = new Autodesk.Viewing.ViewingApplication('main-viewer');
viewerApp.registerViewer(viewerApp.k3D,Autodesk.Viewing.Private.GuiViewer3D ,config);
viewer = viewerApp.getViewer(config);
viewer.start();
If I use the version 4.1 of the viewer, the model can be loaded this way. Changing to 6.0 the above described error appears.
I would really appreaciate a hint to a solution of my problem!
Thanks a lot in advance!
Cheers,
Felix
With v6 and onwards, call wrapper method Viewer3D.load insteadof .loadModel so that the resource requests made to Forge endpoints can be formed properly:
viewer.load('https://developer.api.autodesk.com/derivativeservice/v2/derivatives/urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6c2IyMzMvd2Fycmlvci4zZHM/output/warrior.3ds.svf');
or simply:
viewer.start(svfUrl)
Code sample: https://jsfiddle.net/dukedhx/9qncbuLt
So this is my setup for the 'intent':
Intent cameraACTION_VIDEO_CAPTURE = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
tempUri = accessLocalStorage.getThisAppsStorageUriPath();
//Crashed for tempUri = "/data/user/0/hardy.android.go/app_files/test.mp4"
//Crashed for tempUri = "/data/user/0/hardy.android.go/app_files/"
cameraACTION_VIDEO_CAPTURE.putExtra(MediaStore.EXTRA_OUTPUT, tempUri);
cameraACTION_VIDEO_CAPTURE.setFlags(cameraACTION_VIDEO_CAPTURE.getFlags() | Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivityForResult(cameraACTION_VIDEO_CAPTURE,
Integer.parseInt( DataModel.SETVIDEORECORDING.toString()));
Video intent starts as expected and crashes once I finish recording - it doesn't even make it to 'onActivityResult'. Error is:
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
Don't know why there is a Bitmap floating around in there?
Anywayz, so in an attempt to try and pinpoint the issue, I comment out the following and go again:
cameraACTION_VIDEO_CAPTURE.putExtra(MediaStore.EXTRA_OUTPUT, tempUri);
and it works :( - video is stored here:
/storage/emulated/0/DCIM/Camera/VID_20181004_213440310_HDR.mp4
Ok, I have a partial answer. In terms of the application not crashing, I made progress by using FileProvider to generate the Uri.
tempUri = FileProvider.getUriForFile(
context,
BuildConfig.APPLICATION_ID + ".provider",
new File(accessLocalStorage.getThisAppsStorageUriPath().getPath())
);
However, the video File saved at the path in the Uri was of size/length 0 () and I didn't have time to work through this and so, this story ends here :( - hope this is of some help for others!
i am following a famous book "beginning html5 game development with createjs.pdf " Apress Publication .
Anyhow when i run the codes i get error in my browser console : i updated my createjs hosted lib to latest version
gs skinner github i found p.initialize =function is deprecated .
i am not a good programmer. is there any way so that i can fix the error and run the codes of this book. thanks
Uncaught TypeError: this.EventDispatcher_initialize is not a function
AssetManager.js:34 Uncaught TypeError:
here i pasted few lines for 34 to last of function
p.initialize = function () {
this.EventDispatcher_initialize();
this.loadManifest = [
{id:this.EXPLOSION, src:this.assetsPath + 'explosion.mp3'},
{id:this.SOUNDTRACK, src:this.assetsPath + 'dreamRaid1.mp3'},
{id:this.GAME_SPRITES_DATA, src:this.assetsPath + 'all.json'},
{id:this.GAME_SPRITES, src:this.assetsPath + 'all.png'}
];
}
Can you show more of your code? The this.EventDispatcher_initialize is used with early inheritance approaches, as well as with the newer extend/promote approach.
If you are using the old approach, there should be a line above this one that says:
p.EventDispatcher_initialize = p.initialize;
This stores the superclass (EventDispatcher) method on the current class prototype first, so you can call it to apply the default functionality. You should also see something like this at the top, which sets up the inheritance:
function MyClass() {
this.initialize();
}
var p = MyClass.prototype = new createjs.EventDispatcher();
If you are missing any of these steps, your code will not work.
I have a WebGL app using three.js. It has been running fine for months until today, September 7th, 2014.
It no longer runs on Chrome, however, it still continues to run on Firefox and Safari.
I have traced the problem to a specific condition.
I load objects from json files like this:
loader.load("assets/Tables.json", callback_mesh, "assets/maps/", parent.texturesTable);
The callback_mesh function looks like this:
var callback_mesh = function (result, materials, userData) {
for (var i = 0; i < materials.length; i++) {
if (materials[i].uniforms != undefined) {
materials[i].uniforms.tDiffuse.value = userData[TEXTURE_DIFFUSE];
materials[i].uniforms.tNormal.value = userData[TEXTURE_NORMAL];
materials[i].uniforms.tSpecular.value = userData[TEXTURE_SPECULAR];
}
}
var mesh = new THREE.Mesh(result, new THREE.MeshFaceMaterial(materials));
mesh.scale.set(1, 1, 1);
mesh.receiveShadow = true;
mesh.castShadow = true;
objects.push(mesh);
}
The above code no longer runs in Chrome.
If I remove the line "mesh.receiveShadow = true", it works fine.
If I create a new material, instead of using the materials from the json file and modifying their parameters/uniforms, I can leave the receiveShadow set to true and it works.
So the rather specific issue is when I import an object from a json file and assign the materials array that comes from the json file to the mesh as a MeshFaceMaterial and turn on receiveShadow, the object does not load and I get the following error message:
THREE.WebGLProgram: gl.getProgramInfoLog() (260,64-140): warning X3550: sampler array index must be a literal expression, forcing loop to unroll
(89,12): error X6077: texld/texldb/texldp/dsx/dsy instructions with r# as source cannot be used inside dynamic conditional 'if' blocks, dynamic conditional subroutine calls, or loop/rep with break*.
Failed to create D3D shaders.
three.js:25545
59WebGL: INVALID_OPERATION: getUniformLocation: program not linked three.js:25283
21WebGL: INVALID_OPERATION: getAttribLocation: program not linked
And, again, I never saw this prior to today, maybe there was a Chrome update. And it works fine under Firefox and Safari, the mesh loads with receiveShadows on and the shadows are rendered.
In the current Chrome, it works only if I turn off receiveShadows.
Anyone have this same problem or have any thoughts on what might be causing this?
Thanks.
-mat
I have this code at server side (nodejs):
socket.on('data', function(dt){
var rdata = dt;
var msg = JSON.parse(rdata);
broadcast(msg);
});
Also I tried this way: var msg = JSON.parse(dt);
dt gets either:
{"chat":"hey","nickname":"nick_name"} OR
'{"chat":"hey","nickname":"nick_name"}'
Also I have this at the client side (AS3), tried both:
var msg = JSON.stringify({nickname: nname.text, chat: input_txt.text}); OR
var msg = "'" + JSON.stringify({nickname: nname.text, chat: input_txt.text}) + "'";
That is what console gives:
undefined:1
{"chat":"hey","nickname":"nick_name"}
^
SyntaxError: Unexpected token
DEBUG: Program node app exited with code 8
Also in some other situations, it gives all kinds of messages.
Just have no idea what is going on.
BTW, also tried JSONStream, still doesn't work.
What kind of socket exactly are you using? If you are using a websocket you might have already received an object as a response (I think most frameworks do so). If you are using plain net.socket you might be receiving a buffer or the data in chunks and not all at once. This seems like an appropriate fix for that situation:
var buffer;
socket.setEncoding('utf8');
socket.on('data', function(data) {
buffer += data;
});
socket.on('end', function() {
var object = JSON.parse(buffer);
});
Unexpected token at the end of data string, is some ghost symbol that is not a white space. trim() doesn't work, so to substring the last symbor works. This is AS3 symbol, so we have to keep it. First you save this symbol in the new variable. the you erase this symbol from the line. After that you can parse the string. work with it.
undefined:1
{"chat":"hey","nickname":"nick_name"}
^
SyntaxError: Unexpected token
DEBUG: Program node app exited with code 8
When you finish working with it, stringify the object, then add ghost symbol to the end and send over the socket. Without this symbol AS3 will not parse the data.
I don't know why is that, but that works for me.