[osg-users] OpenSceneGraph for Beginners tutorial help requested

127 views
Skip to first unread message

Seth Hays

unread,
Oct 28, 2012, 9:47:35 PM10/28/12
to osg-...@lists.openscenegraph.org
Hi,

I've been working with the OSG Beginners book. I am trying to get the first program to run but I continually get a bad alloc error:

Code:

Microsoft C++ exception: std::bad_alloc at memory location 0x00a1d4f0..




The break point is:

Code:

inline osg::Node* readNodeFile(const std::string& filename)
{
return readNodeFile(filename,Registry::instance()->getOptions());
}




And the following is my code:

Code:

#include <osgDB/ReadFile>
#include <osgViewer/Viewer>

int main( int argc, char** argv ) {
osg::ref_ptr<osg::Node> root = osgDB::readNodeFile("c:\\osg\\data\\cessna.osg");
osgViewer::Viewer viewer;
viewer.setSceneData( root.get() );
return viewer.run();
}




Any hints would be fantastic.


Thank you!

Cheers,
Seth

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=50843#50843





_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Wuerfel, Hannes

unread,
Oct 30, 2012, 7:23:50 AM10/30/12
to osg-...@lists.openscenegraph.org
Hey,

I've encountered the same problem some time ago.
The problem was the macro in the CMakeLists.txt. On my system it hast to be "_INCLUDE_DIRS" and "_LIBRARIES".
Try this osg-cmake project setup:

cmake_minimum_required(VERSION 2.8)
project(MyProject)
set(target MyProject)

find_package(OpenSceneGraph REQUIRED
osgAnimation
osgDB
osgGA
osgText
osgUtil
osgViewer
osgShadow
osgParticle
)

set(sources
src/main.cpp
)

include_directories(
${OPENSCENEGRAPH_INCLUDE_DIRS}
)

add_executable(${target} ${sources})

target_link_libraries(${target}
${OSG_LIBRARIES}
${OSGANIMATION_LIBRARIES}
${OSGDB_LIBRARIES}
${OSGGA_LIBRARIES}
${OSGTEXT_LIBRARIES}
${OSGUTIL_LIBRARIES}
${OSGVIEWER_LIBRARIES}
${OPENTHREADS_LIBRARIES}
${OSGSHADOW_LIBRARIES}
${OSGPARTICLE_LIBRARIES}
)

Also if you built osg from source and ran the install target, make sure your OSG_DIR env variable point to your install directory specified in the cmake-gui (e.g. c:/lib/osg/install), otherwise cmake could include the wrong header files.
Hope this helps.
________________________________________
Von: osg-user...@lists.openscenegraph.org [osg-user...@lists.openscenegraph.org] im Auftrag von Seth Hays [hays...@gmail.com]
Gesendet: Montag, 29. Oktober 2012 02:47
An: osg-...@lists.openscenegraph.org
Betreff: [osg-users] OpenSceneGraph for Beginners tutorial help requested

Tueller, Shayne R Civ USAF AFMC 519 SMXS/MXDEC

unread,
Oct 30, 2012, 11:08:27 AM10/30/12
to osg-...@lists.openscenegraph.org
Another thing to check is make sure you're not mixing debug version of
OSG with a release version of your app and vice versa. They must be the
same.

I've had readNodeFile() fail as below when I accidently linked my
release built app with debug OSG...

-Shayne

-----Original Message-----
From: osg-user...@lists.openscenegraph.org
[mailto:osg-user...@lists.openscenegraph.org] On Behalf Of Seth
Hays
Sent: Sunday, October 28, 2012 7:48 PM
To: osg-...@lists.openscenegraph.org
Subject: [osg-users] OpenSceneGraph for Beginners tutorial help
requested

Seth Hays

unread,
Oct 30, 2012, 11:42:01 PM10/30/12
to osg-...@lists.openscenegraph.org
Thanks for the feed back.

I tried the new CMakeList.txt file provided without much luck. I changed it back and then double checked that I was using the release version (the version without the d's at the end) and that is correct. I have the precompiled version for win x64 and my environment variable OSG_ROOT points to c:\osg

My bin lib and include files are c:\osg\bin, c:\osg\lib, and c:\osg\include respectively. Now I am getting a new error however.


Code:

2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class osg::Node * __cdecl osgDB::readNodeFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class osgDB::Options const *)" (__imp_?readNodeFile@osgDB@@YAPAVNode@osg@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PBVOptions@1@@Z) referenced in function "class osg::Node * __cdecl osgDB::readNodeFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?readNodeFile@osgDB@@YAPAVNode@osg@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class osgDB::Options * __thiscall osgDB::Registry::getOptions(void)" (__imp_?getOptions@Registry@osgDB@@QAEPAVOptions@2@XZ) referenced in function "class osg::Node * __cdecl osgDB::readNodeFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?readNodeFile@osgDB@@YAPAVNode@osg@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class osgDB::Registry * __cdecl osgDB::Registry::instance(bool)" (__imp_?instance@Registry@osgDB@@SAPAV12@_N@Z) referenced in function "class osg::Node * __cdecl osgDB::readNodeFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?readNodeFile@osgDB@@YAPAVNode@osg@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall OpenThreads::Atomic::operator++(void)" (__imp_??EAtomic@OpenThreads@@QAEIXZ) referenced in function "public: __thiscall osg::ref_ptr<class osg::Node>::ref_ptr<class osg::Node>(class osg::Node *)" (??0?$ref_ptr@VNode@osg@@@osg@@QAE@PAVNode@1@@Z)
2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall osg::Referenced::unref(void)const " (__imp_?unref@Referenced@osg@@QBEHXZ) referenced in function "public: __thiscall osg::ref_ptr<class osg::Node>::~ref_ptr<class osg::Node>(void)" (??1?$ref_ptr@VNode@osg@@@osg@@QAE@XZ)
2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall osgViewer::Viewer::`vbase destructor'(void)" (__imp_??_DViewer@osgViewer@@QAEXXZ) referenced in function __unwindfunclet$_main$0
2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) protected: virtual __thiscall osg::Object::~Object(void)" (__imp_??1Object@osg@@MAE@XZ) referenced in function _main
2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall osgViewer::Viewer::~Viewer(void)" (__imp_??1Viewer@osgViewer@@UAE@XZ) referenced in function _main
2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual int __thiscall osgViewer::Viewer::run(void)" (__imp_?run@Viewer@osgViewer@@UAEHXZ) referenced in function _main
2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual void __thiscall osgViewer::Viewer::setSceneData(class osg::Node *)" (__imp_?setSceneData@Viewer@osgViewer@@UAEXPAVNode@osg@@@Z) referenced in function _main
2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall osgViewer::Viewer::Viewer(void)" (__imp_??0Viewer@osgViewer@@QAE@XZ) referenced in function _main




Do I need a special envrionment variable for the dll's? I've tried to put them into the Working Directory under Debugging in the properties but that doesn't help.
Cheers,
Seth[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=50902#50902
Reply all
Reply to author
Forward
0 new messages