Author: phoudoin Date: 2009-11-29 22:39:49 +0100 (Sun, 29 Nov 2009) New Revision: 34358 Changeset: http://dev.haiku-os.org/changeset/34358/haiku Ticket: http://dev.haiku-os.org/ticket/4562 Modified: haiku/trunk/src/servers/midi/DeviceWatcher.cpp haiku/trunk/src/servers/midi/DeviceWatcher.h Log: Stupid me, vector icon data loaded by a local BResources object is lost outside its scope. Now vector data is copied instead. Spotted by Pete Goodeve, thanks! This should close #4562. Modified: haiku/trunk/src/servers/midi/DeviceWatcher.cpp =================================================================== --- haiku/trunk/src/servers/midi/DeviceWatcher.cpp 2009-11-29 21:38:47 UTC (rev 34357) +++ haiku/trunk/src/servers/midi/DeviceWatcher.cpp 2009-11-29 21:39:49 UTC (rev 34358) @@ -63,11 +63,23 @@ 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 @@ delete fLargeIcon; delete fMiniIcon; + delete[] fVectorIconData; } Modified: haiku/trunk/src/servers/midi/DeviceWatcher.h =================================================================== --- haiku/trunk/src/servers/midi/DeviceWatcher.h 2009-11-29 21:38:47 UTC (rev 34357) +++ haiku/trunk/src/servers/midi/DeviceWatcher.h 2009-11-29 21:39:49 UTC (rev 34358) @@ -39,7 +39,7 @@ typedef HashMap<HashString, DeviceEndpoints*> DeviceEndpointsMap; DeviceEndpointsMap fDeviceEndpointsMap; - const uint8* fVectorIconData; + uint8* fVectorIconData; size_t fVectorIconDataSize; BBitmap* fLargeIcon; BBitmap* fMiniIcon;