Quantcast
Channel: cocos2d-x - Cocos Forums
Viewing all 2748 articles
Browse latest View live

Crash due to onLoadNativeLibraries for some users

$
0
0

@DavidHoltkamp wrote:

We recently released a game using c++ Cocos2d-X on Android. I am getting a crash from a very small number of users while loading the native libraries.

It crashes in “Cocos2dxActivity.java” at

System.loadLibrary(libName);

This is the error that it gives:

Fatal Exception: java.lang.UnsatisfiedLinkError

dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/(REDACTED MY BUNDLE ID)-1/base.apk”],nativeLibraryDirectories=[/data/app/(REDACTED MY BUNDLE ID)-1/lib/arm, /data/app/(REDACTED MY BUNDLE ID)-1/base.apk!/lib/armeabi, /vendor/lib, /system/lib]]] couldn’t find “libMyGame.so”

I can’t understand why this would only happen on some users devices. It also seems to happen on a variety of different devices and versions of Android. Any help would be greatly appreciated!

Thanks,
David

Posts: 5

Participants: 2

Read full topic


What is the value of NSNotFound in cocos2dx 3.17

$
0
0

@chiragkevadiya wrote:

i am converting cocos2d project to cocos2dx i am stuck at NSNotFound
can any one help me to solve this ?
what should i write instead of NSNotFound

