Jump to content

Loading order of plugins leads to crash on Pixmap::Save


klepto2
 Share

Go to solution Solved by Josh,

Recommended Posts

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;
}

 

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

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;

 

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

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;

 

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

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...

  • Like 1

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...