HI Guiseppe,

I haven't heard of others tackling Blackberry with the OSG yet, so
your working right on the bleeding edge so discovering new problems
that will need to worked through.  The ApplicationUsage singleton is
initialized by the first call to it's instance() method, perhaps
multi-threaded static initialization is happening and causing
problems.  Other singletons in the OSG with have to add an explicit
initialization local to the instance() method to force an
initialization to avoid theading issues, perhaps this might be worth
doing here.   The aid with this I wrote a OSG_INIT_SINGLETON_PROXY
#define

I've added usage of this #define as below.  I've also attached the
modified ApplicationUsage.cpp. The modified file is from svn/trunk but
is identical to the one in the OSG-3.2 so it should apply directly.

Could you test this, if it works I'll check it into svn/trunk and the
OSG-3.2 branch.

Robert.


$ svn diff
Index: ApplicationUsage.cpp
===================================================================
--- ApplicationUsage.cpp        (revision 14306)
+++ ApplicationUsage.cpp        (working copy)
@@ -15,6 +15,7 @@
 #include <string.h>

 #include <osg/ApplicationUsage>
+#include <osg/Object>
 #include <osg/Math>
 #include <osg/ref_ptr>

@@ -33,6 +34,8 @@
     return s_applicationUsage.get();
 }

