Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / [DGDK 2.0] Why does this crash?

Author
Message
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 12th Jul 2012 16:18

I have tried several versions of how to use the pointer given by dbGetPixelsPointer ( ); and still the same problem. I checked the value in *p and it looks like a pointer-- it's a large number.

The fastest code is the code never written.
Rudolpho
14
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 12th Jul 2012 16:24 Edited at: 12th Jul 2012 16:29
The returned pointer is probably to a char (byte) array.
When you're converting it to an int pointer pointer arithmetics will have it so that p + (i * 4) will refer to the i * 4:th pixel; I believe you want to step through each byte rather than do that. Still, you most likely should have more than 400 pixels locked so I don't really see why it should crash.
Does it give any particular error message / can you use the stack trace to find something out?

Edit: Just tried the following which runs just fine for me:



"Why do programmers get Halloween and Christmas mixed up?"
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 12th Jul 2012 16:35
No error from the compiler or GDK. I get a "... has stopped working." message from windows.

The i*4 part is because each color has 4 bytes to it. The +1 is so it will only write to the red part of the pixil (I think 1 is red....--I know 1 is not the alpha).

The fastest code is the code never written.
Rudolpho
14
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 12th Jul 2012 18:09
Have you tried compiling it in debug mode?
It should break rather than outright crash if you do.

And as I said the +4 only works if you have a byte pointer, otherwise it will bypass 4 instances of the elements that is pointed towards - in your case 4 32-bit integers, meaning you will only address every fourth pixel.


"Why do programmers get Halloween and Christmas mixed up?"
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 12th Jul 2012 19:59 Edited at: 12th Jul 2012 20:00
Here are the errors I'm getting:

I got a different one some time earlier, but I wasn't able to get a screenshot--It said I had an access violation at the same spot for as in the second image.....

The fastest code is the code never written.

Attachments

Login to view attachments
Rudolpho
14
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 12th Jul 2012 20:58
Aha, what you're doing there is actually just retrieving a pointer to a (single) integer that contains the sought pointer.
In other words p isn't the pixel pointer itself but rather it points to 4 (or maybe 8 if you're on a 64-bit machine) bytes that in turn contains the address of the pixel pointer. (That sounds confusing even as I'm writing it, I hope you get what I mean though, might be easier illustrated with a picture rather than words )

To actually access the pointer you must cast the returned int to a pointer of some kind (I'd recommend a char or BYTE pointer as you likely want to access bytes; you can use a int32_t pointer if you like as well, and then access each full pixel (4 channels) at a time).


"Why do programmers get Halloween and Christmas mixed up?"
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 12th Jul 2012 21:13
Put it in code please. I think I know what you are saying, but I've tried every way I can imagine to reference the pointer with no luck.

The fastest code is the code never written.
Rudolpho
14
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 12th Jul 2012 21:59
You already have it in my snippet up in the second post.
The thing of interrest is this:



"Why do programmers get Halloween and Christmas mixed up?"
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 12th Jul 2012 22:29
THAT'S IT!!!!!

For the life of me I couldn't get that to work. Why didn't TGC/Mistrel have it return a char* instead of a int????

The fastest code is the code never written.
Rudolpho
14
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 12th Jul 2012 23:28
Because the underlying DarkBASIC function returns an int and most of the wrapper functions in DGDK 2 are automatically generated by following a simple generic template function and looking at the string table of the native dll's.
There are a few functions in there where this auto-wrapper has failed and I've had to manually edit a letter so the cases are correct etc, as well as quite a few 3d math functions not returning a value(!).

I suspect it will be manually reviewed before the official version is released though.


"Why do programmers get Halloween and Christmas mixed up?"
Hawkblood
10
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 13th Jul 2012 00:38
Quote: "There are a few functions in there where this auto-wrapper has failed and I've had to manually edit a letter so the cases are correct etc, as well as quite a few 3d math functions not returning a value(!).
"

Could that be why dbCreateImageFromMemblock (..) isn't working?

The fastest code is the code never written.
Olby
16
Years of Service
User Offline
Joined: 21st Aug 2003
Location:
Posted: 13th Jul 2012 23:00
Quote: "There are a few functions in there where this auto-wrapper has failed and I've had to manually edit a letter so the cases are correct etc, as well as quite a few 3d math functions not returning a value(!)."


Could you please point these out for Mistrel so that we all can benefit from your findings. Thanks very much!


Intel Core2Duo 2.2GHZ, 2GB, GeForce 8600M GT 1280MB, Windows Vista Ultimate SP2, PureBasic 4.61 + DarkGDK 2.0

Login to post a reply

Server time is: 2020-02-16 21:41:45
Your offset time is: 2020-02-16 21:41:45