Hello everyone,
I have some trouble about passing arguments to AsyncTask.
I fount this topic and tried like this;
in Application.h;
class Application;
class MyTask : public AsyncTask {
public:
MyTask(Application* _obj) : AsyncTask("My Task"), _self(_obj) {
}
protected:
virtual AsyncTask::DoneStatus do_task() {
std::cout << "a is " << _self->a << std::endl;
return AsyncTask::DS_done;
}
private:
Application* _self;
};
class Application : public CSingleton<Application>
{
public:
Application();
~Application();
int a=5;
void init();
void create(std::string _title, int _w, int _h, bool _fullscreen);
void loop();
void exit();
};
in Application.cpp;
MyTask* _task = new MyTask(this);
AsyncTaskManager::get_global_ptr()->add(_task);
cant compile it;
And if i add anything in MyTask class like “int a;” i can compile but game crashing;
class Application;
class MyTask : public AsyncTask {
public:
int a;
MyTask() : AsyncTask("My Task"){
}
protected:
virtual AsyncTask::DoneStatus do_task() {
std::cout << "a is " << a << std::endl;
return AsyncTask::DS_done;
}
};
class Application : public CSingleton<Application>
{
public:
Application();
~Application();
void init();
void create(std::string _title, int _w, int _h, bool _fullscreen);
void loop();
void exit();
};
MyTask* _task = new MyTask();
_task->a = 7;
AsyncTaskManager::get_global_ptr()->add(_task);
I prefer second method but like i said in public or private doesn’t matter when i add any variable game crashing. And i dont want to use GenericAsyncTask because in that type everything must be static.
Do you have any idea? Thanks…