beo6 Posted June 1, 2013 Share Posted June 1, 2013 Hello Everyone, i created a C++ Project and compiling etc. works nice on Windows. Now i wanted to test it on Android so i published the project for Android but it gave me Errors. then i linked the new .cpp and .h files into the Source-Folder just like the App.cpp and App.h files that are already linked there. But i still get this Error: C:\Leadwerks\Projects/RollingC/Projects/Android/obj/local/armeabi/objs/app/__/__/__/Source/App.o: In function `StoreWorldObjects(Leadwerks::Entity*, Leadwerks::Object*)': C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/App.cpp:33: undefined reference to `Player::Player(Leadwerks::Entity*)' Not sure what i am doing wrong. Will try to compile a completely new Project for Android now. //Edit: Compiling a clean Android project works. I have now found the Application.mk file where i need to add the source files at "LOCAL_SRC_FILES" Now i get different errors: C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/NextMap.cpp: In constructor 'NextMap::NextMap(Leadwerks::Entity*)': C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/NextMap.cpp:15: error: invalid conversion from 'void (*)(Leadwerks::Entity*, Leadwerks::Entity*, float*, float*, float)' to 'void*' C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/NextMap.cpp:15: error: initializing argument 2 of 'virtual void Leadwerks::Entity::AddHook(int, void*)' make: *** [C:\Leadwerks\Projects/RollingC/Projects/Android/obj/local/armeabi/objs/app/__/__/__/Source/NextMap.o] Error 1 make: *** Waiting for unfinished jobs.... C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/Player.cpp: In constructor 'Player::Player(Leadwerks::Entity*)': C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/Player.cpp:10: error: invalid conversion from 'void (*)(Leadwerks::Entity*)' to 'void*' C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/Player.cpp:10: error: initializing argument 2 of 'virtual void Leadwerks::Entity::AddHook(int, void*)' C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/Player.cpp:11: error: invalid conversion from 'void (*)(Leadwerks::Entity*, Leadwerks::Entity*, float*, float*, float)' to 'void*' C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/Player.cpp:11: error: initializing argument 2 of 'virtual void Leadwerks::Entity::AddHook(int, void*)' C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/Player.cpp:12: error: invalid conversion from 'void (*)(Leadwerks::Entity*)' to 'void*' C:\Leadwerks\Projects/RollingC/Projects/Android/jni/../../../Source/Player.cpp:12: error: initializing argument 2 of 'virtual void Leadwerks::Entity::AddHook(int, void*)' make: *** [C:\Leadwerks\Projects/RollingC/Projects/Android/obj/local/armeabi/objs/app/__/__/__/Source/Player.o] Error 1 I suppose that this are some issues that the code needs to be a bit different for Android. Edit: I only used parts of this tutorial. Http://www.leadwerks.com/werkspace/page/tutorials/_/class-hooks-r38 So it seems they are not android compatible? Quote Link to comment Share on other sites More sharing options...
beo6 Posted June 4, 2013 Author Share Posted June 4, 2013 I got it to compile now. I typecasted the methods to (void*) in AddHook entity->AddHook(Entity::UpdateWorldHook,(void*)UpdateWorldHook); entity->AddHook(Entity::CollisionHook,(void*)CollisionHook); entity->AddHook(Entity::DrawHook,(void*)DrawHook); i don't like this way because i am pretty sure it is dirty and is causing the crash when i try to run it. 06-04 02:44:56.058: A/libc(8712): Fatal signal 11 (SIGSEGV) at 0x00000018 (code=1), thread 8738 (Thread-567) But i have still no idea how to solve it. Because everything is working nicely on Windows and i have mostly just followed the tutorial from Josh http://www.leadwerks.com/werkspace/page/tutorials/_/class-hooks-r38 Quote Link to comment Share on other sites More sharing options...
Josh Posted June 4, 2013 Share Posted June 4, 2013 It just casts the function back, so as long as your function matches the documentation you should be fine. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
beo6 Posted June 4, 2013 Author Share Posted June 4, 2013 I haven't changed the gameobject class and when I keep it just like in the tutorial it is working on windows when I compile with visual studio. but the exact same code won't compile with eclipse for android. //edit: just noticed. I have posted this in programming but I should have posted this in the android forum i think. Quote Link to comment Share on other sites More sharing options...
Admin Posted June 4, 2013 Share Posted June 4, 2013 Will check it out in the morning. Quote Link to comment Share on other sites More sharing options...
beo6 Posted June 4, 2013 Author Share Posted June 4, 2013 If you need the project i could send it to you. It might just take its time to upload. Or maybe only the source. To give some more information to possibly help to find the issue: The GameObject in my project is exactly as in the tutorial. The Player Object however i only added an entity parameter to the constructor. Player::Player(Entity* setEntity) { entity = setEntity; entity->SetUserData(this); //Enable the hooks this class uses entity->AddHook(Entity::UpdateWorldHook,UpdateWorldHook); entity->AddHook(Entity::CollisionHook,CollisionHook); entity->AddHook(Entity::DrawHook,DrawHook); } since i have seen other people here doing it this way and that it is working on windows i think that is ok. Thanks anyway for looking at it. Quote Link to comment Share on other sites More sharing options...
Admin Posted June 4, 2013 Share Posted June 4, 2013 I would like to see your source. So to be clear, this is compiling, but when you run it on your device a crash occurs? Quote Link to comment Share on other sites More sharing options...
beo6 Posted June 5, 2013 Author Share Posted June 5, 2013 Source: http://code-i.de/LE3/Source.zip as i have written in the chat: It does not compile on Android when i stick with the tutorial. It only compiled when i typecasted the hook-method to (void*) but it crashed on my android device as soon as i started the game. On Windows it always compiles and runs without any crash. And i have seen in the main.cpp in the c++ project template that you typecast a hook method yourself to (void*) on line 25: Leadwerks::System::AddHook(System::DebugErrorHook,(void*)DebugErrorHook); Quote Link to comment Share on other sites More sharing options...
Josh Posted June 6, 2013 Share Posted June 6, 2013 I copied the code from that tutorial and created a new Foo object in the App::Start function. Everything works fine on Android: Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
beo6 Posted June 6, 2013 Author Share Posted June 6, 2013 Hi Josh, first i need to thank you so much. I tried your Project and it compiled and was running perfectly on my android device. I checked the code and noticed that you also typecasted the hook methods to (void*) so at least i was not completely wrong with my idea. Then i started to remove line by line of my code on loading a map to see what is causing the Crash "Fatal signal 11 (SIGSEGV)". I came to this part where i check the filesize of the map-file: if ( FileSystem::GetFileSize(mapfile) > 0 ) { //map loading stuff } As soon as i removed that line and loaded the map without checking filesize it didn't crashed. So it seems the method "FileSystem::GetFileSize()" causes a Segmentation fault on Android. Thanks for being so patiently when i looked for the error in the wrong place. Quote Link to comment Share on other sites More sharing options...
Admin Posted June 26, 2013 Share Posted June 26, 2013 Create a default CPP project. Replace App.cpp with this: #include "App.h" using namespace Leadwerks; App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {} App::~App() { delete world; delete window; } Vec3 camerarotation; #if defined (PLATFORM_WINDOWS) || defined (PLATFORM_MACOS) bool freelookmode=true; #else bool freelookmode=false; #endif bool App::Start() { System::Print(FileSystem::GetFileSize("Maps/start.map")); //Create a window window = Window::Create("CPPTEST"); //Create a context context = Context::Create(window); //Create a world world = World::Create(); //Create a camera camera = Camera::Create(); camera->Move(0,2,-5); //Hide the mouse cursor window->HideMouse(); std::string mapname = System::GetProperty("map","Maps/start.map"); Map::Load(mapname); //Move the mouse to the center of the screen window->SetMousePosition(context->GetWidth()/2,context->GetHeight()/2); return true; } bool App::Loop() { //Close the window to end the program if (window->Closed()) return false; //Press escape to end freelook mode if (window->KeyHit(Key::Escape)) { if (!freelookmode) return false; freelookmode=false; window->ShowMouse(); } if (freelookmode) { //Keyboard movement float strafe = (window->KeyDown(Key:) - window->KeyDown(Key::A))*Time::GetSpeed() * 0.05; float move = (window->KeyDown(Key::W) - window->KeyDown(Key::S))*Time::GetSpeed() * 0.05; camera->Move(strafe,0,move); //Get the mouse movement float sx = context->GetWidth()/2; float sy = context->GetHeight()/2; Vec3 mouseposition = window->GetMousePosition(); float dx = mouseposition.x - sx; float dy = mouseposition.y - sy; //Adjust and set the camera rotation camerarotation.x += dy / 10.0; camerarotation.y += dx / 10.0; camera->SetRotation(camerarotation); //Move the mouse to the center of the screen window->SetMousePosition(sx,sy); } Time::Update(); world->Update(); world->Render(); context->Sync(false); return true; } Publish the project for Android. Runs fine. Prints 0 for the size, because we had to do some funny things for the Android file system. Quote Link to comment Share on other sites More sharing options...
Rick Posted June 26, 2013 Share Posted June 26, 2013 So none of the file stuff works on mobile then? We need ways to read/write/get info from files on mobile. That's very central to most every game. Quote Link to comment Share on other sites More sharing options...
Admin Posted June 26, 2013 Share Posted June 26, 2013 That's a different issue. I had to implement a "virtual" file system because Android: -Doesn't allow apps to have folders with files in them. -Doesn't allow two files to have the same names, even if the extensions are different. The command std::string FileSystem::GetAppDataPath() returns the correct file path for IO operations. Presently only Windows and Mac are supported. Quote Link to comment Share on other sites More sharing options...
Josh Posted June 26, 2013 Share Posted June 26, 2013 I just got it working for Android. Should be able to get the iOS implementation done before the next patch later this week. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted June 26, 2013 Share Posted June 26, 2013 Yep, I got it. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.