SpiderPig Posted March 8 Share Posted March 8 I'm working on my own model format with a plugin, and with or without the plugin loaded I get the error - "Seek position outside of file bounds". If you try loading this file as a model it should return null if it does not recognise shouldn't it? LoadModel("Test.uga"); Test.zip Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted March 8 Author Share Posted March 8 I was creating the file with a buffer but changed to WriteFile but it still throws an error in LoadModel and crashes the application. This is how I'm creating the model file. void SaveModel(WString filepath, shared_ptr<Model> model) { auto version = 1; auto file = WriteFile(filepath); auto total_lods = model->lods.size(); file->WriteInt(version); file->WriteInt(total_lods); for (auto lod_index = 0; lod_index < total_lods; lod_index++) { auto total_meshes = model->lods[lod_index]->meshes.size(); file->WriteInt(total_meshes); for (auto mesh_index = 0; mesh_index < total_meshes; mesh_index++) { auto mesh = model->lods[lod_index]->meshes[mesh_index]; auto total_vertices = mesh->CountVertices(); auto total_indices = mesh->CountPrimitives(); //Save Vertices file->WriteInt(total_vertices); for (auto vert_index = 0; vert_index < total_vertices; vert_index++) { auto vertex_position = mesh->GetVertexPosition(vert_index); auto vertex_normal = mesh->GetVertexNormal(vert_index); auto vertex_texcoords = mesh->GetVertexTexCoords(vert_index); file->WriteFloat(vertex_position.x); file->WriteFloat(vertex_position.y); file->WriteFloat(vertex_position.z); file->WriteFloat(vertex_normal.x); file->WriteFloat(vertex_normal.y); file->WriteFloat(vertex_normal.z); file->WriteFloat(vertex_texcoords.x); file->WriteFloat(vertex_texcoords.y); } //Save Indices file->WriteInt(total_indices); for (auto indice_index = 0; indice_index < total_indices; indice_index++) { auto v0 = mesh->GetPrimitiveVertex(indice_index, 0); auto v1 = mesh->GetPrimitiveVertex(indice_index, 1); auto v2 = mesh->GetPrimitiveVertex(indice_index, 2); file->WriteInt(v0); file->WriteInt(v1); file->WriteInt(v2); } } } file->Close(); } Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted March 8 Author Share Posted March 8 This is 0.9.4 by the way... Happens in 0.9.5 too. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted March 9 Author Share Posted March 9 This file causes LoadModel() to hang rather than crash. Is there some sort of secret header that all model files should have? To confirm - this is not with any plugin I've made, this is just loading a file that doesn't have much data and is in a format that LoadModel() doesn't recognise. I've also seen LoadModel hang and rapidly increase RAM usage into the tens of GB. CausesHang.zip Quote Link to comment Share on other sites More sharing options...
Josh Posted March 12 Share Posted March 12 On 3/9/2024 at 1:02 AM, SpiderPig said: This file causes LoadModel() to hang rather than crash. Is there some sort of secret header that all model files should have? To confirm - this is not with any plugin I've made, this is just loading a file that doesn't have much data and is in a format that LoadModel() doesn't recognise. I've also seen LoadModel hang and rapidly increase RAM usage into the tens of GB. CausesHang.zip 139 B · 0 downloads This file mimics the beginning of a Leadwerks MDL file. I added some more checks that prevent the loader from trying to load this as such. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted March 12 Author Share Posted March 12 Thanks. I'm now seeing that "Unknown chunk in model file" is spamming the output window for about 20 seconds before it finally fails to load. Also the first file in this thread gives a "Seek position out of file bounds error" still. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted March 12 Author Share Posted March 12 6 hours ago, Josh said: This file mimics the beginning of a Leadwerks MDL file. I added some more checks that prevent the loader from trying to load this as such. Shouldn't it load the file based on the extension type rather than trying to load data from the file first? Quote Link to comment Share on other sites More sharing options...
Josh Posted March 12 Share Posted March 12 4 hours ago, SpiderPig said: Shouldn't it load the file based on the extension type rather than trying to load data from the file first? No, it just loads data from a stream which may not have any file path associated with it at all. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted March 12 Author Share Posted March 12 I'm not fully convinced this issue is solved yet. 14 hours ago, SpiderPig said: Thanks. I'm now seeing that "Unknown chunk in model file" is spamming the output window for about 20 seconds before it finally fails to load. Should it really take 20 seconds before finally failing to load? 5 hours ago, Josh said: No, it just loads data from a stream which may not have any file path associated with it at all. How then are we to create plugins for new models types, custom or not, if the stream is not looking at the file extension? At what point does LoadModel look to see if a plugin might have the function it needs to load that extension? If you could please also try this file as it throws an out of bounds error and crashes the program. Test.zip Quote Link to comment Share on other sites More sharing options...
Solution Josh Posted March 12 Solution Share Posted March 12 Typically your file format should start with some sort of identifier like "SPGM" for the first four bytes or so. This is usually how binary file formats are identified. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted March 12 Author Share Posted March 12 Oh okay. What does SPGM stand for? Quote Link to comment Share on other sites More sharing options...
Josh Posted March 12 Share Posted March 12 Spiderpig game model. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted March 12 Author Share Posted March 12 Oh, I get it now. So just anything that Identifiers my binary format. 1 Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted March 13 Author Share Posted March 13 The addition of a small header fixed the problem, thankyou. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.