if(nPos != NSNotFound) {

            [self reorderChild:ammo.sprt z:1];
            if (nPos == 0) {
            [leftSnake insertObject:ammo atIndex:nPos+1];

Posts: 5

Participants: 2

Read full topic

How to use Text to speech Converter

Parallelism (std::thread)

$
0
0

@krevedkonet wrote:

Hi there!
I tried to study parallelism with std::thread. I read a lot of topics and examples on this theme, but I just can’t implement this in my program.

For starters, description:
Since creating and deleting threads is a labor-intensive process for the CPU, I decided to create a vector with a given number of threads in Level1.cpp:
Level1.h

class Level1 : public cocos2d::Layer
{
public:
	static cocos2d::Scene* createScene();
	virtual bool init();
	CREATE_FUNC(Level1);
	void update(float dt) override;

private:
// ... (declaration of variables)

	std::vector<std::thread> threadsPool;
	std::mutex mtx;
};

in Level1.cpp

bool Level1::init()
{
	if (!Layer::init())
	{
		return false;
	}

// ... initializations

	int numThreads = std::thread::hardware_concurrency();
	threadsPool.resize(numThreads);

	this->scheduleUpdate();
	return true;
}

void Level1::update(float dt)
{
// ... other calculations
    vai->vehicleAIMovement(dt, vehiclePlayerPosition, vehicleAIList, WayPointsList, it, threadsPool, mtx);
}

(vai - object of VehicleAI class)
VehicleAI class class has 3 functions:
vehicleAIMovement() - function called from Level1::update(float dt)
trackingTrajectory() - function called from vehicleAIMovement()
trackingOtherVehicles() - function called from trackingTrajectory()

so in VehicleAI.cpp

float VehicleAI::trackingTrajectory(cocos2d::Vec2 vehiclePlayerPosition, std::vector<std::shared_ptr<VehicleAI>> vehicleAIList, int iterator, float V, float dt, std::vector<std::thread>& threadsPool, std::mutex& mtx)
{
    // ... many many calculations

    	int iterator1 = 0;
	// check every object in the list
    	while (vehicleAIList.size() > iterator1)
	{
		// except itself
		if (iterator1 != iterator)
		{
			auto otherAIVehicle = vehicleAIList.at(iterator1);
			for (auto&& thread : threadsPool)
			{
				if (thread.joinable())
				{
					continue;
				}
				else
				{
					thread = std::thread([=, &boolStopVehicle, &allVehiclesOnCrossroadStopped, &distNearestVehicle] {trackingOtherVehicles(otherAIVehicle, FM1, RM1, FR1, FL1, RR1, RL1, iterator1, F1, V1, W1, L1, minStoppingDistance, decelerationDistance, STP, std::ref(boolStopVehicle), std::ref(allVehiclesOnCrossroadStopped), std::ref(distNearestVehicle)); });
				}
			}
		}
	     iterator1++;
    }

}

trackingOtherVehicles() function should overwrite the “boolStopVehicle” variable, and a few more.
In this form, the code does not work correctly: the function ceases to be called when all threads initially receive their task.
(By the way, the number of threads is much smaller than the size of the “vehicleAIList” vector)
Trying to solve the issue of thread congestion, I came to this conclusion:

    int iterator1 = 0;
	// check every object in the list
	while (vehicleAIList.size() > iterator1)
	{
		// except itself
		if (iterator1 != iterator)
		{
			auto otherAIVehicle = vehicleAIList.at(iterator1);
			bool allThreadsRunning = true;
			while (allThreadsRunning)
			{
				for (auto&& thread : threadsPool)
				{
					if (thread.joinable())
					{
						if (allThreadsRunning)
						{
							thread.join();
						}
						else
						{
							continue;
						}
					}
					else
					{
						std::lock_guard<std::mutex> lock(mtx);
						thread = std::thread([=, &boolStopVehicle, &allVehiclesOnCrossroadStopped, &distNearestVehicle] {trackingOtherVehicles(otherAIVehicle, FM1, RM1, FR1, FL1, RR1, RL1, iterator1, F1, V1, W1, L1, minStoppingDistance, decelerationDistance, STP, std::ref(boolStopVehicle), std::ref(allVehiclesOnCrossroadStopped), std::ref(distNearestVehicle)); });
						allThreadsRunning = false;
					}
				}
			}
		}
		iterator1++;
	}

But it still doesn’t work correctly and does not provide any parallelization benefits. The program starts to slow down even more.
It’s obvious that I’m doing something wrong, but I don’t understand how to handle it.
I hope for the help of the guru)

Posts: 6

Participants: 4

Read full topic

ClippingNode Doesn't Work With Alpha on Some Specific Devices with Android 9?

$
0
0

@rlaghdejr wrote:

Hello!

It’s my first time posting, so please let me know if I broke any forum rule or something. I will update/fix.

Recently some users of our app are reporting images not showing correctly. After some digging I found out it was ClippingNode not working as expected on the following devices with Android 9 (Pie).

Moto g(6) Play
Samsung Galaxy J4+
Samsung Galaxy J6+

One thing in common among them is they are all using Qualcomm Adreno 308 GPU.

Attaching two images: same code with different devices: Pixel 2 and Moto g(6) Play.


And here’s the code I’m using for the test above.

    auto clippingNode = ClippingNode::create();
    auto cloud = Sprite::create("cloud.png");
    clippingNode->addChild(cloud);
    clippingNode->setStencil(Node::create());
    clippingNode->setAlphaThreshold(0);
    addChild(clippingNode, 10);
    clippingNode->setPosition(getContentSize() * 0.5f);
    auto brush = Sprite::create("brush.png");
    clippingNode->getStencil()->addChild(brush);

I’m wondering if anyone is having similar issues. Any suggestions / guides will be appreciated. Current cocos2d-x we are using is 3.16, but I have tried upgrading it to 3.17.2, which didn’t help.

Posts: 1

Participants: 1

Read full topic

BUG. When bluetooth controller connects, editbox disappear

$
0
0

@overcocos wrote:

Hi,

I found that with some game controllers, when I connect, the editbox will disappear. Here’s a video showing it.

https://filedn.com/l3TGy7Y83c247u0RDYa9fkp/temp/cocos2dx/bluetooth/test_bluetooth.m4v

This is a hello world with an editbox only, I made a apk

https://filedn.com/l3TGy7Y83c247u0RDYa9fkp/temp/cocos2dx/bluetooth/TestBluetooth3.17.2.apk

source: replace the helloworld.cpp with his
https://filedn.com/l3TGy7Y83c247u0RDYa9fkp/temp/cocos2dx/bluetooth/HelloWorldScene.cpp

I found it happens on some bluetooth gamepads only, If you have gamepad, could you help test too?

There’s a few issues with gamepads I reported


Posts: 1

Participants: 1

Read full topic

Get camera size

$
0
0

@xSilver978 wrote:

Hello everyone!

I want to Instantiate objects at the borders of the Main Camera.
I read the Camera documentation but I can’t find a property or method which could give me the size of the camera or the borders of the camera.
Is there a way to get these information?

Thanks in advance!

Posts: 2

Participants: 2

Read full topic

Errors In xcode with cocos2dx v2.2.6 build

$
0
0

@mansoor090 wrote:

Hi, I am new to cocos2dx , came here to update a existing app already. I have made changes to the script required. After running build in xcode I am facing several errors. x file not found , y file not found etc

I have solved many of those file not found problem but now i am stuck at
“iostream” file not found ()
“cassert” file not found (b2settings.h)
“string” file not found (CSDATAVISITOR.h)

Note: I am not a cocos2dx developer , this task is assigned to me by the company

Posts: 2

Participants: 2

Read full topic


getResponseDataString is not the same as getResponseData

$
0
0

@overcocos wrote:

So I’m looking at the source of getResponseDataString, it is using a different buffer from getResponseData.

/**
 * Get the http response data.
 * @return std::vector<char>* the pointer that point to the _responseData.
 */
std::vector<char>* getResponseData()
{
    return &_responseData;
}

/**
 * Get the string pointer that point to the response data.
 * @return const char* the string pointer that point to the response data.
 */
const char* getResponseDataString() const
{
    return _responseDataString.c_str();
}

From the comments, it look like they should be returning from same buffer.

I can’t find anywhere in the code that is setting it. What is the serparate _responseDataString buffer used for?

Posts: 1

Participants: 1

Read full topic

Make a Cocos game not scale from top to bottom when the device has a notch

$
0
0

@ArkaM wrote:

So, I have a use-case in which if an Android phone has a notch, I do not want anything to be shown in the top bar. By default, most phones handle this situation without writing additional code. Eg: New Moto G phones with a Notch. But some phones don’t: Like Galaxy A70.

I have upgraded my Cocos 2DX version to the latest and put the game within the getSafeAreaRect rectangle. This works well on the A70, but there’s a double notch adjustment on the Moto phone(since the phone already handles the game within the area). Any guidance on how I can handle this situation is appreciated. I tried Android with Notch simulator too, and it seems to work fine on a Galaxy Note 9(without the getSafeAreaRect API), as the game scaled within the non Notch area by default, and doesn’t go fullscreen. Is this bug specific to Infinity Displays?

Posts: 2

Participants: 2

Read full topic

Auto frameSize = glview->getFrameSize() incorrect

$
0
0

@BobsTheDude wrote:

Not sure if I am doing something wrong, but testing this on different devices the height and width are switched.

auto frameSize = glview->getFrameSize()
iPhone SE

Shows:
(cocos2d::Size) frameSize = (width = 1136, height = 640)

So, am I missing something?

Posts: 4

Participants: 2

Read full topic

IOS - Multiple inheritance problem: bad alloc!

$
0
0

@carloramponi wrote:

Hello!
I’m testing out my cocos2d-x c++ game on ios and i’ve noticed a bug(?).
I don’t really know if this is a bug and I also think that this is not related to the framework.

I integrated firebase::admob to my game and on Android it works fine!
On IOS it works fine but when the framework tries to call my listener everythink crashes.

Here is my Listener Class:

class MyRewardedVideoListener {

public:
    virtual void rewardPlayer(firebase::admob::rewarded_video::RewardItem reward) = 0;
    virtual void handleError() = 0;
    virtual void refuseReward() = 0;
};

Here is the implementation:

class ChargeBatteryPopUp :	public PopUp, public MyRewardedVideoListener {

public:
	CREATE_FUNC(ChargeBatteryPopUp);

	void rewardPlayer(firebase::admob::rewarded_video::RewardItem reward) override;
	void handleError() override;
	void refuseReward() override;

...

};

I have a pointer to this class in the admob lister that calls this methods when those things happen.
The pointer is of this type:

MyRewardedVideoListener * myListener;

But when i try to call a method, for example:

myListener->rewardPlayer(reward);

The game crashes and i get a BAD_ACCESS exception:

Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)

