Horde3D

Next-Generation Graphics Engine
It is currently 27.04.2024, 06:49

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: 01.02.2010, 23:27 
Offline

Joined: 18.09.2009, 07:44
Posts: 17
Using VS2008 or VS2010 on Windows 7, a Debug build hits this assert any time I try to load a DXT1 DDS:

Code:
ASSERT( pixels == (unsigned char *)data + (size - 1) );


The texture appears to successfully load, regardless of this assertion being hit. I'm using the C# bindings with the latest code in the SVN trunk, but I recall seeing this occur in prior releases (beta3, beta4) and in previous versions of windows (Vista).

Any ideas?


Top
 Profile  
Reply with quote  
PostPosted: 02.02.2010, 02:36 
Offline

Joined: 19.11.2007, 19:35
Posts: 218
Mip-maps okay, if you've got them?

Renderer().calcTextureSize() look fine. (width/4) * (height/4) * 8 which for a 4x4 image would be 64 bits or 8 bytes as per the spec.

How are you loading the texture (utility library?), if the size passed into the load function was larger than the data it could definitely hit that assert, though it doesn't look like it would ever go exceed the bounds of a legit dds file, and would fail if your size passed in was too small.

If you're able to debug break after the assert it would be helpful to know the locals in the function.


Top
 Profile  
Reply with quote  
PostPosted: 02.02.2010, 04:41 
Offline

Joined: 18.09.2009, 07:44
Posts: 17
Thanks for the reply, my artist believes the Mip maps are ok, it was exported from photoshop with the Nvidia DDS plugin.

Here are the locals when I break:

Attachment:
h3d-assert-debug-locals.PNG
h3d-assert-debug-locals.PNG [ 45.21 KiB | Viewed 14173 times ]


I use the following code to load it (and any other resource):

Code:
int resId = h3d.addResource((int)resourceType, resourceName, 0);

if (nullTerminate)
{
    ms.Position = ms.Length;
    ms.WriteByte((byte)'\0');
}

byte[] bytes = ms.ToArray();

bool isLoaded = h3d.isResLoaded(resId);

if (!isLoaded)
    h3d.loadResource(resId, bytes, bytes.Length);

return resId;


Attached is the dds, its a grey version of the one that comes with the samples, although I notice it is significantly smaller in size.


Attachments:
ambientMap.zip [5.2 KiB]
Downloaded 609 times
Top
 Profile  
Reply with quote  
PostPosted: 02.02.2010, 13:50 
Offline

Joined: 19.11.2007, 19:35
Posts: 218
Code:
ms.WriteByte((byte)'\0');


That would do it.

Appending the null is giving you an extra byte that the DDS loading isn't concerned about (since it's not dealing with text like an xml resource would be).


Top
 Profile  
Reply with quote  
PostPosted: 02.02.2010, 22:58 
Offline

Joined: 18.09.2009, 07:44
Posts: 17
AcidFaucet wrote:
Code:
ms.WriteByte((byte)'\0');


That would do it.

Appending the null is giving you an extra byte that the DDS loading isn't concerned about (since it's not dealing with text like an xml resource would be).

Agreed, I stepped through that section of code and in this case nullTerminate is false (as it is for all textures), so the byte does not get added. The bytes reported by windows for the dds match the size of the byte array I try to load (16592).

If I change the loadResource call to strip a byte off all dds:

Code:
h3d.loadResource(resId, bytes, resourceName.EndsWith(".dds") ? bytes.Length - 1 : bytes.Length);


The ambient shows up as yellow rather than the grey which is in the texture so I think my code is ok in this case :?

The strange thing is that even though it asserts, the visuals appear as expected.


Top
 Profile  
Reply with quote  
PostPosted: 02.02.2010, 23:10 
Offline

Joined: 19.11.2007, 19:35
Posts: 218
An assertion isn't necessarily a problem just a notification of something unexpected occurring. "I expect this to be true, if not I want to know about it."


Top
 Profile  
Reply with quote  
PostPosted: 02.02.2010, 23:44 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
The assertion is triggered because the dds code assumes that the texture file buffer is also one byte larger (h3dutLoadResourcesFromDisk zero-terminates all files). This behavior is not obvious from the documentation which says just that XML files have to be zero-terminated. Maybe we should change that an recommend to zero-terminate all files.

Although it is somehow acceptable, I would prefer to get completely rid of this termination but unfortunately most XML parsers require it (although they could be modified to work with a size parameter instead).


Top
 Profile  
Reply with quote  
PostPosted: 03.02.2010, 00:16 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
Having to NULL-terminate all resources could cause some headaches.
For example, if you use another library for file loading (e.g. from an archive), then after that library gives me a buffer-of-bytes, I've got to memcpy the whole thing into a new buffer so I can append the 0-byte on the end (which horde will then mostly ignore anyway).


Top
 Profile  
Reply with quote  
PostPosted: 03.02.2010, 03:08 
Offline

Joined: 18.09.2009, 07:44
Posts: 17
Thanks marciano, null terminating fixes the issue.


Top
 Profile  
Reply with quote  
PostPosted: 03.02.2010, 22:12 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
DarkAngel wrote:
Having to NULL-terminate all resources could cause some headaches.
For example, if you use another library for file loading (e.g. from an archive), then after that library gives me a buffer-of-bytes, I've got to memcpy the whole thing into a new buffer so I can append the 0-byte on the end (which horde will then mostly ignore anyway).

Good point. I would propose then that we make the null termination optional for xml resources only. If some xml data is not null-terminated, horde will handle that by creating a temporary buffer.


Top
 Profile  
Reply with quote  
PostPosted: 04.02.2010, 02:34 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
marciano wrote:
DarkAngel wrote:
Having to NULL-terminate all resources could cause some headaches.
For example, if you use another library for file loading (e.g. from an archive), then after that library gives me a buffer-of-bytes, I've got to memcpy the whole thing into a new buffer so I can append the 0-byte on the end (which horde will then mostly ignore anyway).
Good point. I would propose then that we make the null termination optional for xml resources only. If some xml data is not null-terminated, horde will handle that by creating a temporary buffer.
In some ways, that just masks the problem. Horde would then be performing a copy of possibly large amounts of data, for what is ultimately a book-keeping exercise. Perhaps the API could be expanded to accept a length parameter in place of a null terminator, and then operate directly on the data handed in?

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 10.02.2010, 01:02 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
swiftcoder wrote:
In some ways, that just masks the problem. Horde would then be performing a copy of possibly large amounts of data, for what is ultimately a book-keeping exercise. Perhaps the API could be expanded to accept a length parameter in place of a null terminator, and then operate directly on the data handed in?

The API already has a size parameter for loading. The problem is the XML parser which does only work with null terminated data. Thinking about it again, I tend to make the termination completely transparent to the user and have Horde use a pre-allocated scratch buffer. Most xml files are quite small, so the performance overhead of the memcpy should be neglectable. Once we switch to a fast in-situ parser, it makes sense to have a local copy anyway since the parser will have to write to the memory.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 44 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group