# Strange Issue with Wx\_Sugar and xml.load

**URL:** <https://www.ruby-forum.com/t/strange-issue-with-wx-sugar-and-xml-load/182648>\
**Category:** wxRuby\
**Created:** [February 1, 2010, 12:05am UTC](https://www.ruby-forum.com/t/strange-issue-with-wx-sugar-and-xml-load/182648 "2010-02-01T00:05:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [February 1, 2010, 12:05am UTC](https://www.ruby-forum.com/t/strange-issue-with-wx-sugar-and-xml-load/182648/1 "2010-02-01T00:05:52Z")

</div>

Hi everyone,

I’m having a strange issue and I’m trying to wrap my head around it and  
unfortunately, I’m not having much luck.

Let me simplify my directory structure and show you what’s happening:

\lib  
– app.rb  
– main.rb  
– xrc\_source.rb  
– xrc\_source.xrc

* * *

app.rb just contains some standard requires:

$:.unshift File.dirname( **FILE** )

require ‘wx’  
require ‘pp’  
require “xrc\_source”  
require “main”

Wx::App.run do  
GuiMain.new.show  
end

* * *

When the xrc\_source.rb is required, inside of xrc\_source.rb is the  
following line:

xml.load(‘xrc\_source’)

… which is automatically generated by running the xrcise command:

xrcise -o xrc\_source.rb xrc\_source.xrc

So Sugar is creating the load line. Now, so far so good. When I try to  
run my app out of the lib directory using ruby app.rb it launches and  
the gui is working just fine.

If I try to package this using ocra and type ocra app.rb it  
automatically creates an app.exe executable file. If I double-click the  
exe file, it launches and everything is good. Again, so far so good.

Now, if I move this new executable file anywhere else, and launch it, I  
receive the following error:

Cannot load resources from file ‘xrc\_source.xrc’.

========

So, does this mean that if I use wx\_sugar, I won’t be able to create a  
stand-a-lone GUI app with ocra? Notice, I’m not receiving any errors  
concerning any other loads or requires from my other files. The only  
error is occurring from the xml.load method inside of the file that was  
created via xrcise.

I’m sure there must be a way around this.

Please advise.

Thanks.

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [February 1, 2010, 12:22am UTC](https://www.ruby-forum.com/t/strange-issue-with-wx-sugar-and-xml-load/182648/2 "2010-02-01T00:22:28Z")

</div>

Just for clarification:

xml.load(‘xrc\_source’)

is actually xml.load(‘xrc\_source.xrc’)

I believe the problem is probably more related to something ocra is  
doing during compile so I added a bug report to the ocra home project  
page. If anyone else is using ocra with wxruby, and you are able to  
move the exe to another part of your system and launch it, please let me  
know what I’m doing wrong in terms of the xrc source load from sugar…

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [February 1, 2010, 2:41am UTC](https://www.ruby-forum.com/t/strange-issue-with-wx-sugar-and-xml-load/182648/3 "2010-02-01T02:41:20Z")

</div>

After reading Ocra’s website, it looks as though, if you want the  
xrc\_source.xrc to be included, you need to add it to the ocra command  
line  
execution, EG:

ocra app.rb xrc\_source.xrc

This will add xrc\_source.xrc to the executable, and when it extracts it,  
it’ll be placed into the same directory as your app.rb, so it should  
work  
then.

hth,

Mario

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [February 1, 2010, 3:00am UTC](https://www.ruby-forum.com/t/strange-issue-with-wx-sugar-and-xml-load/182648/4 "2010-02-01T03:00:55Z")

</div>

Mario S. wrote:

> After reading Ocra’s website, it looks as though, if you want the  
> xrc\_source.xrc to be included, you need to add it to the ocra command  
> line  
> execution, EG:
> 
> ocra app.rb xrc\_source.xrc
> 
> This will add xrc\_source.xrc to the executable, and when it extracts it,  
> it’ll be placed into the same directory as your app.rb, so it should  
> work  
> then.
> 
> hth,
> 
> Mario

Hey Mario,

I’m not sure how I missed that. I tried what you said and with the  
packager what happens is when I open the file on another part of the  
system, I receive the same error.

However, instead of closing the app and allowing it to fully close, I go  
to the temp directory within appdata and I personally checked out  
everything. There’s a src folder that shows that it is indeed pulling  
the xrc source and placing it in the same directory.

So, perhaps it has something to do with how it’s being required in the  
xml.load?

Should I be placing some other relative path? Again, a very strange  
thing as all of the files are there but it refuses to load the xrc  
source. The error usually happens when the path is not correct. But,  
I’m not sure why that is..

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [February 1, 2010, 5:24pm UTC](https://www.ruby-forum.com/t/strange-issue-with-wx-sugar-and-xml-load/182648/5 "2010-02-01T17:24:05Z")

</div>

Okay, I figured it out, but it’s a really weird issue.

I decided to put the following in the generated ruby file that xrcise  
generates:

begin  
xml.load(“ui/ui.xrc”)  
rescue  
xml.load(Dir.getwd + “/ui/ui.xrc”)  
end

When I built the app and ran the app from my desktop:

Cannot load resources from C:/users/joel/desktop/ui/ui.xrc.

So, I created a folder called ui on my desktop and placed the xrc source  
in there and it works. I went back to the generated ruby file, removed  
the rescue statement completely and left it just as:

xml.load(“ui/ui.xrc”)

And rebuilt the app and tried again from my desktop. It worked, because  
there was a ui/ui.xrc file on my desktop.

This is very strange because when using xml.load it appears it’s looking  
in the current working directory and not the temp directory that ocra  
unpacks everything into. So, I’m not sure how to change the working  
directory to the temp directory that ocra creates when you launch the  
executable.

Is this a bug with xml.load? Or a bug with Ocra?

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [February 1, 2010, 5:56pm UTC](https://www.ruby-forum.com/t/strange-issue-with-wx-sugar-and-xml-load/182648/6 "2010-02-01T17:56:03Z")

</div>

Reported this in a bug ticket:

[http://rubyforge.org/tracker/index.php?func=detail&aid=27762&group\_id=35&atid=218](http://rubyforge.org/tracker/index.php?func=detail&aid=27762&group_id=35&atid=218)

Ticket # 27762

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [February 1, 2010, 5:42pm UTC](https://www.ruby-forum.com/t/strange-issue-with-wx-sugar-and-xml-load/182648/7 "2010-02-01T17:42:31Z")

</div>

In order to fix the issue, I had to replace the xml.load with:

xml.load(File.join(File.dirname( **FILE** ),“ui.xrc”))

… which while fixable, means that anytime I want to port an application  
using xrcise, I have to hack the generated file. I wonder if they  
realize that load is not like require and that it generally should be  
used with absolute paths?