These classes work fine on android so I don’t know why i’m getting this problem on IOS.
Could be because of the fact that Objective-C does not support multiple inheritance?
I have not fount anything useful on the web that’s why I’m writing this post. I don’t even know if this is the right place to ask this.

If you need more information let me know!

Thanks,
Carlo

Posts: 1

Participants: 1

Read full topic

Tiled Map rendering problem?

$
0
0

@tranthor wrote:

Hi,
I’ve a strange problem with a map. I will try to explain it with an example.
This is part of my map:

When I load it, it works. I can see the map.
But if I change some tiles by another ones, for example like this:

I can’t see the green background anymore and that tiles/sprites are badly drawn. Result:

I only replaced some tiles by another ones, in the same Layer.
The draw problem sounds like a bug? I’m using Tiled 1.2 but i also tried with Tiled 1.0

Thanks.

Posts: 1

Participants: 1

Read full topic

Log in xCode (Mac)

$
0
0

@yosu2s wrote:

Hi guys,

I am new and testing out cocos2d. I tried a few tutorials and the graphics appear nicely.

But I am unable to view any log in Console when I use ‘cclog’ & ‘log’. How do i view logs printed out in my program on Mac ?

Posts: 9

Participants: 4

Read full topic

Can't build project for Android, undefined reference

