Hi Jordi,

On 24 May 2013 17:40, Jordi Torres <[email protected]> wrote:
> There are still a couple of submissions pending w.r.t android devices.
> Specially one about the static variables initialization in Uniform.cpp from
> Jorge Izquierdo, without this fix the viewer in android won't run.

Thanks for the pointer. I've had a look through the submissions
associated with Android and merge one, but for the Uniform.cpp
submission I've decided to try out a simpler solution - move the
static's from global scope into th Uniform::getNameID() method and
then use the OSG_INIT_SINGLETON_PROXY to force a call to the
getNameID() method.   I used this approach as I keeps the code simple
without needing to create another singleton class simply to get around
this platform specific issue.

The code now looks like:

unsigned int Uniform::getNameID(const std::string& name)
{
    typedef std::map<std::string, unsigned int> UniformNameIDMap;
    static OpenThreads::Mutex s_mutex_uniformNameIDMap;
    static UniformNameIDMap s_uniformNameIDMap;

    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_uniformNameIDMap);
    UniformNameIDMap::iterator it = s_uniformNameIDMap.find(name);
    if (it != s_uniformNameIDMap.end())
    {
        return it->second;
    }
    unsigned int id = s_uniformNameIDMap.size();
    s_uniformNameIDMap.insert(UniformNameIDMap::value_type(name, id));
    return id;
}

// Use a proxy to force the initialization of the static variables in
the Unifrom::getNameID() method during static initialization
OSG_INIT_SINGLETON_PROXY(UniformNameIDStaticInitializationProxy,
Uniform::getNameID(std::string()))

This change is now checked into svn/trunk.  Could you test it out and
let me know if there is any remaining problems?


Robert.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to