Convert __NSCFString to NSData
App crash when I try to get data from my NSDictionary
NSData *routeData = [dictSelectedScheduleTrip valueForKey:#"routeSerialize"];
Crash Log
[__NSCFString bytes]: unrecognized selector sent to instance 0x107310000
Console Code
po [[dictSelectedScheduleTrip valueForKey:#"routeSerialize"] class]
__NSCFString
Below is my NSData (Not added whole data because data is too long if you want to check all data please open below link)
NSData
routeSerialize = "<d5112fa3 0c000000 382e3330 2e313031 2e313536 02000000 30000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00030200 00000710 008e015d 474cc1fe 5e7fa094 477dd52f 5f0b0400 9f000000 0c240003 01000402 04000200 00000104 00000000 00030100 04020400 02000000 01040000 0000000e 00000600 00000000>";
I found a solution.
Original Answer #zaph
+ (NSData *)dataFromHexString:(NSString *)string
{
string = [string lowercaseString];
NSMutableData *data= [NSMutableData new];
unsigned char whole_byte;
char byte_chars[3] = {'\0','\0','\0'};
int i = 0;
int length = string.length;
while (i < length-1) {
char c = [string characterAtIndex:i++];
if (c < '0' || (c > '9' && c < 'a') || c > 'f')
continue;
byte_chars[0] = c;
byte_chars[1] = [string characterAtIndex:i++];
whole_byte = strtol(byte_chars, NULL, 16);
[data appendBytes:&whole_byte length:1];
}
return data;
}
__NSCFString is a class cluster of NSString, you could convert it as is NSString *, no print (call - (NSString *)description) to get hex string needed.
NSData *routeData = [dictSelectedScheduleTrip valueForKey:#"routeSerialize"];
if ([routeData isKindOfClass:NSString.class]) {
routeData = [(NSString *)routeData dataUsingEncoding:NSUTF8StringEncoding]; // or your other prefer data encoding.
}
Related
I am trying to connect to HiveMQ MQTT Broker from my ESP8266, 2 months ago, this code works fine, but now, when I implement more features, the code run with a lot of Exceptions. Sometimes, Exception (28), I'm newbie in this fields and don't know the way to handle it, thanks for your helps.
RAM and Flash:
Exception:
Sometimes:
My Code:
void setup()
{
BearSSL::WiFiClientSecure *bear = setSSLCertificate();
PSclient = new PubSubClient(*bear);
MQTT_ADDRESS = cEEPROM.getMqttAddress();
MQTT_PORT = cEEPROM.getMqttPort();
PSclient->setServer(MQTT_ADDRESS.c_str(), MQTT_PORT);
PSclient->setBufferSize(512);
PSclient->setCallback(myCallback);
}
void loop()
{
wifiConfig.configWifiAP(ENV_SSID_AP, ENV_PASS_AP);
if (!PSclient->connected())
{
reconnect();
}
else
{
PSclient->loop();
}
}
}
void reconnect()
{
while ((!PSclient->connected()) && tryConnectPS <= 5)
{
setDateTime();
String MQTT_ACCOUNT = cEEPROM.getMqttAccount();
String MQTT_USERNAME = cEEPROM.getMqttUsername();
String MQTT_PASSWORD = cEEPROM.getMqttPassword();
Serial.print("Try to connect to MQTT... ");
if (PSclient->connect(MQTT_ACCOUNT.c_str(), MQTT_USERNAME.c_str(), MQTT_PASSWORD.c_str()))
{
Serial.print("Connected state:");
Serial.println(PSclient->state());
String MQTT_TOPIC = cEEPROM.getMqttTopic();
boolean result = PSclient->subscribe(MQTT_TOPIC.c_str());
Serial.print("Tinh trang subscribe topic: ");
Serial.println(result);
tryConnectPS = 0;
DeviceService::turnReadyLedOn();
return;
}
else
{
Serial.print("Failed,rc = ");
Serial.println(PSclient->state());
Serial.println("Try again in 2 seconds ... ");
delay(1000);
tryConnectPS++;
}
}
}
BearSSL::WiFiClientSecure *setSSLCertificate()
{
LittleFS.begin();
int numCerts = certStore.initCertStore(LittleFS, PSTR("/certs.idx"), PSTR("/certs.ar"));
Serial.printf("So chung chi CA : %d\n", numCerts);
if (numCerts == 0)
{
Serial.printf("KHONG TIM THAY CHUNG CHI NAO");
}
BearSSL::WiFiClientSecure *bear = new BearSSL::WiFiClientSecure();
bear->setCertStore(&certStore);
return bear;
}
Full exception:
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Exception (28):
epc1=0x40205f0d epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
stack>>>
ctx: bearssl
sp: 3fff3690 end: 3fff3a80 offset: 0190
3fff3820: 3ffe8cc1 3fffbd6c 3fffb7f4 40205ef4
3fff3830: 4021bb04 00000000 000003e8 4021ad84
3fff3840: 00000000 00000000 00000000 40213640
3fff3850: 00000000 00000000 3fff116c 4021bb04
3fff3860: 00000000 000003e8 3ad6faec 00000000
3fff3870: 00000000 00000000 40213640 00000000
3fff3880: 00000000 3fff116c bd2fdbf6 925dd89d
3fff3890: c6b3dd59 2f7b7dde 0c3e3fec bc6117ef
3fff38a0: 572033bf f8302d1e 0001d90a 0000056f
3fff38b0: 928b6852 b5d6e5dc d07ddae3 3fffa404
3fff38c0: 3fffa428 3fffae04 000003dd 4023efe6
3fff38d0: 4026ed46 eb148196 203ddbd5 d3597ea7
3fff38e0: f958f8e2 cd48b85b 164f5cfe 551efe29
3fff38f0: 11c8af23 7cea8db0 2f179093 09a2acfd
3fff3900: f03f4647 ffb7b0e9 32684d28 1e5e67d6
3fff3910: 4026f0a7 00000000 00000b80 00000000
3fff3920: 3fffa41c 3fffac04 3fffa4d4 0000001a
3fff3930: 3fffa434 3fffa430 c818691e 0a857cc3
3fff3940: 56789534 54be83d2 466dbc59 1ce0b490
3fff3950: 3416a5e4 0b8510a4 5d8f434c 59ff5645
3fff3960: 3fff6072 0000002a 3fff6072 00000683
3fff3970: 3fff5ad4 3fff52d4 3fff5ab8 4023f682
3fff3980: 3fff5adc 3fff52d4 3fff5ab8 40239cb0
3fff3990: 402083e4 3fff52d4 3ffffdf0 00000004
3fff39a0: 4026d679 00000005 00000000 fffffffe
3fff39b0: 00000000 3fffc6fc 00000000 3fff4b3c
3fff39c0: 0000f811 00000000 3fff11d8 00000030
3fff39d0: deadbeef deadbeef 4026da73 deadbeef
3fff39e0: 3fff5ad8 3fff5b5c 3fff5ad4 deadbeef
3fff39f0: deadbeef 3fff52b8 0000001a 3fff5db8
3fff3a00: 0000001a deadbeef deadbeef deadbeef
3fff3a10: deadbeef deadbeef deadbeef 3fff5dd4
3fff3a20: 000005c2 3fff5cd4 3fff52d4 40237e44
3fff3a30: 3fff5ab8 deadbeef deadbeef deadbeef
3fff3a40: 00000250 00000005 deadbeef 3fff11d8
3fff3a50: 00000000 00000000 3fff52d4 40238439
3fff3a60: 00000100 deadbeef deadbeef deadbeef
3fff3a70: deadbeef 00000000 3fff4b3c 402093b8
ctx: cont
sp: 3ffffde0 end: 3fffffc0 offset: 0000
3ffffde0: 00000000 00000000 00003a98 40208400
3ffffdf0: 000005c2 6e00c440 c4c69916 284c5820
3ffffe00: 00000008 00000001 000024a9 00000000
3ffffe10: 40238f4c 40238f9c 3fff52d4 4023858a
3ffffe20: 3fff57d4 3fff4d44 3fff52d4 3fff4d44
3ffffe30: 00000000 00000001 3fff4b3c 40208453
3ffffe40: 00000000 00000001 3fff4b3c 40208643
3ffffe50: 40105b5d 3fff135c 3fff135c 000000c9
3ffffe60: 00000000 00000000 000022b3 4021733a
3ffffe70: 00000000 3fff4b3c 3fff4cd4 4020746e
3ffffe80: 3fff5194 00000010 3fffff5c 3fff45f4
3ffffe90: 000022b3 3fff4d44 3fff4b3c 3fff45f4
3ffffea0: 000022b3 3fff4d44 3fff4b3c 402086e5
3ffffeb0: 4021bbac 9e5c4936 4021bbac 9e5c4936
3ffffec0: 00000000 3fff4c94 3fff4cbc 4021a08a
3ffffed0: 00000000 3fff4c94 3fff4cbc 4020b3e8
3ffffee0: 3ffe88ec 3fff135c 00000005 000000a4
3ffffef0: 00000000 3fffff74 00000000 00000000
3fffff00: 00000001 3ffe88d2 3fff11a0 40214c34
3fffff10: 40214c28 3ffe88d2 3fff11a0 3fff0f30
3fffff20: 3fff0c48 3fff0d44 3fff11a0 4020b5d0
3fffff30: 00000000 00000000 00000001 402150d0
3fffff40: 3fff0c48 3fff0d44 3fff11a0 4020575a
3fffff50: 3fff0f30 00000001 3fff0c54 3fff4cbc
3fffff60: 000f000f 8a003837 3fff4c94 0012001f
3fffff70: 8a003439 36384d53 4a4b3252 0a003439
3fffff80: 3fffdad0 3fff0d44 3fff0c3c 3fff12f4
3fffff90: 3fffdad0 00000000 3fff0d44 40205b09
3fffffa0: 3fffdad0 00000000 3fff12e0 40216d40
3fffffb0: feefeffe feefeffe 3ffe8650 40100dd9
<<<stack<<<
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
I expect to a successful and stable connection to MQTT Broker
I has a sketch that startings a web server to show files in LittleFS. But when it is starting, it's crashing with Exception code 28.
My full code:
#include <FS.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESP8266WebServer.h>
#include <LittleFS.h>
FS* fileSystem = &LittleFS;
File uploadFile;
ESP8266WebServer server(80);
void handleRoot() {
String lstemp = "<html>\
<head>\
<title>ESP8266 FS Browser</title>\
</head>\
<body>\
<nav>\
Disk Info\
</nav>\n";
if ((server.hasArg("path") ? server.arg("path") : "/").endsWith("/")) {
Dir dir = fileSystem->openDir(server.hasArg("path") ? server.arg("path") : "/");
Serial.println("listing dir");
while (dir.next()) {
Serial.println(dir.fileName());
if (dir.isFile()) {
lstemp += "<a href='/?path=" + (server.hasArg("path") ? server.arg("path") : "/") + dir.fileName() + "'>" + dir.fileName() + "</a><br>\n";
} else {
lstemp += "<a href='/?path=" + (server.hasArg("path") ? server.arg("path") : "/") + dir.fileName() + "/'>" + dir.fileName() + "/</a><br>\n";
}
}
} else {
lstemp = "<html><head><title>ESP8266 FS Browser</title></head><body>You are viewing file now. Click <a href='/download?action=download?path=" + server.arg("path") + "'>here</a> to download\n<iframe src='/download?action=view?path=" + server.arg("path") + "'></iframe>";
}
lstemp += "</body></html>";
server.send(200, "text/html", lstemp);
}
void handleFsInfo() {
String fsinfotemp = "FS: LittleFS\nTotal size: ";
FSInfo fs_info;
LittleFS.info(fs_info);
fsinfotemp += fs_info.totalBytes / 1000;
fsinfotemp += " KB\nUsed: ";
fsinfotemp += fs_info.usedBytes / 1000;
fsinfotemp += "\nFree: ";
fsinfotemp += (fs_info.totalBytes - fs_info.usedBytes) / 1000;
server.send(200, "text/plain", fsinfotemp);
}
void handleUploadFile() {}
void handleDownloadFile() {
if (server.arg("action") == "download") {
server.chunkedResponseModeStart(200, "application/octet-stream");
}
if (server.arg("action") == "view") {
server.chunkedResponseModeStart(200, "text/plain");
}
File downloadable = fileSystem->open(server.arg("path"), (char*)'r');
while (downloadable.available()) {
server.sendContent((char*)downloadable.read());
Serial.write(downloadable.read());
}
server.chunkedResponseFinalize();
downloadable.close();
}
void handleMkdir() {}
void handleRemove() {}
void handleRename() {}
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin("MySSID", "MyPASSWORD");
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("WiFi Connect Failed! Rebooting...");
delay(1000);
ESP.restart();
}
if (!fileSystem->begin()) {
Serial.println("File system begin failed! Formatting LittleFS...");
fileSystem->format();
Serial.println("Done. Reboot ESP8266");
while (1) {;}
}
server.on("/", handleRoot);
server.on("/fsinfo", handleFsInfo);
server.on("/upload", handleUploadFile);
server.on("/download", handleDownloadFile);
server.on("/mkdir", handleMkdir);
server.on("/rm", handleRemove);
server.on("/rename", handleRename);
if (MDNS.begin("esp8266-filehost")) {
MDNS.addService("http", "tcp", 80);
}
server.begin();
}
void loop() {
server.handleClient();
MDNS.update();
}
Full exception code:
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Exception (28):
epc1=0x40214c00 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000072 depc=0x00000000
>>>stack>>>
ctx: cont
sp: 3ffffca0 end: 3fffffc0 offset: 0190
3ffffe30: 3ffee9c0 ffffffff 00000006 402123c6
3ffffe40: 000052b4 00000430 3fff0924 40208bba
3ffffe50: 3ffffea0 3ffeff78 00000000 40211400
3ffffe60: 0000000a 3ffee9e4 4021439c 00000000
3ffffe70: 3ffffecc 00000000 3ffee9c0 402059d4
3ffffe80: 00000000 3ffeeb64 3ffffea0 4020f901
3ffffe90: 00000000 3ffeeb64 3ffee9c0 40207732
3ffffea0: 00000000 69006e6f 00000000 ffffffff
3ffffeb0: 40211df2 00000001 00000000 00000000
3ffffec0: 0023002f 00000000 00000000 68746170
3ffffed0: 3ffeea00 04000000 00000000 40211400
3ffffee0: 00000000 00000000 4bc6a7f0 3ffeed28
3ffffef0: 3fffdad0 00000001 3fff0204 4021435e
3fffff00: 00000000 00000000 3fff0b3c 401000e9
3fffff10: 00000000 616f6c6e 00000000 402058fd
3fffff20: 3fff04b4 3ffeea08 3ffee9c0 40207876
3fffff30: 00000000 3ffeeb08 00000001 4020accf
3fffff40: 000052ac 00000000 00000000 00000001
3fffff50: 00000001 3ffee9e4 3fff04e8 3ffeed28
3fffff60: 3fffdad0 3ffee9e4 3ffee9c0 402080a2
3fffff70: 00000000 3ffeeb08 3ffeed14 4020adc4
3fffff80: 00000000 00000000 00000001 401003ec
3fffff90: 3fffdad0 00000000 3ffeed14 40208168
3fffffa0: 3fffdad0 00000000 3ffeed14 40211de0
3fffffb0: feefeffe feefeffe 3ffe85dc 40100ea5
<<<stack<<<
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
This crash happens when I added file download function, but I hasn't found an error. Global variables remaining 36% of RAM, but all temp String variables are freed after finishing function automatically. So chunk server sending is collecting a much of junk?
I think that this can happen when converting char to char*. The read function returns a char and at the end of c-strings it should always be null and when converting it is not. Perhaps there is an error in this
I'm working on a bluetooth project at the moment and after getting the value of the kCBAdvDataManufacturerData:
var data = advertisementData.value(forKey: "kCBAdvDataManufacturerData")
The values are hex values:
<00133377 08d704de ff03c200 00000000 00000000 00000000 00000000 00337701 416e746f 6e206465 20426f64 65000000 00000000 00000000>
what I know so far is that the value of kCBAdvDataManufacturerDatakey is an AnyObject
From the above value I need this:
00133377 08d704de ff03c200 00000000 00000000 00000000 00000000 00337701 416e746f 6e206465 20426f64 65000000 00000000 00000000
How can I get this value without converting it to a String? In other word is there a way to use something like Range on a AnyObject value without converting it to a String?
I need to acquire some points' coordinates (represented by variables xCoord and yCoord) and set to 1 the associated positions in matrix scan_image. It may happen that a point's coordinates are outside matrix's dimensions, so scan_image needs to be resized before setting point's associated position in matrix to 1.
Here's the code:
#include "line_matching/listener.hpp"
#include <opencv2/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/utility.hpp>
using namespace cv;
using namespace std;
int main(int argv, char** argc){
/* start listening */
listener lsr;
lsr.listen(argv, argc);
/* get data that were listened to */
vector<listener::completeInformation> vecCI = lsr.getListeningInfo();
/* create a matrix to host image */
Mat scan_image;
/* fill matrix */
float currentX = 0;
float currentY = 0;
for(int i = 0; i<(int)vecCI.size(); i++)
{
/* get current info */
listener::completeInformation ci = vecCI[i];
float xCoord = ci.position.first;
float yCoord = ci.position.second;
/* matrix is void */
if(scan_image.empty())
{
cout << "case 1" << endl;
/* create a new row */
Mat firstRow = Mat::zeros(yCoord+1, xCoord+1, CV_32FC1);
scan_image.push_back(firstRow);
/* set element to 1 */
scan_image.at<float>(xCoord, yCoord) = 1;
/* update matrix size */
currentX = xCoord;
currentY = yCoord;
}
/* new coordinate is outside current matrix */
else if (xCoord > currentX && yCoord > currentY)
{
cout << "case 2" << endl;
/* add necessary rows */
Mat newRows = Mat::zeros(yCoord-currentY, currentX+1, CV_32FC1);
cout << "Size scan " << scan_image.rows << " " << scan_image.cols << endl;
scan_image.push_back(newRows);
currentY = yCoord;
/* add new cols */
Mat newCols = Mat::zeros(currentY+1, xCoord-currentX, CV_32FC1);
cout << "Size newCols " << newCols.rows << " " << newCols.cols << endl;
hconcat(scan_image, newCols, scan_image);
/* update matrix size */
currentX = xCoord;
/* set element to 1 */
scan_image.at<float>(xCoord, yCoord) = 1;
}
/* coordinate's column is outside matrix */
else if(xCoord > currentX && yCoord < currentY)
{
cout << "case 3" << endl;
/* add necessary cols */
Mat newCols = Mat::zeros(currentY+1, xCoord-currentX, CV_32FC1);
cout << "Size scan " << scan_image.rows << " " << scan_image.cols << endl;
cout << "Size newCols " << newCols.rows << " " << newCols.cols << endl;
Mat newMat;
hconcat(scan_image, newCols, newMat);
cout << "Size newMat " << newMat.rows << " " << newMat.cols << endl;
//scan_image.resize(newMat.rows);
//scan_image.create(newMat.rows, newMat.cols, CV_32FC1);
resize(scan_image, scan_image, newMat.size());
cout << "Size scan dopo" << scan_image.rows << " " << scan_image.cols << endl;
//scan_image = newMat.clone();
cout << "create" << endl;
newMat.copyTo(scan_image);
//newMat.assignTo(scan_image, -1);
cout << "Dopo creazione mat " << scan_image.rows << " " << scan_image.cols << endl;
/* update matrix size */
currentX = xCoord;
/* set element to 1 */
scan_image.at<float>(xCoord, yCoord) = 1;
}
/* coordinate's row is outside matrix */
else if(xCoord < currentX && yCoord > currentY)
{
cout << "case 4" << endl;
/* add necessary rows */
Mat newRows = Mat::zeros(yCoord-currentY, currentX+1, CV_32FC1);
scan_image.push_back(newRows);
/* update matrix size */
currentY = yCoord;
/* set element to 1 */
scan_image.at<float>(xCoord, yCoord) = 1;
}
else
{
cout << "case 5" << endl;
/* set element to 1 */
scan_image.at<float>(xCoord, yCoord) = 1;
}
}
imshow("Scan", scan_image);
waitKey();
}
I tried many options to modify scan_info's dimensions (you'll find them in comments) in case denoted as CASE 3, but everytime I get a bad memory error:
*** glibc detected *** /home/ubisum/fuerte_workspace/line_matching/bin/matching_main: free(): invalid next size (fast): 0x0000000001e81060 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7e846)[0x7feb0e3fe846]
/usr/local/lib/libopencv_core.so.3.0(_ZN2cv8fastFreeEPv+0x9d)[0x7feb0fb24986]
/usr/local/lib/libopencv_core.so.3.0(+0x21cbb0)[0x7feb0fb26bb0]
/usr/local/lib/libopencv_core.so.3.0(_ZNK2cv12MatAllocator5unmapEPNS_8UMatDataE+0x43)[0x7feb0fb25eaf]
/usr/local/lib/libopencv_core.so.3.0(_ZN2cv3Mat10deallocateEv+0x71)[0x7feb0fb27c3b]
/home/ubisum/fuerte_workspace/line_matching/bin/matching_main(_ZN2cv3MatD1Ev+0x75)[0x40de15]
/usr/local/lib/libopencv_imgproc.so.3.0(_ZN2cv6resizeERKNS_11_InputArrayERKNS_12_OutputArrayENS_5Size_IiEEddi+0x16da)[0x7feb0efd80dc]
/home/ubisum/fuerte_workspace/line_matching/bin/matching_main(main+0x1b19)[0x40d389]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7feb0e3a176d]
/home/ubisum/fuerte_workspace/line_matching/bin/matching_main[0x40dce1]
======= Memory map: ========
00400000-0041f000 r-xp 00000000 08:06 1318193 /home/ubisum/fuerte_workspace/line_matching/bin/matching_main
0061e000-0061f000 r--p 0001e000 08:06 1318193 /home/ubisum/fuerte_workspace/line_matching/bin/matching_main
0061f000-00620000 rw-p 0001f000 08:06 1318193 /home/ubisum/fuerte_workspace/line_matching/bin/matching_main
01e43000-030ec000 rw-p 00000000 00:00 0 [heap]
7feae470a000-7feae490a000 rw-p 00000000 00:00 0
7feae490a000-7feae4919000 r-xp 00000000 08:06 2772700 /usr/lib/libtbbmalloc.so.2
7feae4919000-7feae4b19000 ---p 0000f000 08:06 2772700 /usr/lib/libtbbmalloc.so.2
7feae4b19000-7feae4b1a000 r--p 0000f000 08:06 2772700 /usr/lib/libtbbmalloc.so.2
7feae4b1a000-7feae4b1b000 rw-p 00010000 08:06 2772700 /usr/lib/libtbbmalloc.so.2
7feae4b1b000-7feae4b2c000 rw-p 00000000 00:00 0
7feae4b2c000-7feae4b6c000 rw-s 00024000 00:05 13777 /dev/ati/card0
7feae4b6c000-7feae526c000 rw-s 00006000 00:05 13777 /dev/ati/card0
7feae526c000-7feae53ec000 rw-p 00000000 00:00 0
7feae53ec000-7feae5486000 r-xp 00000000 08:06 2766513 /usr/lib/fglrx/libGL.so.1.2
7feae5486000-7feae5586000 ---p 0009a000 08:06 2766513 /usr/lib/fglrx/libGL.so.1.2
7feae5586000-7feae55ae000 rwxp 0009a000 08:06 2766513 /usr/lib/fglrx/libGL.so.1.2
7feae55ae000-7feae55cb000 rwxp 00000000 00:00 0
7feae55cb000-7feae7a13000 r-xp 00000000 08:06 2766506 /usr/lib/fglrx/libamdocl64.so
7feae7a13000-7feae7c13000 ---p 02448000 08:06 2766506 /usr/lib/fglrx/libamdocl64.so
7feae7c13000-7feae7ee0000 rw-p 02448000 08:06 2766506 /usr/lib/fglrx/libamdocl64.so
7feae7ee0000-7feae8000000 rw-p 00000000 00:00 0
7feae8000000-7feae8021000 rw-p 00000000 00:00 0
7feae8021000-7feaec000000 ---p 00000000 00:00 0
7feaec000000-7feaec021000 rw-p 00000000 00:00 0
7feaec021000-7feaf0000000 ---p 00000000 00:00 0
7feaf0000000-7feaf0021000 rw-p 00000000 00:00 0
7feaf0021000-7feaf4000000 ---p 00000000 00:00 0
7feaf4000000-7feaf4021000 rw-p 00000000 00:00 0
7feaf4021000-7feaf8000000 ---p 00000000 00:00 0
7feaf8000000-7feaf8021000 rw-p 00000000 00:00 0
7feaf8021000-7feafc000000 ---p 00000000 00:00 0
7feafc011000-7feafc0d1000 rw-p 00000000 00:00 0
7feafc0d1000-7feafc171000 r-xp 00000000 08:06 2766543 /usr/lib/fglrx/libatiadlxx.so
7feafc171000-7feafc271000 ---p 000a0000 08:06 2766543 /usr/lib/fglrx/libatiadlxx.so
7feafc271000-7feafc274000 rw-p 000a0000 08:06 2766543 /usr/lib/fglrx/libatiadlxx.so
7feafc274000-7feafc284000 rw-p 00000000 00:00 0
7feafc284000-7feafc28a000 r-xp 00000000 08:06 2766549 /usr/lib/fglrx/libOpenCL.so.1
7feafc28a000-7feafc489000 ---p 00006000 08:06 2766549 /usr/lib/fglrx/libOpenCL.so.1
7feafc489000-7feafc48a000 rw-p 00005000 08:06 2766549 /usr/lib/fglrx/libOpenCL.so.1
7feafc48a000-7feafc48b000 ---p 00000000 00:00 0
7feafc48b000-7feafcc8b000 rw-p 00000000 00:00 0 [stack:13933]
7feafcc8b000-7feafcc8c000 ---p 00000000 00:00 0
7feafcc8c000-7feafd48c000 rw-p 00000000 00:00 0
7feafd48c000-7feafd48d000 ---p 00000000 00:00 0
7feafd48d000-7feafdc8d000 rw-p 00000000 00:00 0
7feafdc8d000-7feafdc8e000 ---p 00000000 00:00 0
7feafdc8e000-7feafe48e000 rw-p 00000000 00:00 0
7feafe48e000-7feafe48f000 ---p 00000000 00:00 0
7feafe48f000-7feafec8f000 rw-p 00000000 00:00 0
7feafec8f000-7feafec9b000 r-xp 00000000 08:06 1970270 /lib/x86_64-linux-gnu/libnss_files-2.15.so
7feafec9b000-7feafee9a000 ---p 0000c000 08:06 1970270 /lib/x86_64-linux-gnu/libnss_files-2.15.so
7feafee9a000-7feafee9b000 r--p 0000b000 08:06 1970270 /lib/x86_64-linux-gnu/libnss_files-2.15.so
7feafee9b000-7feafee9c000 rw-p 0000c000 08:06 1970270 /lib/x86_64-linux-gnu/libnss_files-2.15.so
7feafee9c000-7feaff57f000 r--p 00000000 08:06 2759450 /usr/lib/locale/locale-archive
7feaff57f000-7feaff585000 r-xp 00000000 08:06 2760664 /usr/lib/x86_64-linux-gnu/libogg.so.0.7.1
7feaff585000-7feaff784000 ---p 00006000 08:06 2760664 /usr/lib/x86_64-linux-gnu/libogg.so.0.7.1
7feaff784000-7feaff785000 r--p 00005000 08:06 2760664 /usr/lib/x86_64-linux-gnu/libogg.so.0.7.1
7feaff785000-7feaff786000 rw-p 00006000 08:06 2760664 /usr/lib/x86_64-linux-gnu/libogg.so.0.7.1
7feaff786000-7feaff7a7000 r-xp 00000000 08:06 2760810 /usr/lib/x86_64-linux-gnu/libv4lconvert.so.0
7feaff7a7000-7feaff9a6000 ---p 00021000 08:06 2760810 /usr/lib/x86_64-linux-gnu/libv4lconvert.so.0
7feaff9a6000-7feaff9a8000 r--p 00020000 08:06 2760810 /usr/lib/x86_64-linux-gnu/libv4lconvert.so.0
7feaff9a8000-7feaff9a9000 rw-p 00022000 08:06 2760810 /usr/lib/x86_64-linux-gnu/libv4lconvert.so.0
7feaff9a9000-7feaff9fb000 rw-p 00000000 00:00 0
7feaff9fb000-7feaffa0b000 r-xp 00000000 08:06 2760531 /usr/lib/x86_64-linux-gnu/libgstinterfaces-0.10.so.0.25.0
7feaffa0b000-7feaffc0b000 ---p 00010000 08:06 2760531 /usr/lib/x86_64-linux-gnu/libgstinterfaces-0.10.so.0.25.0
7feaffc0b000-7feaffc0c000 r--p 00010000 08:06 2760531 /usr/lib/x86_64-linux-gnu/libgstinterfaces-0.10.so.0.25.0Aborted (core dumped)
Any suggestion?
thanks
I am confused as to why I am getting 128 bytes for scan-lines/rowpitch rather than the 8 I am specifying. The BMP in question being loaded is 4 pixels, red top left, green top right, blue bottom left, yellow bottom right.
Code is as follows:
ID3D11Resource *g_pOverlay_Staging = nullptr;
IWICImagingFactory* WICFactory = nullptr;
IWICBitmapDecoder * WICBitmapDecoder = nullptr;
IWICBitmapFrameDecode * WICBitmapFrame = nullptr;
WICPixelFormatGUID pixelFormat;
HR(CoCreateInstance(CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, __uuidof(IWICImagingFactory), (LPVOID*)&WICFactory));
HR(WICFactory->CreateDecoderFromFilename(L"province_map.bmp", nullptr, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &WICBitmapDecoder));
HR(WICBitmapDecoder->GetFrame(0,&WICBitmapFrame));
HR(WICBitmapFrame->GetPixelFormat(&pixelFormat));
DXGI_FORMAT format;
if (pixelFormat == GUID_WICPixelFormat24bppBGR){
std::wostringstream outs2;
outs2 << "pixelformat = GUID_WICPixelFormat24bppBGR" << std::endl;
OutputDebugString(outs2.str().c_str());
format = DXGI_FORMAT_R8G8B8A8_UNORM;
}
IWICFormatConverter * FC = nullptr;
WICFactory->CreateFormatConverter(&FC);
HR(FC->Initialize(WICBitmapFrame, GUID_WICPixelFormat32bppRGBA, WICBitmapDitherTypeErrorDiffusion, 0, 0, WICBitmapPaletteTypeCustom));
std::unique_ptr<uint8_t[]> temp(new uint8_t[16]);
HR(FC->CopyPixels(0, 8, 16, temp.get()));
D3D11_TEXTURE2D_DESC desc;
desc.Width = 2;
desc.Height = 2;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = format;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D11_USAGE_STAGING;
desc.BindFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
desc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA initData;
initData.pSysMem = temp.get();
initData.SysMemPitch = 8;
initData.SysMemSlicePitch = 16;
ID3D11Texture2D* tex = nullptr;
HR(d3d11DeviceInterface->CreateTexture2D(&desc, &initData, &tex));
g_pOverlay_Staging = tex;
D3D11_MAPPED_SUBRESOURCE mapped_subresource;
HR(d3d11DeviceContextInterface->Map(g_pOverlay_Staging, 0, D3D11_MAP_READ_WRITE, 0, &mapped_subresource));
uint8_t * v = reinterpret_cast<uint8_t*>(mapped_subresource.pData);
unsigned int x = 0;
while (x < 256 ) {
std::bitset<8> one(v[x]);
std::bitset<8> two(v[x+1]);
std::bitset<8> three(v[x+2]);
std::bitset<8> four(v[x + 3]);
std::wostringstream outs1;
outs1 << "x[" << x << "] = " << one << " x[" << x + 1 << "] = " << two << " x[" << x + 2 << "] = " << three << " x[" << x + 3 << "] = " << four << std::endl;
OutputDebugString(outs1.str().c_str());
x += 4;
}
Output is:
pixelformat = GUID_WICPixelFormat24bppBGR
x[0] = 11111111 x[1] = 00000000 x[2] = 00000000 x[3] = 11111111
x[4] = 00000000 x[5] = 11111111 x[6] = 00000000 x[7] = 11111111
x[8] = 00000000 x[9] = 00000000 x[10] = 00000000 x[11] = 00000000
x[12] = 00000000 x[13] = 00000000 x[14] = 00000000 x[15] = 00000000
x[16] = 00000000 x[17] = 00000000 x[18] = 00000000 x[19] = 00000000
x[20] = 00000000 x[21] = 00000000 x[22] = 00000000 x[23] = 00000000
x[24] = 00000000 x[25] = 00000000 x[26] = 00000000 x[27] = 00000000
x[28] = 00000000 x[29] = 00000000 x[30] = 00000000 x[31] = 00000000
x[32] = 00000000 x[33] = 00000000 x[34] = 00000000 x[35] = 00000000
x[36] = 00000000 x[37] = 00000000 x[38] = 00000000 x[39] = 00000000
x[40] = 00000000 x[41] = 00000000 x[42] = 00000000 x[43] = 00000000
x[44] = 00000000 x[45] = 00000000 x[46] = 00000000 x[47] = 00000000
x[48] = 00000000 x[49] = 00000000 x[50] = 00000000 x[51] = 00000000
x[52] = 00000000 x[53] = 00000000 x[54] = 00000000 x[55] = 00000000
x[56] = 00000000 x[57] = 00000000 x[58] = 00000000 x[59] = 00000000
x[60] = 00000000 x[61] = 00000000 x[62] = 00000000 x[63] = 00000000
x[64] = 00000000 x[65] = 00000000 x[66] = 00000000 x[67] = 00000000
x[68] = 00000000 x[69] = 00000000 x[70] = 00000000 x[71] = 00000000
x[72] = 00000000 x[73] = 00000000 x[74] = 00000000 x[75] = 00000000
x[76] = 00000000 x[77] = 00000000 x[78] = 00000000 x[79] = 00000000
x[80] = 00000000 x[81] = 00000000 x[82] = 00000000 x[83] = 00000000
x[84] = 00000000 x[85] = 00000000 x[86] = 00000000 x[87] = 00000000
x[88] = 00000000 x[89] = 00000000 x[90] = 00000000 x[91] = 00000000
x[92] = 00000000 x[93] = 00000000 x[94] = 00000000 x[95] = 00000000
x[96] = 00000000 x[97] = 00000000 x[98] = 00000000 x[99] = 00000000
x[100] = 00000000 x[101] = 00000000 x[102] = 00000000 x[103] = 00000000
x[104] = 00000000 x[105] = 00000000 x[106] = 00000000 x[107] = 00000000
x[108] = 00000000 x[109] = 00000000 x[110] = 00000000 x[111] = 00000000
x[112] = 00000000 x[113] = 00000000 x[114] = 00000000 x[115] = 00000000
x[116] = 00000000 x[117] = 00000000 x[118] = 00000000 x[119] = 00000000
x[120] = 00000000 x[121] = 00000000 x[122] = 00000000 x[123] = 00000000
x[124] = 00000000 x[125] = 00000000 x[126] = 00000000 x[127] = 00000000
x[128] = 00000000 x[129] = 00000000 x[130] = 11111111 x[131] = 11111111
x[132] = 11111111 x[133] = 11111111 x[134] = 00000000 x[135] = 11111111
x[136] = 00000000 x[137] = 00000000 x[138] = 00000000 x[139] = 00000000
x[140] = 00000000 x[141] = 00000000 x[142] = 00000000 x[143] = 00000000
x[144] = 00000000 x[145] = 00000000 x[146] = 00000000 x[147] = 00000000
x[148] = 00000000 x[149] = 00000000 x[150] = 00000000 x[151] = 00000000
x[152] = 00000000 x[153] = 00000000 x[154] = 00000000 x[155] = 00000000
x[156] = 00000000 x[157] = 00000000 x[158] = 00000000 x[159] = 00000000
x[160] = 00000000 x[161] = 00000000 x[162] = 00000000 x[163] = 00000000
x[164] = 00000000 x[165] = 00000000 x[166] = 00000000 x[167] = 00000000
x[168] = 00000000 x[169] = 00000000 x[170] = 00000000 x[171] = 00000000
x[172] = 00000000 x[173] = 00000000 x[174] = 00000000 x[175] = 00000000
x[176] = 00000000 x[177] = 00000000 x[178] = 00000000 x[179] = 00000000
x[180] = 00000000 x[181] = 00000000 x[182] = 00000000 x[183] = 00000000
x[184] = 00000000 x[185] = 00000000 x[186] = 00000000 x[187] = 00000000
x[188] = 00000000 x[189] = 00000000 x[190] = 00000000 x[191] = 00000000
x[192] = 00000000 x[193] = 00000000 x[194] = 00000000 x[195] = 00000000
x[196] = 00000000 x[197] = 00000000 x[198] = 00000000 x[199] = 00000000
x[200] = 00000000 x[201] = 00000000 x[202] = 00000000 x[203] = 00000000
x[204] = 00000000 x[205] = 00000000 x[206] = 00000000 x[207] = 00000000
x[208] = 00000000 x[209] = 00000000 x[210] = 00000000 x[211] = 00000000
x[212] = 00000000 x[213] = 00000000 x[214] = 00000000 x[215] = 00000000
x[216] = 00000000 x[217] = 00000000 x[218] = 00000000 x[219] = 00000000
x[220] = 00000000 x[221] = 00000000 x[222] = 00000000 x[223] = 00000000
x[224] = 00000000 x[225] = 00000000 x[226] = 00000000 x[227] = 00000000
x[228] = 00000000 x[229] = 00000000 x[230] = 00000000 x[231] = 00000000
x[232] = 00000000 x[233] = 00000000 x[234] = 00000000 x[235] = 00000000
x[236] = 00000000 x[237] = 00000000 x[238] = 00000000 x[239] = 00000000
x[240] = 00000000 x[241] = 00000000 x[242] = 00000000 x[243] = 00000000
x[244] = 00000000 x[245] = 00000000 x[246] = 00000000 x[247] = 00000000
x[248] = 00000000 x[249] = 00000000 x[250] = 00000000 x[251] = 00000000
x[252] = 00000000 x[253] = 00000000 x[254] = 00000000 x[255] = 00000000
This is expected. After you've uploaded texture memory to the GPU, if you Map it back for read, there's no guarantee that it will come back with the same pitch that you uploaded it as. This is because on upload, the driver re-lays out memory in a way that's optimal for rendering. When you bring it back to the CPU, the driver efficiently converts it back to linear format, usually in a way that reflects various properties of the texture cache or page size.