$
0
0

@Lukas0842 wrote:

When I try to run/build my Game in Android Studio I get an error but it works without any error in Xcode. I get the following error in Android Studio:

/Users/lukas/Documents/CircleGame/Classes/AppDelegate.cpp:126: error: undefined reference to 'MenuScene::createScene()'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

This is the code in AppDelegate.cpp that gives an error:

auto scene = MenuScene::createScene();

This is the code in MenuScene.cpp

#include "MenuScene.h"

USING_NS_CC;


Scene* MenuScene::createScene() {
    return MenuScene::create();
}

bool MenuScene::init() {
    if ( !Scene::init() ) {
        return false;
    }

    ...

and this is MenuScene.h

class MenuScene : public cocos2d::Scene {
public:
    virtual bool init();
    static cocos2d::Scene* createScene();
 
    // implement the "static create()" method manually
    CREATE_FUNC(MenuScene);
    
    ...

What can I do to fix this error?

Posts: 1

Participants: 1

Read full topic


V4 building on Xcode 11 beta on macOS 10.15 beta

$
0
0

@trojanfoe wrote:

Hi guys, I have managed to get the Cocos2d-x v4 branch to build on macOS 10.15 beta using the Xcode 11 beta toolchain by using CMake 3.14 as that has built-in support for generating iOS Xcode projects without the need for a custom toolchain script.

I have created a PR for this work, which I hope will be considered for merging into upstream/v4.

I have had cpp-tests running on an iOS 13 device however while it also builds for the iOS 13 Simulator (which has hardware support for Metal) it crashes due to a shader compile error, which I have yet to look into.

-A

Posts: 5

Participants: 3

Read full topic

How to export files from CocosCreator to Cocos2d-x

$
0
0

@MadJi wrote:

Hello,
I may have missed something, but I couldn’t figure out how to export the scene from Cocos Creator to Cocos2d-x.
I want to do things with the creator as backgrounds, UI and use them in coconut, but I couldn’t figure out how to export it and how to import it later in my C++ project.
I use:
Creator 2.1.2
Cocos2d-x-3.16
Xcode

Thanks.

Posts: 4

Participants: 2

Read full topic

Had to uninstall my python3 because path kept finding it when cocos internally ran python

$
0
0

@gustxw wrote:

In order to get cocos2dx to work i had to uninstall my python cause it kept finding it when i ran the cocos command it gave “raw_input not found” due to it not existing in python 3 even tho i had installed python 2 it wasnt being distinguised by cocos, eventually i wanted to make it work so i decided to uninstall python 3 and all my stuff i previously had installed with it
my question is now, is there a way to have both python versions installed on windows the same time while also using cocos2dx?

Posts: 4

Participants: 2

Read full topic

Need help for APK build with cocos compile

$
0
0

@Jang_Wei wrote:

Hello
How’s it going?

I compiled my game with below cocos command and I get APK

cocos compile -p android --ap android-11 -m release

When I run app in android device, it shows below message

This app was built for an older version of Android and may not work properly.
Try checking for updates, or contact the developer

Do you know what I need to update or change?

Thank you
Best Regards

Posts: 1

Participants: 1

Read full topic

3.17.2 not working on command line but works well on android studio

$
0
0

@redkoda wrote:

Platform: Mac OS.
Cocos2d-x version:3.17.2

Following the tutorial:

./setup.py

cocos new abc317 -p com.abc.abc317 -l cpp -d .

cd abc317

cocos compile -p android

Error message as below:
"Configuration failed.

External native generate JSON debug: JSON generation completed with problems

:abc317:generateJsonModelDebug (Thread[Task worker for ‘:’,5,main]) completed. Took 0.05 secs.

FAILURE: Build failed with an exception."

Change the following configuration in android-studio.
PROP_BUILD_TYPE=ndk-build

Run the game on Android studio, it works fine.

After that, try again on command line, it doesn’t work.

cocos compile -p android

Error message as below:
"Configuration failed.

External native generate JSON debug: JSON generation completed with problems

:abc317:generateJsonModelDebug (Thread[Task worker for ‘:’,5,main]) completed. Took 0.05 secs.

It looks the command line is still using the CMAKE. Would you mind to tell me how to correct the command line issue? Thank you very much.

Posts: 5

Participants: 2

Read full topic

Viewing all 2748 articles
Browse latest View live


Latest Images