diff --git a/src/servers/midi/DeviceWatcher.cpp b/src/servers/midi/DeviceWatcher.cpp index 56c1b5c689..fa7b6e1919 100644 --- a/src/servers/midi/DeviceWatcher.cpp +++ b/src/servers/midi/DeviceWatcher.cpp @@ -63,11 +63,23 @@ DeviceWatcher::DeviceWatcher() BResources resources; if (resources.SetTo(&file) == B_OK) { - fVectorIconData = (const uint8*)resources.LoadResource( - B_VECTOR_ICON_TYPE, "endpoint_vector_icon", &fVectorIconDataSize); + size_t dataSize; + // Load MIDI port endpoint vector icon + const uint8* data = (const uint8*)resources.LoadResource( + B_VECTOR_ICON_TYPE, "endpoint_vector_icon", &dataSize); + + if (data != NULL && dataSize > 0) + fVectorIconData = new(std::nothrow) uint8[dataSize]; + + if (fVectorIconData) { + // data is own by resources local object: copy its content for + // later use + memcpy(fVectorIconData, data, dataSize); + fVectorIconDataSize = dataSize; + } } - // Render 32x32 and 16x16 icons for R5 compatibility + // Render 32x32 and 16x16 B_CMAP8 icons for R5 compatibility if (fVectorIconData != NULL) { fLargeIcon = new(std::nothrow) BBitmap(BRect(0, 0, 31, 31), B_CMAP8); fMiniIcon = new(std::nothrow) BBitmap(BRect(0, 0, 15, 15), B_CMAP8); @@ -94,6 +106,7 @@ DeviceWatcher::~DeviceWatcher() delete fLargeIcon; delete fMiniIcon; + delete[] fVectorIconData; } diff --git a/src/servers/midi/DeviceWatcher.h b/src/servers/midi/DeviceWatcher.h index 864f6bbd42..9483823a7d 100644 --- a/src/servers/midi/DeviceWatcher.h +++ b/src/servers/midi/DeviceWatcher.h @@ -39,7 +39,7 @@ private: typedef HashMap DeviceEndpointsMap; DeviceEndpointsMap fDeviceEndpointsMap; - const uint8* fVectorIconData; + uint8* fVectorIconData; size_t fVectorIconDataSize; BBitmap* fLargeIcon; BBitmap* fMiniIcon;