bool ItemAttribute::unserialize(PropStream& stream) { // dealloc possible string value dealloc(); // read type stream.GET_UCHAR(reinterpret_cast<uint8_t&>(m_type)); // do not call here set(...) or any other function depending on m_type which may result in deallocating phantom string ! // read contents switch(m_type){ case STRING: { m_var.string = new std::string; if(!stream.GET_LSTRING(*m_var.string)) return false; break; } case INTEGER: case FLOAT: { if(!stream.GET_ULONG(m_var.unsignedInteger)) return false; break; } case BOOLEAN: { if(!stream.GET_UCHAR(m_var.unsignedChar)) return false; break; } default: { m_type = NONE; break; } } return true; }