Problem cf.load(m_ResourcePath + "resources.cfg")

 

Postbywilsonwing » Sat Mar 21, 2009 7:22 am

I got a strange problem.
I am using Visual Studio 2005 SP1, Ogre 1.60, build my project with no errors.
But when I run the appication after build(in Visual Studio, ctrl + F5), I got crash at this line
Code: Select all
cf.load(m_ResourcePath + "resources.cfg");

and run into output.c (looks like a windows file...)
Code: Select all
#else  /* _UNICODE */
                if (flags & (FL_LONG|FL_WIDECHAR)) {
                    if (text.wz == NULL) /* NULL passed, use special string */
                        text.wz = __wnullstring;
                    bufferiswide = 1;
                    pwch = text.wz;
                    while ( i-- && *pwch )
                        ++pwch;
                    textlen = (int)(pwch - text.wz);
                    /* textlen now contains length in wide chars */
                } else {
                    if (text.sz == NULL) /* NULL passed, use special string */
                        text.sz = __nullstring;
                    p = text.sz;
                    while (i-- && *p)                                 /// <-- crash here
                        ++p;
                    textlen = (int)(p - text.sz);    /* length of the string */
                }


But if I close Visual Studio and just go to the bin/release folder, double click the .exe, It can run with no crashes....
I hope someone can help me with this.
Because I can build project but cannot debug it, this is difficult to me :(
wilsonwing
Halfling
Posts: 63
Kudos: 1
Joined: 14 Jan 2008
Location: Taipei Taiwan
Top

Re: Problem cf.load(m_ResourcePath + "resources.cfg")

Postbysyedhs » Sun Mar 22, 2009 7:58 am

This is a common problem.

You have to understand what is the 'application path' or 'working directory' when running in VS IDE vs running it yourself ie double clicking the executable. The working directory when running it by double clicking is the executable directory itself. The working directory when running inside your VS IDE is the path of your <project>.vcproj. So this is the main reason why your app can't find the file because the executable location is different now. I always set the working directory by right-clicking on the project, and choose setting (or simply Alt+F7). Choose 'Debugging' under 'Configuration Properties', type in the proper working directory.
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2378
Kudos: 18
Joined: 29 Aug 2005
Location: Kuala Lumpur, Malaysia
Top

Re: Problem cf.load(m_ResourcePath + "resources.cfg")

Postbywilsonwing » Sun Mar 22, 2009 8:25 am

syedhs wrote:This is a common problem.
I always set the working directory by right-clicking on the project, and choose setting (or simply Alt+F7). Choose 'Debugging' under 'Configuration Properties', type in the proper working directory.

Thanks for your help :D
This is what i do, my .exe is locate under E:\GameProject\bin\release\ [GameProject].exe
I do as you said, and put    E:\GameProject\bin\release\ [GameProject].exe   to the work directory, doesn't work. :?
ps.
This project was original write on the other computer, for some reason I have to move it to the computer I am using now.
It has no problem with the origin one.
Image
Image

And the program actually runs a little bit..
Code: Select all
bool OgreNewtonApplication::setup() //almost the same as ExampleApplication in the wiki
{
   String pluginsPath;
   // only use plugins.cfg if not static
#ifndef OGRE_STATIC_LIB
   pluginsPath = m_ResourcePath + "plugins.cfg";
#endif

   //Ogre Root
   m_pOgreRoot = new Root(pluginsPath, m_ResourcePath + "ogre.cfg", m_ResourcePath + "Ogre.log");


   setupResources();   
   
   .....
                .....
   return true;
}
void OgreNewtonApplication::setupResources()
{
   // Load resource paths from config file
   ConfigFile cf;
**********************************************************************************************************************************
**********************************************************************************************************************************
**********************************************************************************************************************************
**********************************************************************************************************************************
   cf.load(m_ResourcePath + "resources.cfg"); //<---crash until here (only crash when run in VS2005) **********************************************************************************************************************************
**********************************************************************************************************************************
**********************************************************************************************************************************
**********************************************************************************************************************************
**********************************************************************************************************************************

.....
.....
}
wilsonwing
Halfling
Posts: 63
Kudos: 1
Joined: 14 Jan 2008
Location: Taipei Taiwan
Top

Re: Problem cf.load(m_ResourcePath + "resources.cfg")

Postbysyedhs » Sun Mar 22, 2009 3:38 pm

Try changing working directory into 'E:\GameProject\bin\release\'
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2378
Kudos: 18
Joined: 29 Aug 2005
Location: Kuala Lumpur, Malaysia
Top

Re: Problem cf.load(m_ResourcePath + "resources.cfg")

Postbywilsonwing » Mon Mar 23, 2009 2:14 am

syedhs wrote: Try changing working directory into 'E:\GameProject\bin\release\'

Cool  , it works now:D
Thanks for helping me on this stupid problem :oops:
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值