+OSG_INIT_SINGLETON_PROXY(ApplicationUsageSingletonProxy,
ApplicationUsage::instance())
+
 void ApplicationUsage::addUsageExplanation(Type type,const
std::string& option,const std::string& explanation)
 {
     switch(type)
@@ -69,7 +72,7 @@
     {
         std::ostringstream ostr;
         ostr<<prefix;
-
+
         if (key==' ')
         {
             ostr<<"Space";


On 27 June 2014 07:19, Giuseppe Amaro <geme...@hotmail.de> wrote:
> Hi,
>
> I would like to develop Apps with OSG and Qt for BlackBerry10 devices.
> I've built OSG for BlackBerry10 using the CMake GUI and the ARM toolchain 
> which is provided by the BlackBerry Native SDK. In CMake, I added
>         the include path and the library of GDAL which I also built from 
> source with the ARM toolchain
>
>         GLESv1 (I've used the settings as descibed in the OSG Wiki)
>
>         Qt4 dependencies. Therefor I've used the already existing Qt 
> libraries which are preinstalled on BlackBerry10
>
>         the zlib include directory and library
>
> Further CMake configuration I set:
>         BUILD_OPENTHREADS_WITH_QT: ON
>
>         OSG_WINDOWING_SYSTEM: Qt
>
>         CMAKE_EXE_LINKER_FLAGS: -V4.6.3,gcc_ntoarmv7le -g -O0 -Y_gpp 
> -D__QNX__ -D_QT -fstack-protector-strong
>
> The Toolchain:
>         CMAKE_AR: ntoarm-ar.exe
>
>         CMAKE_ASM_COMPILER: qcc.exe
>
>         CMAKE_CXX_COMPILER: gcc.exe
>
>         CMAKE_C_COMPILER: gcc.exe
>
>         CMAKE_LINKER: ntoarmv7-ld.exe
>
>         CMAKE_NM: ntoarmv7-nm.exe
>
>         CMAKE_OBJCOPY: ntoarmv7-objcopy.exe
>
>         CMAKE_OBJDUMP: ntoarmv7-objdump.exe
>
>         CMAKE_RANLIB: ntoarm-ranlib.exe
>
>         CMAKE_STRIP: ntoarm-strip.exe
>
>
> When I run following simple code the app crashes immediately.
>
> Code:
>
> #include <bb/cascades/Application>
>
> #include <QLocale>
> #include <QTranslator>
> #include "applicationui.hpp"
>
> #include <Qt/qdeclarativedebug.h>
> #include <osgViewer/CompositeViewer>
>
> using namespace bb::cascades;
>
> class ViewerWidget : public osgViewer::CompositeViewer
> {
>
> };
>
> Q_DECL_EXPORT int main(int argc, char **argv)
> {
>     Application app(argc, argv);
>
>     // Create the Application UI object, this is where the main.qml file
>     // is loaded and the application scene is set.
>     new ApplicationUI(&app);
>     osgViewer::CompositeViewer vWidget;
>
>     // Enter the application main event loop.
>     return Application::exec();
> }
>
>
>
> I don't get any error messages. In debugging mode, the back trace gives me 
> following information:
>         #0  0x016634ac in SignalKill () from 
> C:\bbndk\runtime_10_2_1_3175\qnx6\armle-v7\lib\libc.so.3
>
>         #1  0x01652c68 in raise () from 
> C:\bbndk\runtime_10_2_1_3175\qnx6\armle-v7\lib\libc.so.3
>
>         #2  0x01690668 in __ssp_fail () from 
> C:\bbndk\runtime_10_2_1_3175\qnx6\armle-v7\lib\libc.so.3
>
>         #3  0x080b6f66 in std::map<std::string, std::string, 
> std::less<std::string>, std::allocator<std::pair<std::string const, 
> std::string> > >::operator
> [] (this=0x922e474, __k=...) at 
> C:/bbndk/target_10_2_0_1155/qnx6/usr/include/c++/4.6.3/bits/stl_map.h:455
>         #4  0x0820cf76 in osg::ApplicationUsage::addEnvironmentalVariable 
> (this=<error reading variable: Cannot access memory at address 0x1b>, 
> option=<error reading variable: Cannot access memory at address 0x17>, 
> explanation=<error reading variable: Cannot access memory at address 0x13>, 
> defaultValue=<error reading variable: Cannot access memory at address 0xf>) 
> at 
> C:\Project\OpenSceneGraph-3.2.0\OpenSceneGraph\src\osg\ApplicationUsage.cpp:69
>
>         Backtrace stopped: previous frame inner to this frame (corrupt stack?)
>
>
> It seems like there must be a memory corruption somewhere. Since the debugger 
> never reaches main, it is very hard to me to find the issue.
> Does anybody have an idea? Please let me know if you need more information.
>
> I would greatly appreciate any help!
>
>
> Thank you!
>
> Cheers,
> Giuseppe
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=59973#59973
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
 *
 * This library is open source and may be redistributed and/or modified under
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * OpenSceneGraph Public License for more details.
*/

#include <stdlib.h>
#include <string.h>

#include <osg/ApplicationUsage>
#include <osg/Object>
#include <osg/Math>
#include <osg/ref_ptr>

#include <sstream>

using namespace osg;

ApplicationUsage::ApplicationUsage(const std::string& commandLineUsage):
    _commandLineUsage(commandLineUsage)
{
}

ApplicationUsage* ApplicationUsage::instance()
{
    static osg::ref_ptr<ApplicationUsage> s_applicationUsage = new ApplicationUsage;
    return s_applicationUsage.get();
}

OSG_INIT_SINGLETON_PROXY(ApplicationUsageSingletonProxy, ApplicationUsage::instance())

void ApplicationUsage::addUsageExplanation(Type type,const std::string& option,const std::string& explanation)
{
    switch(type)
    {
        case(COMMAND_LINE_OPTION):
            addCommandLineOption(option,explanation);
            break;
        case(ENVIRONMENTAL_VARIABLE):
            addEnvironmentalVariable(option,explanation);
            break;
        case(KEYBOARD_MOUSE_BINDING):
            //addKeyboardMouseBinding(option,explanation);
            break;
        default:
            break;
    }
}

void ApplicationUsage::addCommandLineOption(const std::string& option,const std::string& explanation,const std::string& defaultValue)
{
    _commandLineOptions[option]=explanation;
    _commandLineOptionsDefaults[option]=defaultValue;
}

void ApplicationUsage::addEnvironmentalVariable(const std::string& option,const std::string& explanation, const std::string& defaultValue)
{
    _environmentalVariables[option]=explanation;
    _environmentalVariablesDefaults[option]=defaultValue;
}

void ApplicationUsage::addKeyboardMouseBinding(const std::string& prefix, int key, const std::string& explanation)
{
    if (key!=0)
    {
        std::ostringstream ostr;
        ostr<<prefix;

        if (key==' ')
        {
            ostr<<"Space";
        }
        else if (key!=0)
        {
            ostr<<char(key);
        }

        _keyboardMouse[ostr.str()]=explanation;
    }
}


void ApplicationUsage::addKeyboardMouseBinding(int key,const std::string& explanation)
{
    addKeyboardMouseBinding("",key,explanation);
}

void ApplicationUsage::addKeyboardMouseBinding(const std::string& option,const std::string& explanation)
{
    _keyboardMouse[option]=explanation;
}

void ApplicationUsage::getFormattedString(std::string& str, const UsageMap& um,unsigned int widthOfOutput,bool showDefaults,const UsageMap& ud)
{

    unsigned int maxNumCharsInOptions = 0;
    ApplicationUsage::UsageMap::const_iterator citr;
    for(citr=um.begin();
        citr!=um.end();
        ++citr)
    {
        maxNumCharsInOptions = maximum(maxNumCharsInOptions,(unsigned int)citr->first.length());
    }


    unsigned int fullWidth = widthOfOutput;
    unsigned int optionPos = 2;
    unsigned int explanationPos = optionPos+maxNumCharsInOptions+2;

    double ratioOfExplanationToOutputWidth = float(explanationPos)/float(widthOfOutput);
    double maxRatioOfExplanationToOutputWidth = 0.25f;

    if (ratioOfExplanationToOutputWidth > maxRatioOfExplanationToOutputWidth)
    {
        explanationPos = static_cast<unsigned int>(maxRatioOfExplanationToOutputWidth*float(widthOfOutput));
    }

    unsigned int defaultPos = 0;
    if (showDefaults)
    {
        defaultPos = explanationPos;
        explanationPos = optionPos+8;
    }
    unsigned int explanationWidth = fullWidth-explanationPos;

    std::string line;

    for(citr=um.begin();
        citr!=um.end();
        ++citr)
    {
        line.assign(fullWidth,' ');
        line.replace(optionPos,citr->first.length(),citr->first);
        unsigned int currentEndPos = optionPos + citr->first.length();

        if (showDefaults)
        {

            UsageMap::const_iterator ditr = ud.find(citr->first);
            if (ditr != ud.end())
            {
                if (currentEndPos+1>=defaultPos)
                {
                    str += line; str += "\n";
                    line.assign(fullWidth,' ');
                }

                line.replace(defaultPos, std::string::npos, "");
                if (ditr->second != "")
                {
                    line += "[";
                    line += ditr->second;
                    line += "]";
                }
                str += line;
                str += "\n";
                line.assign(fullWidth,' ');

                currentEndPos =  0;
            }
        }

        const std::string& explanation = citr->second;
        std::string::size_type pos = 0;
        std::string::size_type offset = 0;
        bool firstInLine = true;
        if (!explanation.empty())
        {

            if (currentEndPos+1>explanationPos)
            {
                str += line; str += "\n";
                line.assign(fullWidth,' ');
            }

            while (pos<explanation.length())
            {
                if (firstInLine) offset = 0;

                // skip any leading white space.
                while (pos<explanation.length() && explanation[pos]==' ')
                {
                    if (firstInLine) ++offset;
                    ++pos;
                }

                firstInLine = false;

                std::string::size_type width = minimum((std::string::size_type)(explanation.length()-pos),(std::string::size_type)(explanationWidth-offset));
                std::string::size_type slashn_pos = explanation.find('\n',pos);

                unsigned int extraSkip = 0;
                bool concatinated = false;
                if (slashn_pos!=std::string::npos)
                {
                    if (slashn_pos<pos+width)
                    {
                        width = slashn_pos-pos;
                        ++extraSkip;
                        firstInLine = true;
                    }
                    else if (slashn_pos==pos+width)
                    {
                        ++extraSkip;
                        firstInLine = true;
                    }
                }

                if (pos+width<explanation.length())
                {
                    // now reduce width until we get a space or a return
                    // so that we ensure that whole words are printed.
                    while (width>0 &&
                           explanation[pos+width]!=' ' &&
                           explanation[pos+width]!='\n') --width;

                    if (width==0)
                    {
                        // word must be longer than a whole line so will need
                        // to concatenate it.
                        width = explanationWidth-1;
                        concatinated = true;
                    }
                }

                line.replace(explanationPos+offset,explanationWidth, explanation, pos, width);

                if (concatinated) { str += line; str += "-\n"; }
                else { str += line; str += "\n"; }

                // move to the next line of output.
                line.assign(fullWidth,' ');

                pos += width+extraSkip;

            }
        }
        else
        {
            str += line; str += "\n";
        }
    }
}

void ApplicationUsage::write(std::ostream& output, const ApplicationUsage::UsageMap& um,unsigned int widthOfOutput,bool showDefaults,const ApplicationUsage::UsageMap& ud)
{
    std::string str;
    getFormattedString(str, um, widthOfOutput, showDefaults, ud);
    output << str << std::endl;
}

void ApplicationUsage::write(std::ostream& output, unsigned int type, unsigned int widthOfOutput, bool showDefaults)
{

    output << "Usage: "<<getCommandLineUsage()<<std::endl;
    bool needspace = false;
    if ((type&COMMAND_LINE_OPTION) && !getCommandLineOptions().empty())
    {
        output << "Options";
        if (showDefaults) output << " [and default value]";
        output << ":"<<std::endl;
        write(output,getCommandLineOptions(),widthOfOutput,showDefaults,getCommandLineOptionsDefaults());
        needspace = true;
    }

    if ((type&ENVIRONMENTAL_VARIABLE) && !getEnvironmentalVariables().empty())
    {
        if (needspace) output << std::endl;
        output << "Environmental Variables";
        if (showDefaults) output << " [and default value]";
        output << ":"<<std::endl;
        write(output,getEnvironmentalVariables(),widthOfOutput,showDefaults,getEnvironmentalVariablesDefaults());
        needspace = true;
    }

    if ((type&KEYBOARD_MOUSE_BINDING) && !getKeyboardMouseBindings().empty())
    {
        if (needspace) output << std::endl;
        output << "Keyboard and Mouse Bindings:"<<std::endl;
        write(output,getKeyboardMouseBindings(),widthOfOutput);
        needspace = true;
    }

}


void ApplicationUsage::writeEnvironmentSettings(std::ostream& output)
{
    output << "Current Environment Settings:"<<std::endl;

    unsigned int maxNumCharsInOptions = 0;
    ApplicationUsage::UsageMap::const_iterator citr;
    for(citr=getEnvironmentalVariables().begin();
        citr!=getEnvironmentalVariables().end();
        ++citr)
    {
        std::string::size_type len = citr->first.find_first_of("\n\r\t ");
        if (len == std::string::npos) len = citr->first.size();
        maxNumCharsInOptions = maximum( maxNumCharsInOptions,static_cast<unsigned int>(len));
    }

    unsigned int optionPos = 2;
    std::string line;

    for(citr=getEnvironmentalVariables().begin();
        citr!=getEnvironmentalVariables().end();
        ++citr)
    {
        line.assign(optionPos+maxNumCharsInOptions+2,' ');
        std::string::size_type len = citr->first.find_first_of("\n\r\t ");
        if (len == std::string::npos) len = citr->first.size();
        line.replace(optionPos,len,citr->first.substr(0,len));
        const char *cp = getenv(citr->first.substr(0, len).c_str());
        if (!cp) cp = "[not set]";
        else if (!*cp) cp = "[set]";
        line += std::string(cp) + "\n";

        output << line;
    }
    output << std::endl;
}
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to