My 3d rendering application crashes if textures not found
-
Hi!
I have created a sample application to render 3d models using the assimp-cpp sample. I am using Qt5.7.
The application is meant to work for both win and mac environments.Now, I had been working first on Windows, and was able to create a working application that loads and displays .dae files.
These files also use image textures. I noted, that if the application could not locate the textures(incorrect path etc.), it just crashed without giving any additional info.Same thing happens on Mac as well.
How can I ensure that my application does not crash, and the scenario is handled appropriately?
Any exception handling that I can do?Here is a link to the assimp-cpp sample in qt5.7.
Please guide me here. I am very new to Qt.
-
@Poorti Well, in your main() function you do:
if (sourceFileName.isEmpty()) return 0; sceneLoader->setSource(sourceFileName);
So, if you do not have a file name you just return - returning in main() means exit the program.
You should do:if (!sourceFileName.isEmpty()) sceneLoader->setSource(sourceFileName);
-
Thanks for the response..
Modifying the code to what you suggested won't work either because sourceFileName contains the name of the .dae file. The .dae file is present on the system and is found.
My problem is when the 3d model is parsed, it looks for textures referred in the .dae..
If you open the .dae as text, you'll see the references, for eg,<library_images> <image id="Front_png-image" name="Front_png"> <init_from>file://Textures\Front.png</init_from> </image> <image id="Back_png-image" name="Back_png"> <init_from>file://Textures\Back.png</init_from> </image> <image id="Right_Arm_png-image" name="Right_Arm_png"> <init_from>file://Textures\Right-Arm.png</init_from> </image> <image id="Left_Arm_png-image" name="Left_Arm_png"> <init_from>file://Textures\Left-Arm.png</init_from> </image> </library_images>
The above is how my .dae file appears on my Windows machine.
Now, if these images are missing on disk, the crash happens.
I thought the .dae files are cross platform, so tried the same on Mac. It crashed.
Also, what is with the path separators..? This file won't load textures on my Mac, and so it crashes. -
It should be relative to the .dae..
I am saying this because, I tried opening it using FBX Review which renders 3d.
FBX Review loaded the 3d model without the textures.Moreover, the application does not know anything about textures. It just renders whatever is in the .dae
and all the information about the textures is inside the .dae...My concern is that if some .dae file is created on Windows which refers textures as in my example, how will I be able to open the same on Mac (with textures), and vice-versa.
I tried changing the path to full path too in the .dae.
No change.