View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0001444 | NoesisGUI | C++ SDK | public | 2019-04-05 13:46 | 2019-04-08 11:33 |
| Reporter | decai | Assigned To | sfernandez | ||
| Priority | normal | Severity | crash | ||
| Status | feedback | Resolution | open | ||
| Product Version | 2.2.1 | ||||
| Summary | 0001444: BitmapSource::Create from MFC CImage Bits crashed on x64 | ||||
| Description | We add bellow code in HelloWorld sample for test create BitmapSource from MFC CImage. We just modiy the HelloWorld sample. | ||||
| Attached Files | Main.cpp (2,807 bytes)
////////////////////////////////////////////////////////////////////////////////////////////////////
// NoesisGUI - http://www.noesisengine.com
// Copyright (c) 2013 Noesis Technologies S.L. All Rights Reserved.
////////////////////////////////////////////////////////////////////////////////////////////////////
#include <atlimage.h>
#include <NsCore/Noesis.h>
#include <NsCore/ReflectionImplement.h>
#include <NsCore/RegisterComponent.h>
#include <NsCore/TypeId.h>
#include <NsApp/EmbeddedXamlProvider.h>
#include <NsApp/ApplicationLauncher.h>
#include <NsApp/EntryPoint.h>
#include <NsApp/Application.h>
#include <NsApp/Window.h>
#include "App.xaml.bin.h"
#include "MainWindow.xaml.bin.h"
using namespace Noesis;
using namespace NoesisApp;
namespace HelloWorld
{
////////////////////////////////////////////////////////////////////////////////////////////////////
class App final: public Application
{
NS_IMPLEMENT_INLINE_REFLECTION(App, Application)
{
NsMeta<TypeId>("HelloWorld.App");
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
class MainWindow final: public Window
{
NS_IMPLEMENT_INLINE_REFLECTION(MainWindow, Window)
{
NsMeta<TypeId>("HelloWorld.MainWindow");
}
};
}
////////////////////////////////////////////////////////////////////////////////////////////////////
class AppLauncher final: public ApplicationLauncher
{
private:
void RegisterComponents() const override
{
NsRegisterComponent<HelloWorld::App>();
NsRegisterComponent<HelloWorld::MainWindow>();
}
Ptr<XamlProvider> GetXamlProvider() const override
{
EmbeddedXaml xamls[] =
{
{ "App.xaml", App_xaml, sizeof(App_xaml) },
{ "MainWindow.xaml", MainWindow_xaml, sizeof(MainWindow_xaml) }
};
return *new EmbeddedXamlProvider(xamls, NS_COUNTOF(xamls));
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
int NsMain(int argc, char **argv)
{
AppLauncher launcher;
launcher.SetArguments(argc, argv);
launcher.SetApplicationFile("App.xaml");
CImage *image = new CImage();
HRESULT sr = image->Load("d:\\1.png");
if (sr == S_OK)
{
int imageWidth = image->GetWidth();
int imageHeight = image->GetHeight();
const void *data = image->GetBits();
int pitch = image->GetPitch();
BitmapSource::Format bitmapFormat = Noesis::BitmapSource::Format_BGRA8;
auto imageSource = BitmapSource::Create(imageWidth, imageHeight, 0, 0, (uint8_t*)data, pitch, bitmapFormat);
if (imageSource)
{
printf("image source create ok");
}
}
return launcher.Run();
}
| ||||
| Platform | Windows | ||||
|
Could you also attach a minidump please? Thanks! |
|
|
here is the dump:https://drive.google.com/file/d/1n8m2I5oRnDcOUZaJF-MXrvIMkJ6qvDHT/view?usp=sharing |
|
|
Hi, according to CImage documentation: https://docs.microsoft.com/en-us/cpp/atl-mfc-shared/reference/cimage-class?view=vs-2019#getbits, if the pitch value returned by the CImage is negative it indicates that it is creating a bottom-up DIB, and the pointer returned by GetBits() points to the last row of the image. That is the case with the image you supplied. Our BitmapSource::Create() expects a positive stride and a pointer to the first pixel in the buffer, but I see we are not checking this and no error message explaining what happened is shown, so we will add it for next versions. Your code should look as follows to properly work: CImage image = new CImage(); |
|
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2019-04-05 13:46 | decai | New Issue | |
| 2019-04-05 13:46 | decai | Tag Attached: C++ | |
| 2019-04-05 13:46 | decai | File Added: Main.cpp | |
| 2019-04-05 13:46 | decai | File Added: 1.png | |
| 2019-04-05 16:19 | sfernandez | Assigned To | => sfernandez |
| 2019-04-05 16:19 | sfernandez | Status | new => assigned |
| 2019-04-05 21:15 | jsantos | Note Added: 0005600 | |
| 2019-04-05 21:15 | jsantos | Status | assigned => feedback |
| 2019-04-06 11:20 | decai | Note Added: 0005603 | |
| 2019-04-06 11:20 | decai | Status | feedback => assigned |
| 2019-04-06 11:28 | decai | Note Edited: 0005603 | |
| 2019-04-08 11:33 | sfernandez | Status | assigned => feedback |
| 2019-04-08 11:33 | sfernandez | Note Added: 0005614 |