correction of the segFault bug with Resources
This commit is contained in:
parent
5d2000e952
commit
fd86f42454
@ -657,6 +657,7 @@ namespace etk
|
|||||||
if (requestSize == m_allocated) {
|
if (requestSize == m_allocated) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//TK_INFO("Change vector allocation : " << m_allocated << "==>" << requestSize);
|
||||||
// check if something is allocated :
|
// check if something is allocated :
|
||||||
if (NULL == m_data) {
|
if (NULL == m_data) {
|
||||||
// no data allocated ==> request an allocation (might be the first)
|
// no data allocated ==> request an allocation (might be the first)
|
||||||
|
@ -41,7 +41,7 @@ namespace ewol
|
|||||||
virtual ~Resource(void) { };
|
virtual ~Resource(void) { };
|
||||||
virtual bool HasName(etk::UString& fileName)
|
virtual bool HasName(etk::UString& fileName)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("check : " << fileName << " ?= " << m_name << " = " << (fileName==m_name) );
|
EWOL_VERBOSE("G : check : " << fileName << " ?= " << m_name << " = " << (fileName==m_name) );
|
||||||
return fileName==m_name;
|
return fileName==m_name;
|
||||||
};
|
};
|
||||||
virtual etk::UString GetName(void) { return m_name; };
|
virtual etk::UString GetName(void) { return m_name; };
|
||||||
|
@ -56,8 +56,7 @@ void ewol::resource::UnInit(void)
|
|||||||
// internal generic keeper ...
|
// internal generic keeper ...
|
||||||
static ewol::Resource* LocalKeep(etk::UString& filename)
|
static ewol::Resource* LocalKeep(etk::UString& filename)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("KEEP : DEFAULT : file : \"" << filename << "\"");
|
EWOL_VERBOSE("KEEP (DEFAULT) : file : \"" << filename << "\"");
|
||||||
//for (int32_t iii=l_resourceList.Size()-1; iii>=0; iii--) {
|
|
||||||
for (int32_t iii=0; iii<l_resourceList.Size(); iii++) {
|
for (int32_t iii=0; iii<l_resourceList.Size(); iii++) {
|
||||||
if (l_resourceList[iii] != NULL) {
|
if (l_resourceList[iii] != NULL) {
|
||||||
if(l_resourceList[iii]->HasName(filename)) {
|
if(l_resourceList[iii]->HasName(filename)) {
|
||||||
@ -70,11 +69,23 @@ static ewol::Resource* LocalKeep(etk::UString& filename)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// internal generic keeper ...
|
||||||
|
static void LocalAdd(ewol::Resource* object)
|
||||||
|
{
|
||||||
|
EWOL_VERBOSE("Add ... find empty slot");
|
||||||
|
for (int32_t iii=0; iii<l_resourceList.Size(); iii++) {
|
||||||
|
if (l_resourceList[iii] == NULL) {
|
||||||
|
l_resourceList[iii] = object;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
l_resourceList.PushBack(object);
|
||||||
|
}
|
||||||
|
|
||||||
// return the type of the resource ...
|
// return the type of the resource ...
|
||||||
bool ewol::resource::Keep(etk::UString& filename, ewol::TexturedFont*& object)
|
bool ewol::resource::Keep(etk::UString& filename, ewol::TexturedFont*& object)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("KEEP : TexturedFont : file : \"" << filename << "\"");
|
EWOL_VERBOSE("KEEP : TexturedFont : file : \"" << filename << "\"");
|
||||||
object = static_cast<ewol::TexturedFont*>(LocalKeep(filename));
|
object = static_cast<ewol::TexturedFont*>(LocalKeep(filename));
|
||||||
if (NULL != object) {
|
if (NULL != object) {
|
||||||
return true;
|
return true;
|
||||||
@ -85,14 +96,14 @@ bool ewol::resource::Keep(etk::UString& filename, ewol::TexturedFont*& object)
|
|||||||
EWOL_ERROR("allocation error of a resource : " << filename);
|
EWOL_ERROR("allocation error of a resource : " << filename);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
l_resourceList.PushBack(object);
|
LocalAdd(object);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ewol::resource::Keep(etk::UString& filename, ewol::Font*& object)
|
bool ewol::resource::Keep(etk::UString& filename, ewol::Font*& object)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("KEEP : Font : file : \"" << filename << "\"");
|
EWOL_VERBOSE("KEEP : Font : file : \"" << filename << "\"");
|
||||||
object = static_cast<ewol::Font*>(LocalKeep(filename));
|
object = static_cast<ewol::Font*>(LocalKeep(filename));
|
||||||
if (NULL != object) {
|
if (NULL != object) {
|
||||||
return true;
|
return true;
|
||||||
@ -103,14 +114,14 @@ bool ewol::resource::Keep(etk::UString& filename, ewol::Font*& object)
|
|||||||
EWOL_ERROR("allocation error of a resource : " << filename);
|
EWOL_ERROR("allocation error of a resource : " << filename);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
l_resourceList.PushBack(object);
|
LocalAdd(object);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ewol::resource::Keep(etk::UString& filename, ewol::Program*& object)
|
bool ewol::resource::Keep(etk::UString& filename, ewol::Program*& object)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("KEEP : Program : file : \"" << filename << "\"");
|
EWOL_VERBOSE("KEEP : Program : file : \"" << filename << "\"");
|
||||||
object = static_cast<ewol::Program*>(LocalKeep(filename));
|
object = static_cast<ewol::Program*>(LocalKeep(filename));
|
||||||
if (NULL != object) {
|
if (NULL != object) {
|
||||||
return true;
|
return true;
|
||||||
@ -121,14 +132,14 @@ bool ewol::resource::Keep(etk::UString& filename, ewol::Program*& object)
|
|||||||
EWOL_ERROR("allocation error of a resource : " << filename);
|
EWOL_ERROR("allocation error of a resource : " << filename);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
l_resourceList.PushBack(object);
|
LocalAdd(object);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ewol::resource::Keep(etk::UString& filename, ewol::Shader*& object)
|
bool ewol::resource::Keep(etk::UString& filename, ewol::Shader*& object)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("KEEP : Shader : file : \"" << filename << "\"");
|
EWOL_VERBOSE("KEEP : Shader : file : \"" << filename << "\"");
|
||||||
object = static_cast<ewol::Shader*>(LocalKeep(filename));
|
object = static_cast<ewol::Shader*>(LocalKeep(filename));
|
||||||
if (NULL != object) {
|
if (NULL != object) {
|
||||||
return true;
|
return true;
|
||||||
@ -139,7 +150,7 @@ bool ewol::resource::Keep(etk::UString& filename, ewol::Shader*& object)
|
|||||||
EWOL_ERROR("allocation error of a resource : " << filename);
|
EWOL_ERROR("allocation error of a resource : " << filename);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
l_resourceList.PushBack(object);
|
LocalAdd(object);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,6 +161,7 @@ void ewol::resource::Release(ewol::Resource*& object)
|
|||||||
EWOL_ERROR("Try to remove a resource that have null pointer ...");
|
EWOL_ERROR("Try to remove a resource that have null pointer ...");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
EWOL_VERBOSE("RELEASE (default) : file : \"" << object->GetName() << "\"");
|
||||||
for (int32_t iii=l_resourceList.Size()-1; iii>=0; iii--) {
|
for (int32_t iii=l_resourceList.Size()-1; iii>=0; iii--) {
|
||||||
if (l_resourceList[iii] != NULL) {
|
if (l_resourceList[iii] != NULL) {
|
||||||
if(l_resourceList[iii] == object) {
|
if(l_resourceList[iii] == object) {
|
||||||
@ -157,7 +169,7 @@ void ewol::resource::Release(ewol::Resource*& object)
|
|||||||
// delete element
|
// delete element
|
||||||
delete(l_resourceList[iii]);
|
delete(l_resourceList[iii]);
|
||||||
// remove element from the list :
|
// remove element from the list :
|
||||||
l_resourceList.Erase(iii);
|
l_resourceList[iii] = NULL;
|
||||||
}
|
}
|
||||||
// insidiously remove the pointer for the caller ...
|
// insidiously remove the pointer for the caller ...
|
||||||
object = NULL;
|
object = NULL;
|
||||||
|
@ -77,10 +77,9 @@ ewol::TexturedFont::TexturedFont(etk::UString fontName) :
|
|||||||
EWOL_CRITICAL("Can not parse the font name : \"" << fontName << "\" ==> size ???");
|
EWOL_CRITICAL("Can not parse the font name : \"" << fontName << "\" ==> size ???");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*tmpPos = '\0';
|
|
||||||
}
|
}
|
||||||
|
m_name = fontName.Extract(0, (tmpPos - tmpData));
|
||||||
m_size = tmpSize;
|
m_size = tmpSize;
|
||||||
m_name = tmpData;
|
|
||||||
//EWOL_CRITICAL("Load FONT name : \"" << m_name << "\" ==> size=" << m_size);
|
//EWOL_CRITICAL("Load FONT name : \"" << m_name << "\" ==> size=" << m_size);
|
||||||
ewol::resource::Keep(m_name, m_font);
|
ewol::resource::Keep(m_name, m_font);
|
||||||
if (NULL == m_font) {
|
if (NULL == m_font) {
|
||||||
@ -214,8 +213,8 @@ bool ewol::TexturedFont::HasName(etk::UString& fileName)
|
|||||||
etk::UString tmpName = m_name;
|
etk::UString tmpName = m_name;
|
||||||
tmpName += ":";
|
tmpName += ":";
|
||||||
tmpName += m_size;
|
tmpName += m_size;
|
||||||
EWOL_DEBUG("check : " << fileName << " ?= " << tmpName << " = " << (fileName==tmpName) );
|
EWOL_VERBOSE("S : check : " << fileName << " ?= " << tmpName << " = " << (fileName==tmpName) );
|
||||||
return fileName==tmpName;
|
return (fileName==tmpName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user