Drawables issue


#1

I was hoping someone might be able to help me out with this problem I’ve been having in getting a drawable routine working.

When I instantiate a drawable in the constructor of my class as follows…

…and then try to draw it in the paint routine as follows…

void Main::paint (Graphics& g) { drawable->draw (g, AffineTransform::translation (0.0f, 0.0f)); }

…the program compiles, but then proceeds to crash.

However, when the above 2 steps are both done in the paint function, as follows…

void Main::paint (Graphics& g) { Drawable* drawable = Drawable::createFromImageFile (File (T("wood.png"))); drawable->draw (g, AffineTransform::translation (0.0f, 0.0f)); }

…everything works ok.

I’m baffled by this one. Could someone possibly help me out here?


#2

well if the lines are exactly as written, then the pointer ‘drawable’ is only in the scope of the constructor (i.e. it should be a member of the class if you plan on using it in multiple functions).

but then i guess it wouldn’t compile.

which suggests that you’ve had to augment that line for the purposes of this post; in which case there may be other differences in the actual code compared to what we’re seeing!


#3

it might compile if drawable is defined as a member but the compiler is allowing a local variable in the constructor to share the same name as a class member.


#4

indeed! if the lines are written in your code as stated here, just delete the ‘Drawable*’ from the line in the constructor. This is, of course, assuming that you have a member ‘Drawable* drawable’ in your class.


#5

Thank you so very much! You guys are just awesome. I’ve been trying to work that one out over the past week and just couldn’t figure out what was wrong. My noobiness with c++ shall eventually subside thanks to so much aide from this board. Thanks again.

Oh, and thanks much for the Juce tutorials haydxn. I began learning Juce using those tutorials and messing around with different examples. Oh, and I especially appreciated your update to TrackPad. There’s a commercial notepad VST, but I am firmly convinced that it pales in comparison to TrackPad2X. I’ve worked out several EnergyXT tutorials using it. Thanks again, again.


#6

thank you for using my things :smiley: i really hope to get the tutorials updated and renewed soon. i’ve got the formatting done, it’s now friendlier than it was before (even for total newcomers who haven’t yet learned much C++, explaining basic principles required to understand juce as they’re needed).

i’ve been making a quiz game for my girlfriend; she’s a teacher, and we recently bought the PS2 game ‘Buzz’, which comes with a USB device with four remote buzzer controls for giving your answers. I’ve written an easy Juce class (for windows only) that lets you use the device in your app from a single object instance; it even pops up a warning if the device is not detected. A single callback (buzzerPressed(int buzzerId, int buttonId)) in a BuzzerListener lets you respond to the devices any way you need.

If anyone’s interested, I can send the code for it right away, and it should slot right into any program [it’s based on my windows Joystick class which is of course included].


#7

I’m having the same problem.
I have a class

SSME_Window : public DocumentWindow

which instantiates a

class SSME_MainComponent : public Component,
public ButtonListener,
public KeyListener,
public SliderListener

In SSME_MainComponent as a private member I make a

Drawable* d

and then in the constructor I add the line

d = Drawable::createFromImageFile(File(T(“test.png”)));

the previous line always seems to crash the program. It compiles fine but goes to run and crashes…Any help? Also if test.png isn’t where it needs to be will it crash? or will it default to NULL or something and not crash?[/code]


#8

I have since tried the following code…

File phil2("test.png");
		
if(phil2.existsAsFile())
{
  JPEGImageFormat imageFormat;
  FileInputStream input(phil2);
  image = imageFormat.decodeImage(input);
}

this also compiles fine but crashes the program. If I change the first line to just “File phil2;” it compiles and runs fine but whenever it tries to load an actual image file it’s crashing. It makes me think it’s a problem with the image not being where it’s supposed to be or perhaps not the correct format. Can someone shed some light on this subject for me please? It’s greatly appreciated. In the end I want to have a toolbar with a bunch of images but for right now I’m just trying to load an image. Thanks again.


#9

Well the jpeg code throws an exception, but that’s what it’s supposed to do, and will be ignored in a release build. Your debugger will catch it but it’s not important.

Hope you’re not actually expecting that JPEG format object to load a PNG successfully, are you?!


#10

well I have one image I saved twice. Once to a jpeg and once to a png and since I wasn’t sure which folder it needed to be in I just placed it in every single folder under the main one I could and every bit of code I try I try it with .jpg, .jpeg and .png so I just wasn’t thinking when I put .png in the code but the result is the same even with the other two.

So the JPEG code throws an exception and I switched to release mode and like you said it works… So I did the same with PNG and that throws the exception in debug but works in release as well which is a step in the right direction…

Now my question is is there a way to catch the exception so I can do what I need with the images in DEBUG? I’ve tried catching the exception but I’m new with exception handling in C++. I tried

try{
  File file("test.png");
}catch(int e){
}

but the same thing happens. Thanks again for your help.


#11

Just ignore it. Turn off exception-catching in your debugger if it bothers you. It’s used internally and never goes anywhere near your code.


#12

Can you turn off the debugging exception handling in Visual C++ 2005 Express? I’ve tried every combination I could think of of /EHsac- but it still crashes. I’ve tried Project Properties -> C/C++ -> Code Generation and turned Enable C++ Exceptions to OFF. I’ve also gone to Debug -> Exceptions on the top menubar and turned them all off and on. None seem to work :frowning:


#13

I said turn it off in your debugger, not your compiler! Go to the debug menu / exceptions.


#14

I actually tried that right after my last post and then edited my post but you must have already been typing. Sorry. So I’ve tried disabling all exceptions and enabling all exceptions just in case but neither work. I tried adding my own exception and in the name I added the text it returns when it crashes.


#15

Yes, you can turn them on and off - I do it all the time…


#16

I’m sorry…It’s not working. I know it’s my fault…obviously. I’m just wondering if someone can explain exactly what exception I need to turn on or off for it to work because I like to test the program I’m creating quite often and if I use the release build it takes a bit longer because of code generation. Or if there is another way I’m all ears…thanks.


#17

It’s a “c++ exception”


#18

I’ve tried turning all the C++ Exceptions ON and OFF, I tried both ways. It still comes up saying it triggered a breakpoint and then the following error message says “No symbols are loaded for any call stack frame. The source code cannot be displayed.” Must I create my own exception? if so what do I name it and do I check it or not?


#19

why on earth don’t you just sort your files out? you’re just asking for trouble.


#20

If your project is so messed-up that it can’t even find the stack frame, then no wonder it’s struggling to handle the exceptions correctly.