[fixed]CXMeshFileLoader

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
irw
Posts: 3
Joined: Sun Mar 06, 2011 8:17 pm
Location: Ukraine

[fixed]CXMeshFileLoader

Post by irw »

Recently when I was working with Irrlicht 1.7.2 and tried to load some .x file my program crashed with access violation exception. Debug showed that problem is in CXMeshFileLoader.
Here is my workaround followed by explanation:

Code: Select all

Index: D:/Projects/Irrlicht/CXMeshFileLoader.cpp
===================================================================
--- D:/Projects/Irrlicht/CXMeshFileLoader.cpp   (revision 3603)
+++ D:/Projects/Irrlicht/CXMeshFileLoader.cpp   (working copy)
@@ -1024,7 +1024,8 @@
            mesh.TCoords2.reallocate(mesh.Vertices.size());
            u8* dataptr = (u8*) data;
            const u32 size=((dataformat>>8)&0xf)*sizeof(core::vector2df);
-            for (u32 j=0; j<mesh.Vertices.size(); ++j)
+            u32 boundary = (datasize << 2)/size;
+            for (u32 j=0; j<mesh.Vertices.size() && j<boundary; ++j)
            {
               mesh.TCoords2.push_back(*((core::vector2df*)(dataptr)));
               dataptr += size;
Access violation happens if size*mesh.Vertices.size() is greater than size of memory block pointed by dataptr, so I've just added second stop condition j<boundary where boundary is the actual size of memory block in bytes divided by the value of variable size.
This workaround allowed me to work with all models that were in project but in general it would be great to think about possible consequences of premature end of cycle and probably find more suitable solution.
Thanks for your attention.
P. S. I've read rules of the forum and know that I should attach file that caused the problem but unfortunately I don't have possibility to do this.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, you don't need to add the code as a file. But it would help if you could send us some of your .x files so we can properly check for a correct solution. You can upload files either via some download hoster or on our bug tracker http://sourceforge.net/tracker/?group_i ... tid=540676
irw
Posts: 3
Joined: Sun Mar 06, 2011 8:17 pm
Location: Ukraine

Post by irw »

hybrid wrote:No, you don't need to add the code as a file. But it would help if you could send us some of your .x files so we can properly check for a correct solution. You can upload files either via some download hoster or on our bug tracker http://sourceforge.net/tracker/?group_i ... tid=540676
Sorry, maybe I've expressed my thoughts a bit unclearly - I meant that I can't upload model (.x file) that caused the problem. But I'll try to get permission to do this.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

In case there are legal problems with this, you might consider mailing the file directly to me. I'll keep it confidential and only use it for fixing the loader code. Write a PM or search my mail address if this is viable.
irw
Posts: 3
Joined: Sun Mar 06, 2011 8:17 pm
Location: Ukraine

Post by irw »

If this topic is still actual, I got permission to upload whole solution.
Link at model causing the problem is http://www.assembla.com/code/pathman/su ... els/hero.X
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

It seems as if the loader has fixed this problem already for the upcoming 1.8 version of Irrlicht. If I find the time I will also check with Irrlicht 1.7, but chances are high that this will be unfixed until the next major release.
Post Reply