-
-
Notifications
You must be signed in to change notification settings - Fork 147
Windows Drop File Code Checkpoint, Using WM_DROPFILES Message (not OLE). #608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
… but since OnDropFiles is not assigned, this code does not currently provide a full working example.
Incorporate Michalis' changes from May 18th, 2024 and May 19th, 2024
michaliskambi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much! Reviewed, I have small notes -- see below. Only minor stuff, I think the biggest change will be to move handling to TCastleWindow.WindowProc.
|
Note that GitHub Actions detected failure at Delphi compilation -- You can leave investigating + solving it on me later. If you'll make it work with FPC, I'll later fix Delphi, no problem :) |
|
To answer some things in PR description:
In Pascal, strings (
In case of FPC (open-source compiler that you use), this is true. The full picture is a bit more complicated as we also support Delphi, where |
|
Question: You mention a few times (in the title of this too) that it's "not OLE". If you have please post here some links and arguments why we'd like to go with a different implementation, using OLE? Because I quite like the current approach (WM_DROPFILES), this is simple and we like simple code :) |
|
I couldn't test fully due to MimeType type changes blocking simple loads of files without a mimeType. I will look into creating a stream, but just loading a file without a stream (just a URL and a MimeType, or just a URL might be simpler). |
Merge from Michalis #2
As we discuss on Discord, this is likely a bug on your side -- your string handling adds a trailing There are no "MimeType changes" lately that change the relevant logic -- And again, please keep the discussion in one place. It is now in 4 places (one here, 3 on Discord), which means I have to answer 4 times to keep everyone who's reading aware of what's going on :) Let's continue on |
|
Pascal doesn't like the NUL at the end of the Windows string so we chop it off! |
|
Yes, the extra space is for Windows API to fill in a NUL, otherwise it will
chop off ‘d’ from ‘.x3d’. I tried several combinations, but settled on
trimming the NUL after Windows finished with the string. This works.
We’ll probably want to discuss trying to figure out how to reclaim the
memory for the file names and array. It could consume a lot with a lot of
files dropped . After DoDropFiles finishes in WMDropFiles, there’s an
opportunity to free up the space for the filenames and the array. I don’t
know how to do that yet.
Also, the client needs to be informed in documentation that that
OnDropFiles gives them should not be freed, but we don’t have much control
from the calling side.
John
…On Tue, May 21, 2024 at 6:45 AM Michalis Kamburelis < ***@***.***> wrote:
I couldn't test fully due to MimeType type changes blocking simple loads
of files without a mimeType. I will look into creating a stream, but just
loading a file without a stream (just a URL and a MimeType, or just a URL
might be simpler).
As we discuss on Discord, this is likely a bug on your side -- your string
handling adds a trailing #0.
There are no "MimeType changes" lately that change the relevant logic --
LoadNode(Url) detects file type based on URL (through extension->MIME
type mapping), and it fails if it doesn't match any known type.
And again, please keep the discussion in one place. It is now in 4 places
(one here, 3 on Discord), which means I have to answer 4 times to keep
everyone who's reading aware of what's going on :) Let's continue on
#general on Discord and post here conclusions. In the future, please keep
talking about PR contained to the GitHub comments about this PR.
—
Reply to this email directly, view it on GitHub
<#608 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFMJ5Y2OB7UFM6KFTI772LZDMXWTAVCNFSM6AAAAABH7BQ6NWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRSGQ2DQOJWGM>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
Here’s my test code previously mentioned. https://github.com/coderextreme/draganddraop I’ll work on freeing up the array of strings allocated in WMDropFiles in WMDropFiles. My first guess is to use SetLength and use a length of zero. I also don’t know what calling SetLength on an array does. More stuff to look up |
okay, Calling SetLength(var, 0) seems to be the way to go for both arrays and strings. I am now realizing I am probably overwriting the file name when I call SetLength for a second time. I will try more two file drops to make sure things are ok. I know the scene will get overwritten in the demo. I am trying to follow the interface. |
Pulled in stuff from Michalis
|
All set, except I don't know how to free up memory held by PFileName. AIRC, I can't use SetLength. So, a puzzle. |
|
You don't need to explicitly free memory allocated for Pascal , they are not useful and somewhat confusing :) The Pascal The Pascal dynamic array, like Test your application for memory leaks following https://castle-engine.io/memory_leaks to see if you have real problem with memory leaking and where. |
|
We can discuss how to add to applications in a portable manner. Thanks! |
Merge from castle engine master
|
Seems like things have settled down. I've got another demo working with the 3D viewer project template, even dragging and dropping and playing the animation works. I'm still working out how to organize things. If you have any further ideas on portability, let me know. I haven't checked for memory leaks yet. |
|
TODOs for me :
|
Since this is my first contribution, I'd thought I'd give people a chance to review my code before writing an example against it (I have a partial one that brings up a blank window and registers for an event, but since OnDropFiles is not assigned, DoDropFiles does not do anything (You can check this in the debugger that DoDropFiles is called). This has not been called with several files yet, but the code could possibly work. I don't know about 0 indexing versus 1 indexing into the FileNames array. I tried 1 indexing.
I couldn't seem to get Any WideChar stuff working yet. AFAIK, DoDropFiles takes an array of AnsiString.
I am not expecting this pull request to get merged yet, but I would like the code reviewed (It's quite short), and possibly make sure stuff still compiles on other systems.
I don't expect any gotchas in this code except perhaps I need to add a 1 to a FileNameLength here and there.