BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION

New to FreeBASIC? Post your questions here.
davidshq
Posts: 52
Joined: Oct 29, 2008 3:28
Contact:

BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION

Post by davidshq »

Hi All,

I'm trying to make this bit of code work:

DIM SHARED mtn(1 TO 1564)
BLoad "mtn.vga", VarPtr(mtn(1))

But it crashes the app every time and fbdebugger tells me it is an "EXCEPTION_ACCESS_VIOLATION"

I believe all I'm trying to do here is load mtn.vga into the array mtn at position 1?

Any ideas why this is causing me issues?

Thanks!
Dave
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION

Post by MrSwiss »

Dim Shared (As "what?") a Type is needed here ...

Code: Select all

Dim Shared As Any Ptr mtn(1 To ...)
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION

Post by fxm »

-lang qb ?
-lang fblite ?
(in qb, DIM by default => single = 4 Bytes)
(in fblite, DIM by default => integer = 4 Bytes)

If yes, how do you compute the size of mtn() ?
Last edited by fxm on Dec 03, 2016 21:10, edited 1 time in total.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION

Post by MrSwiss »

fxm,

you should know me better than that, by now ... never -lang "QB"
only -lang "FB".
davidshq
Posts: 52
Joined: Oct 29, 2008 3:28
Contact:

Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION

Post by davidshq »

I tried added As Integer, doesn't seem to make a different.

Yes, -lang qb. Hmmm...not sure how to do that?
davidshq
Posts: 52
Joined: Oct 29, 2008 3:28
Contact:

Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION

Post by davidshq »

@MrSwiss - I am migrating an old QuickBasic project to FreeBasic, doing -lang qb so that I can get it up and running as quickly as possible, then work on moving to FB syntax. :)
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION

Post by fxm »

@MrSwiss,
My previous post was for davidshq.

@davidshq,
How do you compute the size of mtn() ?
Is there DEFINT before in the code?
In qb, mtn() size (in bytes) >= 4 + (w * h * bpp)
Last edited by fxm on Dec 03, 2016 21:32, edited 2 times in total.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION

Post by MrSwiss »

@davidshq,

IMO, you are creating double work: to FB -lang "QB" then to FB -lang "FB",
simply makes no sense ...
davidshq
Posts: 52
Joined: Oct 29, 2008 3:28
Contact:

Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION

Post by davidshq »

@fxm - In QuickBasic I've never had to do that...so I don't think it does. The .vga file is a BSAVE, VGA resolution.

@MrSwiss - There are a lot of changes to make if I move to FB, with the -lang qb I have only two or three remaining - namely, adding a sound library and loading these BSAVE images.
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION

Post by fxm »

What is the size of the image to load ?
davidshq
Posts: 52
Joined: Oct 29, 2008 3:28
Contact:

Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION

Post by davidshq »

Hmmm...I don't have any dimensions for them. I was hoping just to use the files as the memory dumps they are, but it sounds like it may be easier to export them to a modern format like jpg and then load them in - since I have a way to figure out dimensions then...as I don't know of any way to extract the dimensions.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION

Post by MrSwiss »

davidshq wrote:namely, adding a sound library and loading these BSAVE images
And exactly these tasks are so much simpler, in -lang "FB".
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION

Post by dodicat »

I get the dimensions with lang "qb"

But get an error with bload (64 bit) and no picture(32 bit)
All OK with lang "fb"

Code: Select all

#lang "qb"
screen 19,32

Function GetSize(bmp As String,byref x as long,byref y as long) As long 'get bitmap width/height
    if Open (bmp For Binary access read As #1)=0 then
    Get #1, 19, X
    Get #1, 23, Y
    Close #1
else
    print bmp;"  not found"
    end if
    GetSize= x*y
End Function

dim as string file 

file = "num6.bmp" '<-------------  YOUR FILE
dim as long w,h


if GetSize(file,w,h) then print w,h else print "ERROR":sleep:end



redim as long a((w+1)*(h+1))


bload(file,@(a(0)))

put(0,0),@a(0)
sleep

 
davidshq
Posts: 52
Joined: Oct 29, 2008 3:28
Contact:

Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION

Post by davidshq »

@MrSwiss - I won't disagree that these tasks are simpler in FB, the issue is if I use FB then lots more of the QB code becomes invalid.

@dodicat - Thanks for the code snippet! It seems to "load" the image, but it shows a bunch of pixels and not the image, it also gives the dimensions as: 1 and 128.
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: BLOAD / VARPTR Causing EXCEPTION_ACCESS_VIOLATION

Post by sancho2 »

How sure are you of your .vga file? Are %100 sure it is a valid bmp image?
Rename it xxx.bmp and try to load it in paint or another graphics program.
@dodicat:
According to the help file in lang QB the second paramter of the screen statement is 'colormode' and it is ignored. I'm not sure why you include it.
Your code does work with bmp files 8bit bit depth. It shows the picture with slightly off colors.
Post Reply