klepto2 Posted February 6, 2023 Share Posted February 6, 2023 When the KTX2 plugin is loaded before the FreeImage plugin, the Pixmap::Save method throws an exception in the KTX2 plugin when trying to save a jpg or png file: #include "UltraEngine.h" using namespace UltraEngine; #define BUG int main(int argc, const char* argv[]) { #ifdef BUG auto plg_2 = LoadPlugin("Plugins/KTX2TextureLoader"); auto plg_1 = LoadPlugin("Plugins/FITextureLoader"); #else auto plg_1 = LoadPlugin("Plugins/FITextureLoader"); auto plg_2 = LoadPlugin("Plugins/KTX2TextureLoader"); #endif auto pixmap = CreatePixmap(256, 256); pixmap->Save("test.jpg"); pixmap->Save("test.png"); return 0; } Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Josh Posted February 6, 2023 Share Posted February 6, 2023 Okay, it looks like the plugin doesn't do any pre-checking of the file and the KTX lib isn't set up to account for that: //Texture load function void* LoadTexture(Context* context, void* data, uint64_t size, wchar_t* cpath, uint64_t& size_out) { ktx_uint64_t offset = 0; ktx_uint8_t* image = NULL; ktx_uint32_t level, layer, faceSlice; KTX_error_code result = ktxTexture2_CreateFromMemory((const ktx_uint8_t*)data, size, KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &context->ktx); if (result != KTX_error_code::KTX_SUCCESS) return NULL; 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...
Josh Posted February 6, 2023 Share Posted February 6, 2023 See section 3.1 about the file header: https://registry.khronos.org/KTX/specs/2.0/ktxspec.v2.html Does this code look right to you? void* LoadTexture(Context* context, void* data, uint64_t size, wchar_t* cpath, uint64_t& size_out) { //Check file header if (size < 12) return NULL; char FileIdentifier[12] = { '«', 'K', 'T', 'X', ' ', '2', '0', '»', '\r', '\n', '\x1A', '\n' }; if (strcmp((char*)data, &FileIdentifier[0]) != 0) return NULL; 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...
klepto2 Posted February 6, 2023 Author Share Posted February 6, 2023 Yes, this looks right. But I don’t know what this has to do with the save function? Shouldn’t the save function just go by the extension ? Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Josh Posted February 6, 2023 Share Posted February 6, 2023 Oh, you are correct. 😱 I don't know why it would even be trying to save that... 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...
Josh Posted February 7, 2023 Share Posted February 7, 2023 Okay, it just needs this code in the plugin: void* SaveTexture(Context* context, wchar_t* extension, const int type, const int width, const int height, const int format, void** mipchain, int* sizechain, const int mipcount, const int layers, uint64_t& returnsize, int flags) { std::wstring ext = extension; if (ext != L"ktx2") return NULL; Although I still want to test and make sure KTX saving is working... 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...
Solution Josh Posted February 7, 2023 Solution Share Posted February 7, 2023 This plugin is now updated. You need to sync your project to get the new plugin file. 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...
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.