[DEV] update to the new ETK allocator wrapper

This commit is contained in:
Edouard DUPIN 2017-10-21 19:05:21 +02:00
parent 0f14d7341a
commit 3be9f44264
10 changed files with 64 additions and 56 deletions

View File

@ -545,18 +545,18 @@ extern "C" {
s_applicationInit = NULL; s_applicationInit = NULL;
gale::Application* localApplication = NULL; gale::Application* localApplication = NULL;
// call the basic init of all application (that call us ...) // call the basic init of all application (that call us ...)
main(0,NULL); main(0, NULL);
localApplication = s_applicationInit; localApplication = s_applicationInit;
s_applicationInit = NULL; s_applicationInit = NULL;
if (org_gale_GaleConstants_GALE_APPL_TYPE_ACTIVITY == _typeApplication) { if (org_gale_GaleConstants_GALE_APPL_TYPE_ACTIVITY == _typeApplication) {
tmpContext = new AndroidContext(localApplication, _env, _classBase, _objCallback, AndroidContext::appl_application); tmpContext = ETK_NEW(AndroidContext, localApplication, _env, _classBase, _objCallback, AndroidContext::appl_application);
} else if (org_gale_GaleConstants_GALE_APPL_TYPE_WALLPAPER == _typeApplication) { } else if (org_gale_GaleConstants_GALE_APPL_TYPE_WALLPAPER == _typeApplication) {
tmpContext = new AndroidContext(localApplication, _env, _classBase, _objCallback, AndroidContext::appl_wallpaper); tmpContext = ETK_NEW(AndroidContext, localApplication, _env, _classBase, _objCallback, AndroidContext::appl_wallpaper);
} else { } else {
GALE_CRITICAL(" try to create an instance with no apply type: " << _typeApplication); GALE_CRITICAL(" try to create an instance with no apply type: " << _typeApplication);
return -1; return -1;
} }
if (nullptr == tmpContext) { if (tmpContext == nullptr) {
GALE_ERROR("Can not allocate the main context instance _id=" << (s_listInstance.size()-1)); GALE_ERROR("Can not allocate the main context instance _id=" << (s_listInstance.size()-1));
return -1; return -1;
} }
@ -572,24 +572,24 @@ extern "C" {
GALE_DEBUG("** remove JVM Pointer **"); GALE_DEBUG("** remove JVM Pointer **");
GALE_DEBUG("*******************************************"); GALE_DEBUG("*******************************************");
if( _id >= (int32_t)s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0) { || _id < 0) {
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
return; return;
} }
if (nullptr == s_listInstance[_id]) { if (s_listInstance[_id] == nullptr) {
GALE_ERROR("the requested instance _id=" << (int32_t)_id << " is already removed ..."); GALE_ERROR("the requested instance _id=" << (int32_t)_id << " is already removed ...");
return; return;
} }
s_listInstance[_id]->unInit(_env); s_listInstance[_id]->unInit(_env);
delete(s_listInstance[_id]); ETK_DELETE(AndroidContext, s_listInstance[_id]);
s_listInstance[_id]=nullptr; s_listInstance[_id]=nullptr;
} }
void Java_org_gale_Gale_EWtouchEvent(JNIEnv* _env, jobject _thiz, jint _id) { void Java_org_gale_Gale_EWtouchEvent(JNIEnv* _env, jobject _thiz, jint _id) {
ethread::UniqueLock lock(g_interfaceMutex); ethread::UniqueLock lock(g_interfaceMutex);
GALE_DEBUG(" == > Touch Event"); GALE_DEBUG(" == > Touch Event");
if( _id >= (int32_t)s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id < 0
|| nullptr == s_listInstance[_id] ) { || s_listInstance[_id] == nullptr) {
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -603,8 +603,8 @@ extern "C" {
GALE_DEBUG("** Activity on Create **"); GALE_DEBUG("** Activity on Create **");
GALE_DEBUG("*******************************************"); GALE_DEBUG("*******************************************");
if( _id >= (int32_t)s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id < 0
|| nullptr == s_listInstance[_id] ) { || s_listInstance[_id] == nullptr) {
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -619,8 +619,8 @@ extern "C" {
GALE_DEBUG("** Activity on Start **"); GALE_DEBUG("** Activity on Start **");
GALE_DEBUG("*******************************************"); GALE_DEBUG("*******************************************");
if( _id >= (int32_t)s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id < 0
|| nullptr == s_listInstance[_id] ) { || s_listInstance[_id]== nullptr) {
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -634,8 +634,8 @@ extern "C" {
GALE_DEBUG("** Activity on Re-Start **"); GALE_DEBUG("** Activity on Re-Start **");
GALE_DEBUG("*******************************************"); GALE_DEBUG("*******************************************");
if( _id >= (int32_t)s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id < 0
|| nullptr == s_listInstance[_id] ) { || s_listInstance[_id] == nullptr) {
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -648,8 +648,8 @@ extern "C" {
GALE_DEBUG("** Activity on resume **"); GALE_DEBUG("** Activity on resume **");
GALE_DEBUG("*******************************************"); GALE_DEBUG("*******************************************");
if( _id >= (int32_t)s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id < 0
|| nullptr == s_listInstance[_id] ) { || s_listInstance[_id] == nullptr) {
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -662,8 +662,8 @@ extern "C" {
GALE_DEBUG("** Activity on pause **"); GALE_DEBUG("** Activity on pause **");
GALE_DEBUG("*******************************************"); GALE_DEBUG("*******************************************");
if( _id >= (int32_t)s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id < 0
|| nullptr == s_listInstance[_id] ) { || s_listInstance[_id] == nullptr) {
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -678,8 +678,8 @@ extern "C" {
GALE_DEBUG("** Activity on Stop **"); GALE_DEBUG("** Activity on Stop **");
GALE_DEBUG("*******************************************"); GALE_DEBUG("*******************************************");
if( _id >= (int32_t)s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id < 0
|| nullptr == s_listInstance[_id] ) { || s_listInstance[_id] == nullptr) {
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -692,8 +692,8 @@ extern "C" {
GALE_DEBUG("** Activity on Destroy **"); GALE_DEBUG("** Activity on Destroy **");
GALE_DEBUG("*******************************************"); GALE_DEBUG("*******************************************");
if( _id >= (int32_t)s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id < 0
|| nullptr == s_listInstance[_id] ) { || s_listInstance[_id] == nullptr) {
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;
@ -715,8 +715,8 @@ extern "C" {
jfloat _y) { jfloat _y) {
ethread::UniqueLock lock(g_interfaceMutex); ethread::UniqueLock lock(g_interfaceMutex);
if( _id >= (int32_t)s_listInstance.size() if( _id >= (int32_t)s_listInstance.size()
|| _id<0 || _id < 0
|| nullptr == s_listInstance[_id] ) { || s_listInstance[_id] == nullptr) {
GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); GALE_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : generate error in java to stop the current instance // TODO : generate error in java to stop the current instance
return; return;

View File

@ -25,6 +25,7 @@
#include <echrono/Steady.hpp> #include <echrono/Steady.hpp>
#include <echrono/Time.hpp> #include <echrono/Time.hpp>
#include <etk/typeInfo.hpp> #include <etk/typeInfo.hpp>
#include <etk/Allocator.hpp>
ETK_DECLARE_TYPE(gale::Context); ETK_DECLARE_TYPE(gale::Context);
/** /**
@ -621,6 +622,13 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) {
m_simulationFile.filePuts(etk::toString(_displayEveryTime)); m_simulationFile.filePuts(etk::toString(_displayEveryTime));
m_simulationFile.filePuts("\n"); m_simulationFile.filePuts("\n");
} }
{
static int32_t countMemeCheck = 0;
if (countMemeCheck++ >= 10*16) {
countMemeCheck = 0;
ETK_MEM_SHOW_LOG(true);
}
}
//GALE_VERBOSE("Call draw"); //GALE_VERBOSE("Call draw");
echrono::Steady currentTime = echrono::Steady::now(); echrono::Steady currentTime = echrono::Steady::now();
//echrono::Time currentTime2 = echrono::Time::now(); //echrono::Time currentTime2 = echrono::Time::now();

View File

@ -251,9 +251,9 @@ int gale::run(gale::Application* _application, int _argc, const char *_argv[]) {
void IOs::createInterface() { void IOs::createInterface() {
etk::init(l_argc, l_argv); etk::init(l_argc, l_argv);
GALE_INFO("Create new interface"); GALE_INFO("Create new interface");
interface = new MacOSInterface(l_application, l_argc, l_argv); interface = ETK_NEW(MacOSInterface, l_application, l_argc, l_argv);
l_application = nullptr; l_application = nullptr;
if (nullptr == interface) { if (interface == nullptr) {
GALE_CRITICAL("Can not create the X11 interface ... MEMORY allocation error"); GALE_CRITICAL("Can not create the X11 interface ... MEMORY allocation error");
return; return;
} }
@ -263,7 +263,7 @@ void IOs::releaseInterface() {
if (interface != nullptr) { if (interface != nullptr) {
GALE_INFO("Remove interface"); GALE_INFO("Remove interface");
} }
delete(interface); ETK_DELETE(MacOSInterface, interface);
interface = nullptr; interface = nullptr;
} }

View File

@ -1295,12 +1295,13 @@ class X11Interface : public gale::Context {
GALE_CRITICAL("Unknow thys type of bitDepth : " << depth); GALE_CRITICAL("Unknow thys type of bitDepth : " << depth);
return; return;
} }
char* tmpVal = new char[4*dataImage.getWidth()*dataImage.getHeight()]; etk::Vector<char> tmpVal;
tmpVal.resize(4*dataImage.getWidth()*dataImage.getHeight(), 0);
if (tmpVal == NULL) { if (tmpVal == NULL) {
GALE_CRITICAL("Allocation error ..."); GALE_CRITICAL("Allocation error ...");
return; return;
} }
char* tmpPointer = tmpVal; char* tmpPointer = &tmpVal[0];
switch(depth) { switch(depth) {
case 16: case 16:
for(ivec2 pos(0,0); pos.y()<dataImage.getHeight(); pos.setY(pos.y()+1)) { for(ivec2 pos(0,0); pos.y()<dataImage.getHeight(); pos.setY(pos.y()+1)) {
@ -1349,7 +1350,7 @@ class X11Interface : public gale::Context {
depth, depth,
ZPixmap, ZPixmap,
0, 0,
(char*)tmpVal, (char*)&tmpVal[0],
dataImage.getWidth(), dataImage.getWidth(),
dataImage.getHeight(), dataImage.getHeight(),
32, 32,
@ -1420,7 +1421,6 @@ class X11Interface : public gale::Context {
myImage->data = nullptr; myImage->data = nullptr;
XDestroyImage(myImage); XDestroyImage(myImage);
delete[] tmpVal;
#endif #endif
} }
/****************************************************************************************/ /****************************************************************************************/

View File

@ -1401,12 +1401,9 @@ class WAYLANDInterface : public gale::Context {
GALE_CRITICAL("Unknow thys type of bitDepth : " << depth); GALE_CRITICAL("Unknow thys type of bitDepth : " << depth);
return; return;
} }
char* tmpVal = new char[4*dataImage.getWidth()*dataImage.getHeight()]; etk::Vector<char> tmpVal
if (nullptr == tmpVal) { tmpVal.resize(4*dataImage.getWidth()*dataImage.getHeight(), 0);
GALE_CRITICAL("Allocation error ..."); char* tmpPointer = &tmpVal[0];
return;
}
char* tmpPointer = tmpVal;
switch(depth) { switch(depth) {
case 16: case 16:
for(ivec2 pos(0,0); pos.y()<dataImage.getHeight(); pos.setY(pos.y()+1)) { for(ivec2 pos(0,0); pos.y()<dataImage.getHeight(); pos.setY(pos.y()+1)) {
@ -1522,7 +1519,6 @@ class WAYLANDInterface : public gale::Context {
myImage->data = nullptr; myImage->data = nullptr;
XDestroyImage(myImage); XDestroyImage(myImage);
delete[] tmpVal;
#endif #endif
*/ */
} }

View File

@ -747,8 +747,9 @@ bool gale::openGL::deleteBuffers(etk::Vector<uint32_t>& _buffers) {
#ifdef GALE_BUILD_SIMULATION #ifdef GALE_BUILD_SIMULATION
if (s_simulationMode == false) { if (s_simulationMode == false) {
#endif #endif
//glDeleteBuffers(_buffers.size(), &_buffers[0]); // TODO: Check if we are in the correct thread
//CHECK_GL_ERROR("glDeleteBuffers", __LINE__); glDeleteBuffers(_buffers.size(), &_buffers[0]);
CHECK_GL_ERROR("glDeleteBuffers", __LINE__);
#ifdef GALE_BUILD_SIMULATION #ifdef GALE_BUILD_SIMULATION
} }
#endif #endif
@ -860,8 +861,9 @@ void gale::openGL::shader::remove(int64_t& _shader) {
#ifdef GALE_BUILD_SIMULATION #ifdef GALE_BUILD_SIMULATION
if (s_simulationMode == false) { if (s_simulationMode == false) {
#endif #endif
//glDeleteShader(GLuint(_shader)); // TODO: Check if we are in the correct thread
//CHECK_GL_ERROR("glDeleteShader", __LINE__); glDeleteShader(GLuint(_shader));
CHECK_GL_ERROR("glDeleteShader", __LINE__);
#ifdef GALE_BUILD_SIMULATION #ifdef GALE_BUILD_SIMULATION
} }
#endif #endif
@ -926,8 +928,9 @@ void gale::openGL::program::remove(int64_t& _prog) {
#ifdef GALE_BUILD_SIMULATION #ifdef GALE_BUILD_SIMULATION
if (s_simulationMode == false) { if (s_simulationMode == false) {
#endif #endif
//glDeleteProgram(GLuint(_prog)); // TODO: Check if we are in the correct thread
//CHECK_GL_ERROR("glDeleteProgram", __LINE__); glDeleteProgram(GLuint(_prog));
CHECK_GL_ERROR("glDeleteProgram", __LINE__);
#ifdef GALE_BUILD_SIMULATION #ifdef GALE_BUILD_SIMULATION
} }
#endif #endif

View File

@ -341,11 +341,11 @@ void gale::resource::Program::reload() {
} }
// remove previous data ... // remove previous data ...
if (m_fileData != nullptr) { if (m_fileData != nullptr) {
delete[] m_fileData; del ete[] m_fileData;
m_fileData = 0; m_fileData = 0;
} }
// allocate data // allocate data
m_fileData = new char[fileSize+5]; m_fileData = ne w char[fileSize+5];
if (m_fileData == nullptr) { if (m_fileData == nullptr) {
GALE_ERROR("Error Memory allocation size=" << fileSize); GALE_ERROR("Error Memory allocation size=" << fileSize);
return; return;

View File

@ -15,7 +15,7 @@
#define DECLARE_RESOURCE_FACTORY(className) \ #define DECLARE_RESOURCE_FACTORY(className) \
template<typename ... GALE_TYPE> static ememory::SharedPtr<className> create( GALE_TYPE&& ... _all ) { \ template<typename ... GALE_TYPE> static ememory::SharedPtr<className> create( GALE_TYPE&& ... _all ) { \
ememory::SharedPtr<className> resource(new className()); \ ememory::SharedPtr<className> resource(ETK_NEW(className)); \
if (resource == nullptr) { \ if (resource == nullptr) { \
GALE_ERROR("Factory resource error"); \ GALE_ERROR("Factory resource error"); \
return nullptr; \ return nullptr; \
@ -43,7 +43,7 @@
} \ } \
return resource; \ return resource; \
} \ } \
resource = ememory::SharedPtr<className>(new className()); \ resource = ememory::SharedPtr<className>(ETK_NEW(className)); \
if (resource == nullptr) { \ if (resource == nullptr) { \
GALE_ERROR("allocation error of a resource : " << _name); \ GALE_ERROR("allocation error of a resource : " << _name); \
return nullptr; \ return nullptr; \
@ -70,7 +70,7 @@
if (resource != nullptr) { \ if (resource != nullptr) { \
return resource; \ return resource; \
} \ } \
resource = ememory::SharedPtr<className>(new className()); \ resource = ememory::SharedPtr<className>(ETK_NEW(className)); \
if (resource == nullptr) { \ if (resource == nullptr) { \
GALE_ERROR("allocation error of a resource : " << uniqueName); \ GALE_ERROR("allocation error of a resource : " << uniqueName); \
return nullptr; \ return nullptr; \
@ -150,7 +150,7 @@ namespace gale {
protected: protected:
/** /**
* @brief Add a type of the list of Object. * @brief Add a type of the list of Object.
* @param[in] _type new type to add. * @param[in] _type Type to add.
*/ */
void addResourceType(const char* _type); void addResourceType(const char* _type);
protected: protected:
@ -165,7 +165,7 @@ namespace gale {
}; };
/** /**
* @brief get the resource name * @brief get the resource name
* @param[in] _name The new name * @param[in] _name The name to set.
*/ */
void setName(const etk::String& _name) { void setName(const etk::String& _name) {
m_name = _name; m_name = _name;

View File

@ -45,7 +45,7 @@ gale::resource::Texture::Texture() :
m_size(0,0), m_size(0,0),
m_dataType(gale::resource::Texture::dataType::int16), m_dataType(gale::resource::Texture::dataType::int16),
m_dataColorSpace(gale::resource::Texture::color::mono) { m_dataColorSpace(gale::resource::Texture::color::mono) {
addResourceType("gale::compositing::Texture"); addResourceType("gale::resource::Texture");
} }
gale::resource::Texture::~Texture() { gale::resource::Texture::~Texture() {
@ -58,7 +58,7 @@ bool gale::resource::Texture::updateContext() {
//Lock error ==> try later ... //Lock error ==> try later ...
return false; return false;
} }
if (false == m_loaded) { if (m_loaded == false) {
// Request a new texture at openGl : // Request a new texture at openGl :
glGenTextures(1, &m_texId); glGenTextures(1, &m_texId);
} }
@ -94,7 +94,8 @@ void gale::resource::Texture::removeContext() {
if (true == m_loaded) { if (true == m_loaded) {
// Request remove texture ... // Request remove texture ...
GALE_INFO("TEXTURE: Rm [" << getId() << "] texId=" << m_texId); GALE_INFO("TEXTURE: Rm [" << getId() << "] texId=" << m_texId);
//glDeleteTextures(1, &m_texId); // TODO: Check if we are in the correct thread
glDeleteTextures(1, &m_texId);
m_loaded = false; m_loaded = false;
} }
} }

View File

@ -147,7 +147,7 @@ class MainApplication : public gale::Application {
* @return std IO * @return std IO
*/ */
int main(int _argc, const char *_argv[]) { int main(int _argc, const char *_argv[]) {
return gale::run(new MainApplication(), _argc, _argv); return gale::run(ETK_NEW(appl::MainApplication)(), _argc, _argv);
} }
//! [gale_declare_main] //! [gale_declare_main]