Problem with BlitzMax DLL

BlitzMax Forums/BlitzMax Programming/Problem with BlitzMax DLL

time-killer-games(Posted 2016) [#1]
Hey guys

So I created a DLL in BlitzMax and it works fine for me but a user reported to me it crashed their game and it spit this out in the compile form:

htmlview TODO error line:604
Attempt to access field or method of Null objectCompile


Any ideas on what this means or why this is happening for them and not me? I will provide the source code if necessary.

Thanks!
Samuel


RustyKristi(Posted 2016) [#2]
must be some msvcr or mscvp dlls that their missing I'm not sure. As a tip before you ship your game or program, test first with a typical window installation so you can check for missing dlls.


Derron(Posted 2016) [#3]
The second line is a blitz.mod TNullObjectException.

So you access something of an invalid object


Means:
Your DLL is propably returning "null" instead of a valid object.
Your application is then just doing something in the likes of:

local obj:TMyObject = dllExternalFunction_GetMyObject(123)
obj.DoSomething()



The first line comes from maxgui.mod/win32maxguiex.mod/mshtmlview.cpp


So this means you are calling a function which is not doing something.

example:
STDMETHODIMP CMySite2::OnShowWindow(BOOL fShow){
	TODO
}
STDMETHODIMP CMySite2::RequestNewObjectLayout(){
	TODO
}



Best thing is to run it via debugger to see what is crashing.


bye
Ron


BlitzMan(Posted 2016) [#4]
I had this problem.

I think RustyKristi and Derron have nailed it.


time-killer-games(Posted 2016) [#5]
Thanks guys!

Since I am unable to reproduce this issue on my end of things, are you saying I should compile a debug version, to send the guy who was having the issue, and he could then send what the compile form outputs again? And doing this will somehow let me know what DLL's he is missing? Just wanted to make sure I am reading this correctly.

If it helps at all, here's the source code...

WebBrowser.bat
C:\BlitzMax\bin\bmk.exe makelib -r WebBrowser.bmx


WebBrowser.bmx
Import MaxGui.Drivers

Strict 

Framework brl.blitz

Global UrlOrFilePath:String
Global CurrentUrl:String=""
Global window:TGadget
Global htmlview:TGadget
Global file:TStream
Global exists:Int=0

Function CreateBrowser:Double(HideScrollbars:Double)

		exists=1
		If htmlview<>Null FreeGadget(htmlview)
		file=ReadFile(CurrentDir()+"/url.tmp")
		UrlOrFilePath=String(ReadLine(file))
		CloseStream file
		
		If window=Null window=CreateWindow("YYWebBrowserYY",0,0,320,240,Null,WINDOW_TITLEBAR|WINDOW_RESIZABLE|WINDOW_CENTER|WINDOW_ACCEPTFILES)	
		
		If HideScrollbars=0 Then htmlview=CreateHTMLView(0,0,ClientWidth(window),ClientHeight(window),window)
		If HideScrollbars=1 Then htmlview=CreateHTMLView(0,0,ClientWidth(window)+17,ClientHeight(window)+17,window)
		If HideScrollbars=2 Then htmlview=CreateHTMLView(0,0,ClientWidth(window),ClientHeight(window)+17,window)
		If HideScrollbars=3 Then htmlview=CreateHTMLView(0,0,ClientWidth(window)+17,ClientHeight(window),window)
		
		SetGadgetLayout htmlview,1,1,1,1
		HtmlViewGo htmlview,UrlOrFilePath
		
		ShowGadget(window)
		EnableGadget(window)
		
	Return 0
		
EndFunction

Function GetUrlFromBrowser:Double()
		
		If exists=1
			If htmlview<>Null 
				If HtmlViewCurrentURL(htmlview)<>""
					CurrentUrl=HtmlViewCurrentURL(htmlview)
				Else
					CurrentUrl="about:blank"
				EndIf
			Else
				CurrentUrl="about:blank"
			EndIf
		Else
			CurrentUrl=""
		EndIf
		
		file=WriteFile(CurrentDir()+"\url.tmp")
		WriteLine file,CurrentUrl
		CloseStream file
		
	Return 0
		
EndFunction

Function DestroyBrowser:Double()

		exists=0
		If window<>Null HideGadget(window)
		If htmlview<>Null FreeGadget(htmlview)
		
	Return 0
		
EndFunction


WebBrowser.def
EXPORTS
CreateBrowser=bb_CreateBrowser
GetUrlFromBrowser=bb_GetUrlFromBrowser
DestroyBrowser=bb_DestroyBrowser


It seems that the problem may be related to when the "htmlview" variable's value is "Null", but I'm not 100%.


grable(Posted 2016) [#6]
There are no missing dlls, that kind of error would be shown by the OS loader not by blitz (unless they are loaded manually).

It would also help to have the other side of it as well, where you import and call the dll functions.
I notice that you dont mark them "win32" either, so they are cdecl. Just make sure that the same is true for the other side.

Anyway, since your main problem is a Null pointer exception, the most likely culprits are the files your trying to read/write.
Or its that you FreeGadget something and dont set it to Null afterwards, so next time around it might think its still alive.


time-killer-games(Posted 2016) [#7]
Thank you grable for the insight.

I'll set the variable to Null after each FreeGadget and see if that helps. I'm waiting to hear back from the guy who had the crash, and he's going to send the other side, which I'll post here for further investigation.


Henri(Posted 2016) [#8]
Hi,

before I/O accessing file you should always check that file is valid and when using global variables, set them to null when no longer needed so validity is easier to check.

-Henri


time-killer-games(Posted 2017) [#9]
Thanks everyone for the help. Unfortuneately I heard back from the guy who encountered the aforementioned issue and he was not willing to send me his project which reproduced the bug. But I'll keep all this stuff in mind, in case if I run into that problem myself down the road.